Exemplo n.º 1
0
        /// <inheritdoc/>
        public virtual void AddContextInfomation(ContextLogParametersBase logParameters)
        {
            Check.NotNull(logParameters, nameof(logParameters));

            ResponseTime = _timeProvider.UtcNow;
            StatusCode   = logParameters.DescriptionFromStatusCode;
            Ip           = logParameters.RemoteIpAddress;
            Exception    = logParameters.Exception;
        }
Exemplo n.º 2
0
        public void SetBaseCaughtExceptionShowsInResponse()
        {
            ContextLogParametersBase logParameters = null;

            logger.Setup(c => c.AddContextInfomation(It.IsAny <ContextLogParametersBase>()))
            .Callback <ContextLogParametersBase>(c => logParameters = c);

            var exception = new Mock <BaseCaughtException>();

            exception.Setup(c => c.Message).Returns("exMessage");
            exception.Setup(c => c.StackTrace).Returns("track123");
            exception.Setup(c => c.ResponseCode).Returns(HttpStatusCode.ProxyAuthenticationRequired);
            exception.Setup(c => c.HttpErrorMessage).Returns("test");

            registerMiddleware = app =>
            {
                app.UseMiddleware <AddLoggingDataTestMiddleware>();
                app.UseMiddleware <LogRequestAndResponseMiddleware>();
                app.UseMiddleware <ThrowExceptionMiddleware>(exception.Object);
                app.UseMiddleware <EndOfPipeLineTestMiddleware>();
            };

            Mock <ITimeProvider> timeProvider = new Mock <ITimeProvider>();

            timeProvider.Setup(c => c.UtcNow).Returns(new DateTime(2020, 1, 1));

            logger.SetupAllProperties();
            logger.Setup(c => c.LogCount).Returns(1);

            TestServer          testServer = new TestServer(builder);
            HttpClient          client     = testServer.CreateClient();
            HttpResponseMessage response   = client.GetAsync("/").Result;

            Assert.AreEqual("exMessage", logParameters.Exception);
            Assert.AreEqual("test", logParameters.StatusCode);
        }