-
Notifications
You must be signed in to change notification settings - Fork 499
Expand file tree
/
Copy pathLogMessageFormatterTests.cs
More file actions
553 lines (458 loc) · 24.8 KB
/
LogMessageFormatterTests.cs
File metadata and controls
553 lines (458 loc) · 24.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
using Amazon.Lambda.RuntimeSupport.Helpers;
using Amazon.Lambda.RuntimeSupport.Helpers.Logging;
using Microsoft.VisualStudio.TestPlatform.CommunicationUtilities;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.Text.Json;
using Xunit;
using static Amazon.Lambda.RuntimeSupport.UnitTests.LogMessageFormatterTests;
namespace Amazon.Lambda.RuntimeSupport.UnitTests
{
public class LogMessageFormatterTests
{
[Fact]
public void ParseLogMessageWithNoProperties()
{
var formatter = new JsonLogMessageFormatter();
var properties = formatter.ParseProperties("No message properties here");
Assert.Empty(properties);
}
[Fact]
public void ParseLogMessageWithProperties()
{
var formatter = new JsonLogMessageFormatter();
var properties = formatter.ParseProperties("User {user} bought {count:000} items of {@product} with an {{escaped}}");
Assert.Equal(3, properties.Count);
Assert.Equal("user", properties[0].Name);
Assert.Equal(MessageProperty.Directive.Default, properties[0].FormatDirective);
Assert.Equal("count", properties[1].Name);
Assert.Equal("000", properties[1].FormatArgument);
Assert.Equal(MessageProperty.Directive.Default, properties[1].FormatDirective);
Assert.Equal("product", properties[2].Name);
Assert.Equal(MessageProperty.Directive.JsonSerialization, properties[2].FormatDirective);
}
[Fact]
public void ParseLogMessageWithOpenBracketAndNoClosing()
{
var formatter = new JsonLogMessageFormatter();
var properties = formatter.ParseProperties("{hello} before { after");
Assert.Equal(1, properties.Count);
Assert.Equal("hello", properties[0].Name);
Assert.Equal(MessageProperty.Directive.Default, properties[0].FormatDirective);
}
[Fact]
public void FormatJsonWithNoMessageProperties()
{
var timestamp = DateTime.UtcNow;
var formattedTimestamp = timestamp.ToString("yyyy-MM-ddTHH:mm:ss.fffZ");
var formatter = new JsonLogMessageFormatter();
var state = new MessageState()
{
AwsRequestId = "1234",
TraceId = "4321",
Level = Helpers.LogLevelLoggerWriter.LogLevel.Warning,
MessageTemplate = "Simple Log Message",
MessageArguments = null,
TimeStamp = timestamp
};
var json = formatter.FormatMessage(state);
var doc = JsonDocument.Parse(json);
Assert.Equal("1234", doc.RootElement.GetProperty("requestId").GetString());
Assert.Equal("4321", doc.RootElement.GetProperty("traceId").GetString());
Assert.Equal(formattedTimestamp, doc.RootElement.GetProperty("timestamp").GetString());
Assert.Equal("Warning", doc.RootElement.GetProperty("level").GetString());
Assert.Equal("Simple Log Message", doc.RootElement.GetProperty("message").GetString());
}
[Fact]
public void FormatJsonWithStringMessageProperties()
{
var timestamp = DateTime.UtcNow;
var formattedTimestamp = timestamp.ToString("yyyy-MM-ddTHH:mm:ss.fffZ");
var formatter = new JsonLogMessageFormatter();
var state = new MessageState()
{
AwsRequestId = "1234",
Level = Helpers.LogLevelLoggerWriter.LogLevel.Warning,
MessageTemplate = "Hello {name}",
MessageArguments = new object[] { "AWS" },
TimeStamp = timestamp
};
var json = formatter.FormatMessage(state);
var doc = JsonDocument.Parse(json);
Assert.Equal("1234", doc.RootElement.GetProperty("requestId").GetString());
Assert.Equal(formattedTimestamp, doc.RootElement.GetProperty("timestamp").GetString());
Assert.Equal("Warning", doc.RootElement.GetProperty("level").GetString());
Assert.Equal("Hello AWS", doc.RootElement.GetProperty("message").GetString());
}
[Fact]
public void FormatJsonNullMessageTemplate()
{
var timestamp = DateTime.UtcNow;
var formatter = new JsonLogMessageFormatter();
var state = new MessageState()
{
MessageTemplate = null,
AwsRequestId = "1234",
Level = Helpers.LogLevelLoggerWriter.LogLevel.Warning,
TimeStamp = timestamp
};
var json = formatter.FormatMessage(state);
var doc = JsonDocument.Parse(json);
Assert.Equal(string.Empty, doc.RootElement.GetProperty("message").GetString());
Assert.Equal("1234", doc.RootElement.GetProperty("requestId").GetString());
// Currently the arguments are ignored because they don't exist in the message template but
// having arguments uses a different code path so we need to make sure a NPE doesn't happen.
state = new MessageState()
{
MessageTemplate = null,
MessageArguments = new object[] { true },
AwsRequestId = "1234",
Level = Helpers.LogLevelLoggerWriter.LogLevel.Warning,
TimeStamp = timestamp
};
json = formatter.FormatMessage(state);
doc = JsonDocument.Parse(json);
Assert.Equal(string.Empty, doc.RootElement.GetProperty("message").GetString());
Assert.Equal("1234", doc.RootElement.GetProperty("requestId").GetString());
}
[Fact]
public void FormatJsonWithAllPossibleTypes()
{
var dateOnly = new DateOnly(2024, 2, 18);
var timeOnly = new TimeOnly(15, 19, 45, 545);
var timestamp = DateTime.UtcNow;
var formattedTimestamp = timestamp.ToString("yyyy-MM-ddTHH:mm:ss.fffZ");
var product = new Product() { Name = "Widget", Inventory = 100 };
var formatter = new JsonLogMessageFormatter();
var state = new MessageState()
{
AwsRequestId = "1234",
Level = Helpers.LogLevelLoggerWriter.LogLevel.Warning,
MessageTemplate = "bool: {bool}, byte: {byte}, char: {char}, decimal: {decimal}, double: {double}, float: {float}, " +
"int: {int}, uint: {uint}, long: {long}, ulong: {ulong}, short: {short}, ushort: {ushort}, null: {null}, " +
"DateTime: {DateTime}, DateTimeOffset: {DateTimeOffset}, default: {default}, DateOnly {DateOnly}, TimeOnly: {TimeOnly}",
MessageArguments = new object[] {true, (byte)1, 'a', (decimal)4.5, (double)5.6, (float)7.7, (int)-10, (uint)10, (long)-100, (ulong)100, (short)-50, (ushort)50, null, timestamp, timestamp, product, dateOnly, timeOnly},
TimeStamp = timestamp
};
var json = formatter.FormatMessage(state);
var doc = JsonDocument.Parse(json);
Assert.Equal("bool: True, byte: 1, char: a, decimal: 4.5, double: 5.6, float: 7.7, " +
"int: -10, uint: 10, long: -100, ulong: 100, short: -50, ushort: 50, null: {null}, " +
$"DateTime: {formattedTimestamp}, DateTimeOffset: {formattedTimestamp}, default: Widget 100, DateOnly 2024-02-18, TimeOnly: 15:19:45.545",
doc.RootElement.GetProperty("message").GetString());
Assert.True(doc.RootElement.GetProperty("bool").GetBoolean());
Assert.Equal((byte)1, doc.RootElement.GetProperty("byte").GetByte());
Assert.Equal("a", doc.RootElement.GetProperty("char").GetString());
Assert.Equal((decimal)4.5, doc.RootElement.GetProperty("decimal").GetDecimal());
Assert.Equal((double)5.6, doc.RootElement.GetProperty("double").GetDouble());
Assert.Equal((float)7.7, doc.RootElement.GetProperty("float").GetSingle());
Assert.Equal((int)-10, doc.RootElement.GetProperty("int").GetInt32());
Assert.Equal((uint)10, doc.RootElement.GetProperty("uint").GetUInt32());
Assert.Equal((long)-100, doc.RootElement.GetProperty("long").GetInt64());
Assert.Equal((ulong)100, doc.RootElement.GetProperty("ulong").GetUInt64());
Assert.Equal((short)-50, doc.RootElement.GetProperty("short").GetInt16());
Assert.Equal((ushort)50, doc.RootElement.GetProperty("ushort").GetUInt16());
Assert.False(doc.RootElement.TryGetProperty("null", out var _));
Assert.Equal(formattedTimestamp, doc.RootElement.GetProperty("DateTime").GetString());
Assert.Equal(formattedTimestamp, doc.RootElement.GetProperty("DateTimeOffset").GetString());
Assert.Equal("Widget 100", doc.RootElement.GetProperty("default").GetString());
Assert.Equal("2024-02-18", doc.RootElement.GetProperty("DateOnly").GetString());
Assert.Equal("15:19:45.545", doc.RootElement.GetProperty("TimeOnly").GetString());
}
[Fact]
public void FormatJsonWithPoco()
{
var timestamp = DateTime.UtcNow;
var product = new Product() { Name = "Widget", Inventory = 100 };
var formatter = new JsonLogMessageFormatter();
var state = new MessageState()
{
AwsRequestId = "1234",
Level = Helpers.LogLevelLoggerWriter.LogLevel.Warning,
MessageTemplate = "Our product is {product}",
MessageArguments = new object[] { product },
TimeStamp = timestamp
};
var json = formatter.FormatMessage(state);
var doc = JsonDocument.Parse(json);
Assert.Equal("Our product is Widget 100", doc.RootElement.GetProperty("message").GetString());
Assert.Equal(JsonValueKind.String, doc.RootElement.GetProperty("product").ValueKind);
Assert.Equal("Widget 100", doc.RootElement.GetProperty("product").GetString());
}
[Fact]
public void FormatJsonWithPocoSerialized()
{
var timestamp = DateTime.UtcNow;
var product = new Product() { Name = "Widget", Inventory = 100 };
var formatter = new JsonLogMessageFormatter();
var state = new MessageState()
{
AwsRequestId = "1234",
Level = Helpers.LogLevelLoggerWriter.LogLevel.Warning,
MessageTemplate = "Our product is {@product}",
MessageArguments = new object[] { product },
TimeStamp = timestamp
};
var json = formatter.FormatMessage(state);
var doc = JsonDocument.Parse(json);
Assert.Equal("Our product is Widget 100", doc.RootElement.GetProperty("message").GetString());
Assert.Equal(JsonValueKind.Object, doc.RootElement.GetProperty("product").ValueKind);
Assert.Equal("Widget", doc.RootElement.GetProperty("product").GetProperty("Name").GetString());
Assert.Equal(100, doc.RootElement.GetProperty("product").GetProperty("Inventory").GetInt32());
}
[Fact]
public void FormatJsonWithList()
{
var timestamp = DateTime.UtcNow;
var product1 = new Product() { Name = "Widget", Inventory = 100 };
var product2 = new Product() { Name = "Doohickey", Inventory = 200 };
var formatter = new JsonLogMessageFormatter();
var state = new MessageState()
{
AwsRequestId = "1234",
Level = Helpers.LogLevelLoggerWriter.LogLevel.Warning,
MessageTemplate = "Our products are {products}",
MessageArguments = new object[] { new Product[] { product1, product2 } },
TimeStamp = timestamp
};
var json = formatter.FormatMessage(state);
var doc = JsonDocument.Parse(json);
Assert.Equal("Our products are {products}", doc.RootElement.GetProperty("message").GetString());
Assert.Equal(JsonValueKind.Array, doc.RootElement.GetProperty("products").ValueKind);
Assert.Equal("Widget 100", doc.RootElement.GetProperty("products")[0].GetString());
Assert.Equal("Doohickey 200", doc.RootElement.GetProperty("products")[1].GetString());
}
[Fact]
public void FormatJsonWithListSerialzied()
{
var timestamp = DateTime.UtcNow;
var product1 = new Product() { Name = "Widget", Inventory = 100 };
var product2 = new Product() { Name = "Doohickey", Inventory = 200 };
var formatter = new JsonLogMessageFormatter();
var state = new MessageState()
{
AwsRequestId = "1234",
Level = Helpers.LogLevelLoggerWriter.LogLevel.Warning,
MessageTemplate = "Our products are {@products}",
MessageArguments = new object[] { new Product[] { product1, product2 } },
TimeStamp = timestamp
};
var json = formatter.FormatMessage(state);
var doc = JsonDocument.Parse(json);
Assert.Equal("Our products are {@products}", doc.RootElement.GetProperty("message").GetString());
Assert.Equal(JsonValueKind.Array, doc.RootElement.GetProperty("products").ValueKind);
Assert.Equal("Widget", doc.RootElement.GetProperty("products")[0].GetProperty("Name").GetString());
Assert.Equal(100, doc.RootElement.GetProperty("products")[0].GetProperty("Inventory").GetInt32());
Assert.Equal("Doohickey", doc.RootElement.GetProperty("products")[1].GetProperty("Name").GetString());
Assert.Equal(200, doc.RootElement.GetProperty("products")[1].GetProperty("Inventory").GetInt32());
}
[Fact]
public void FormatJsonWithDictionary()
{
var timestamp = DateTime.UtcNow;
var product1 = new Product() { Name = "Widget", Inventory = 100 };
var product2 = new Product() { Name = "Doohickey", Inventory = 200 };
var formatter = new JsonLogMessageFormatter();
var state = new MessageState()
{
AwsRequestId = "1234",
Level = Helpers.LogLevelLoggerWriter.LogLevel.Warning,
MessageTemplate = "Our products are {products}",
MessageArguments = new object[] { new Dictionary<string, Product> { { product1.Name, product1 }, { product2.Name, product2 } } },
TimeStamp = timestamp
};
var json = formatter.FormatMessage(state);
var doc = JsonDocument.Parse(json);
Assert.Equal("Our products are {products}", doc.RootElement.GetProperty("message").GetString());
Assert.Equal(JsonValueKind.Object, doc.RootElement.GetProperty("products").ValueKind);
Assert.Equal("Widget 100", doc.RootElement.GetProperty("products").GetProperty("Widget").GetString());
Assert.Equal("Doohickey 200", doc.RootElement.GetProperty("products").GetProperty("Doohickey").GetString());
}
[Fact]
public void FormatJsonWithDictionarySerialized()
{
var timestamp = DateTime.UtcNow;
var product1 = new Product() { Name = "Widget", Inventory = 100 };
var product2 = new Product() { Name = "Doohickey", Inventory = 200 };
var formatter = new JsonLogMessageFormatter();
var state = new MessageState()
{
AwsRequestId = "1234",
Level = Helpers.LogLevelLoggerWriter.LogLevel.Warning,
MessageTemplate = "Our products are {@products}",
MessageArguments = new object[] { new Dictionary<string, Product> { { product1.Name, product1 }, { product2.Name, product2 } } },
TimeStamp = timestamp
};
var json = formatter.FormatMessage(state);
var doc = JsonDocument.Parse(json);
Assert.Equal("Our products are {@products}", doc.RootElement.GetProperty("message").GetString());
Assert.Equal(JsonValueKind.Object, doc.RootElement.GetProperty("products").ValueKind);
Assert.Equal("Widget", doc.RootElement.GetProperty("products").GetProperty("Widget").GetProperty("Name").GetString());
Assert.Equal(100, doc.RootElement.GetProperty("products").GetProperty("Widget").GetProperty("Inventory").GetInt32());
Assert.Equal("Doohickey", doc.RootElement.GetProperty("products").GetProperty("Doohickey").GetProperty("Name").GetString());
Assert.Equal(200, doc.RootElement.GetProperty("products").GetProperty("Doohickey").GetProperty("Inventory").GetInt32());
}
[Theory]
[InlineData("No Properties", new object[] { }, "No Properties")]
[InlineData("No Properties", null, "No Properties")]
[InlineData("{name}", new object[] { "aws" } , "aws")]
[InlineData("{0}", new object[] { "aws" }, "aws")]
[InlineData("{0} {1}", new object[] { "aws" }, "aws {1}")]
[InlineData("{0}", new object[] { "aws", "s3" }, "aws")]
[InlineData("{{name}} {name}", new object[] { "aws" }, "{{name}} aws")]
[InlineData("Positional test {0} {1} {0}", new object[] {"Arg1", "Arg2" }, "Positional test Arg1 Arg2 Arg1")]
[InlineData("{category}", new object[] { Product.Category.Electronics }, "Electronics")]
[InlineData("{hextest}", new object[] { new byte[] { 1, 2, 3 } }, "010203")]
[InlineData("{}", new object[] { "dummy" }, "{}")] // Log message doesn't really make any sense but we need to make sure we protect ourselves from it.
public void PropertyReplacementVerification(string message, object[] arguments, string expectedMessage)
{
foreach(var formatter in new AbstractLogMessageFormatter[] { new DefaultLogMessageFormatter(false), new DefaultLogMessageFormatter(true), new JsonLogMessageFormatter() })
{
var timestamp = DateTime.UtcNow;
var state = new MessageState()
{
AwsRequestId = "1234",
Level = Helpers.LogLevelLoggerWriter.LogLevel.Warning,
MessageTemplate = message,
MessageArguments = arguments,
TimeStamp = timestamp
};
var formattedMessage = formatter.FormatMessage(state);
if(formatter is JsonLogMessageFormatter)
{
var doc = JsonDocument.Parse(formattedMessage);
Assert.Equal(expectedMessage, doc.RootElement.GetProperty("message").GetString());
}
else if(formatter is DefaultLogMessageFormatter defaultFormatter)
{
if(defaultFormatter.AddPrefix)
{
Assert.EndsWith(expectedMessage, formattedMessage);
}
else
{
Assert.Equal(expectedMessage, formattedMessage);
}
}
}
if (arguments?.Length == 1 && arguments[0] is byte[] bytes)
{
// Can't create ReadOnlyMemory and Memory as part of the "InlineData" attribute so force check
// if we are doing the byte[] check and if so repeat for ReadonlyMemory and Memory
PropertyReplacementVerification(message, new object[] { new ReadOnlyMemory<byte>(bytes) }, expectedMessage);
PropertyReplacementVerification(message, new object[] { new Memory<byte>(bytes) }, expectedMessage);
}
}
[Fact]
public void OutOfOrderPositionalArgumentsWithJson()
{
var timestamp = DateTime.UtcNow;
var formatter = new JsonLogMessageFormatter();
var state = new MessageState()
{
AwsRequestId = "1234",
Level = Helpers.LogLevelLoggerWriter.LogLevel.Warning,
MessageTemplate = "{1} {0}",
MessageArguments = new object[] { "arg1", "arg2" },
TimeStamp = timestamp
};
var json = formatter.FormatMessage(state);
var doc = JsonDocument.Parse(json);
Assert.Equal("arg2 arg1", doc.RootElement.GetProperty("message").GetString());
Assert.Equal("arg1", doc.RootElement.GetProperty("0").GetString());
Assert.Equal("arg2", doc.RootElement.GetProperty("1").GetString()); ;
}
[Fact]
public void FormatLargeByteArray()
{
var timestamp = DateTime.UtcNow;
var bytes = new byte[10000];
for (var i = 0; i < bytes.Length; i++)
{
bytes[i] = 1;
}
foreach (var argument in new object [] { bytes, new ReadOnlyMemory<byte>(bytes), new Memory<byte>(bytes) })
{
var state = new MessageState()
{
AwsRequestId = "1234",
Level = Helpers.LogLevelLoggerWriter.LogLevel.Warning,
MessageTemplate = "Binary data: {bytes}",
MessageArguments = new object[] { argument },
TimeStamp = timestamp
};
var formatter = new JsonLogMessageFormatter();
var json = formatter.FormatMessage(state);
var doc = JsonDocument.Parse(json);
Assert.Equal($"Binary data: 01010101010101010101010101010101... ({bytes.Length} bytes)", doc.RootElement.GetProperty("message").GetString());
Assert.Equal($"01010101010101010101010101010101... ({bytes.Length} bytes)", doc.RootElement.GetProperty("bytes").GetString());
}
}
[Fact]
public void FormatJsonException()
{
try
{
var nre = new NullReferenceException("You got a null");
throw new ApplicationException("This Will Fail", nre);
}
catch(Exception ex)
{
var timestamp = DateTime.UtcNow;
var state = new MessageState()
{
AwsRequestId = "1234",
Level = Helpers.LogLevelLoggerWriter.LogLevel.Warning,
MessageTemplate = "What does an error look like?",
MessageArguments = null,
Exception = ex,
TimeStamp = timestamp
};
var formatter = new JsonLogMessageFormatter();
var json = formatter.FormatMessage(state);
var doc = JsonDocument.Parse(json);
Assert.Equal("What does an error look like?", doc.RootElement.GetProperty("message").GetString());
Assert.Equal("This Will Fail", doc.RootElement.GetProperty("errorMessage").GetString());
Assert.Equal("System.ApplicationException", doc.RootElement.GetProperty("errorType").GetString());
Assert.Equal(JsonValueKind.Array, doc.RootElement.GetProperty("stackTrace").ValueKind);
var stackLines = ex.ToString().Split('\n').Select(x => x.Trim()).ToList();
var jsonExArray = doc.RootElement.GetProperty("stackTrace");
Assert.Equal(stackLines.Count, jsonExArray.GetArrayLength());
for(var i = 0; i < stackLines.Count; i++)
{
Assert.Equal(stackLines[i], jsonExArray[i].GetString());
}
}
}
[Theory]
[InlineData("{0}", true)]
[InlineData("{1} {0}", true)]
[InlineData("{1} {10}", false)]
[InlineData("{1} {2}", false)]
[InlineData("{0} {5} {6}", false)]
[InlineData("Arg1 {0} Arg2 {1}", true)]
[InlineData("Test {user}", false)]
[InlineData("Arg1 {0} Arg5 {5}", false)] // Not positional because there is a gap in between the numbers
[InlineData("Arg1 {@0} Arg2 {1:00}", true)]
public void CheckIfPositional(string message, bool expected)
{
var formatter = new DefaultLogMessageFormatter(true);
var properties = formatter.ParseProperties(message);
var isPositional = formatter.UsingPositionalArguments(properties);
Assert.Equal(expected, isPositional);
}
public class Product
{
public enum Category { Food, Electronics }
public string Name { get; set; }
public int Inventory { get; set; }
public Category? Cat { get; set; }
public override string ToString()
{
return $"{Name} {Inventory}";
}
}
}
}