120 | | | | 1 | | using System; |
121 | | | | 2 | | |
122 | | | | 3 | | namespace UnitTesting02.Projects |
123 | | | | 4 | | { |
124 | | | | 5 | | public class Issue |
125 | | | | 6 | | { |
126 | | | 13 | 7 | | public string Key { get; private set; } // "HW-2022-U-1F7531A6", "SW-2019-L-405B417E" |
127 | | | 13 | 8 | | public string Description { get; private set; } |
128 | | | 39 | 9 | | public DateTime CreatedAt { get; private set; } // 0001-01-01 |
129 | | | 56 | 10 | | public Priority Priority { get; private set; } |
130 | | | 44 | 11 | | public Category Category { get; private set; } |
131 | | | | 12 | | |
132 | | | | 13 | | |
133 | | | 15 | 14 | | public Issue (string description, Priority priority, Category category, |
134 | | | 15 | 15 | | DateTime? createdAt = null) |
135 | | | 15 | 16 | | { |
136 | | | | 17 | | |
137 | | | 15 | 18 | | if (string.IsNullOrWhiteSpace(description)) |
138 | | | 2 | 19 | | throw new InvalidIssueDescriptionException(); |
139 | | | | 20 | | |
140 | | | 13 | 21 | | Description = description; |
141 | | | | 22 | | |
142 | | | 13 | 23 | | this.Priority = priority; |
143 | | | | 24 | | |
144 | | | 13 | 25 | | this.Category = category; |
145 | | | | 26 | | |
146 | | | 13 | 27 | | this.CreatedAt = createdAt is null ? DateTime.Now : createdAt.Value; |
147 | | | | 28 | | |
148 | | | 13 | 29 | | this.Key = GenerateKey(); |
149 | | | | 30 | | |
150 | | | 13 | 31 | | } |
151 | | | | 32 | | |
152 | | | | 33 | | private string GenerateKey() |
153 | | | 25 | 34 | | { |
154 | | | 25 | 35 | | var categorySegment = Category is Category.Hardware ? "HW" : |
155 | | | 25 | 36 | | Category is Category.Software ? "SW" : "NA"; |
156 | | | | 37 | | |
157 | | | 25 | 38 | | var prioritySegment = |
158 | | | 25 | 39 | | Priority is Priority.Low ? "L" : |
159 | | | 25 | 40 | | Priority is Priority.Medium ? "M" : |
160 | | | 25 | 41 | | Priority is Priority.High ? "H" : "U"; |
161 | | | | 42 | | |
162 | | | 25 | 43 | | var yearSegment = CreatedAt.Year.ToString(); // YYYY |
163 | | | | 44 | | |
164 | | | 25 | 45 | | var uniqueId = Guid.NewGuid().ToString().Substring(0, 8).ToUpper(); |
165 | | | | 46 | | |
166 | | | 25 | 47 | | return $"{ categorySegment }-{yearSegment}-{prioritySegment}-{uniqueId}"; |
167 | | | 25 | 48 | | } |
168 | | | | 49 | | |
169 | | | | 50 | | public override string ToString() |
170 | | | 0 | 51 | | { |
171 | | | 0 | 52 | | return $"[{Key}] {Description}"; |
172 | | | 0 | 53 | | } |
173 | | | | 54 | | } |
174 | | | | 55 | | } |
175 |
176 |