public void AddsEnvironmentNameLabel()
        {
            // Arrange
#if NETCOREAPP3_1
            var    hostingEnvironmentMock = new Mock <IWebHostEnvironment>();
            string expectedEnvironment    = Environments.Production;
#elif NETCOREAPP2_1 || NET461
            var    hostingEnvironmentMock = new Mock <IHostingEnvironment>();
            string expectedEnvironment    = EnvironmentName.Production;
#else
#error unknown target framework
#endif

            hostingEnvironmentMock.Setup(x => x.EnvironmentName).Returns(expectedEnvironment);

            var instance = new EnvironmentNameLogEntryLabelProvider(hostingEnvironmentMock.Object);
            var labels   = new Dictionary <string, string>();

            // Act
            instance.Invoke(labels);

            // Assert
            Assert.Single(labels);
            var label = labels.Single();
            Assert.Equal("aspnetcore_environment", label.Key);
            Assert.Equal(expectedEnvironment, label.Value);
        }
예제 #2
0
        public void SkipsNullOrEmptyEnvironmentName(string label)
        {
            // Arrange
            var hostingEnvironmentMock = new Mock <IHostingEnvironment>();

            hostingEnvironmentMock.Setup(x => x.EnvironmentName).Returns(label);

            var instance = new EnvironmentNameLogEntryLabelProvider(hostingEnvironmentMock.Object);
            var labels   = new Dictionary <string, string>();

            // Act
            instance.Invoke(labels);

            // Assert
            Assert.Empty(labels);
        }
예제 #3
0
        public void AddsEnvironmentNameLabel()
        {
            // Arrange
            var hostingEnvironmentMock = new Mock <IHostingEnvironment>();

            hostingEnvironmentMock.Setup(x => x.EnvironmentName).Returns(EnvironmentName.Production);

            var instance = new EnvironmentNameLogEntryLabelProvider(hostingEnvironmentMock.Object);
            var labels   = new Dictionary <string, string>();

            // Act
            instance.Invoke(labels);

            // Assert
            Assert.Single(labels);
            var label = labels.Single();

            Assert.Equal("aspnetcore_environment", label.Key);
            Assert.Equal(EnvironmentName.Production, label.Value);
        }
        public void SkipsNullOrEmptyEnvironmentName(string label)
        {
            // Arrange
#if NETCOREAPP3_1
            var hostingEnvironmentMock = new Mock <IWebHostEnvironment>();
#elif NETCOREAPP2_1 || NET461
            var hostingEnvironmentMock = new Mock <IHostingEnvironment>();
#else
#error unknown target framework
#endif
            hostingEnvironmentMock.Setup(x => x.EnvironmentName).Returns(label);

            var instance = new EnvironmentNameLogEntryLabelProvider(hostingEnvironmentMock.Object);
            var labels   = new Dictionary <string, string>();

            // Act
            instance.Invoke(labels);

            // Assert
            Assert.Empty(labels);
        }