Ejemplo n.º 1
0
        public void DoesNotAddWhenNoRemoteIp()
        {
            // Arrange
            var mockHttpContext = new Mock <HttpContext>();

            mockHttpContext.Setup(x => x.Connection.RemoteIpAddress).Returns((IPAddress)null);

            var mockHttpContextAccessor = new Mock <IHttpContextAccessor>();

            mockHttpContextAccessor.Setup(x => x.HttpContext).Returns(mockHttpContext.Object);

            var instance = new ClientIpLogEntryLabelProvider(mockHttpContextAccessor.Object);
            var labels   = new Dictionary <string, string>();

            // Act
            instance.Invoke(labels);

            // Assert
            Assert.Empty(labels);
        }
Ejemplo n.º 2
0
        public void AddClientIpLabel()
        {
            // Arrange
            var mockHttpContext = new Mock <HttpContext>();

            mockHttpContext.Setup(x => x.Connection.RemoteIpAddress).Returns(IPAddress.Loopback);

            var mockHttpContextAccessor = new Mock <IHttpContextAccessor>();

            mockHttpContextAccessor.Setup(x => x.HttpContext).Returns(mockHttpContext.Object);

            var instance = new ClientIpLogEntryLabelProvider(mockHttpContextAccessor.Object);
            var labels   = new Dictionary <string, string>();

            // Act
            instance.Invoke(labels);

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

            Assert.Equal("client_ip", label.Key);
            Assert.Equal(IPAddress.Loopback.ToString(), label.Value);
        }