public void Contains_Key_FalseWhenNoMatchKey()
        {
            var subject = new ChangeTrackingDictionary <string, TestItem>();
            var result  = subject.ContainsKey("not found");

            Assert.False(result);
        }
Exemple #2
0
        public void MessageIsSetToOriginalFormatWhenIncludeFormattedMessageIsNotSet()
        {
            var logRecords = new List <LogRecord>();

            using var loggerFactory = LoggerFactory.Create(builder =>
            {
                builder.AddOpenTelemetry(options =>
                {
                    options.AddInMemoryExporter(logRecords);
                });
                builder.AddFilter(typeof(LogsHelperTests).FullName, LogLevel.Trace);
            });

            var logger = loggerFactory.CreateLogger <LogsHelperTests>();

            string log = "Hello from {name} {price}.";

            logger.LogInformation(log, "tomato", 2.99);

            var properties = new ChangeTrackingDictionary <string, string>();
            var message    = LogsHelper.GetMessageAndSetProperties(logRecords[0], properties);

            Assert.Equal(log, message);
            Assert.False(properties.ContainsKey("OriginalFormat"));
            Assert.True(properties.TryGetValue("name", out string name));
            Assert.Equal("tomato", name);
            Assert.True(properties.TryGetValue("price", out string price));
            Assert.Equal("2.99", price);
        }
        public void Contains_Key_TrueWhenMatchKey()
        {
            var expectedKey   = "Test1";
            var expectedItems = new Dictionary <string, TestItem>
            {
                { expectedKey, new TestItem() },
                { "Test2", new TestItem() }
            };
            var subject = new ChangeTrackingDictionary <string, TestItem>(expectedItems);
            var result  = subject.ContainsKey(expectedKey);

            Assert.True(result);
        }