Ejemplo n.º 1
0
        public void OnExceptionIsExecutedWhenApiResultHasException()
        {
            Logger logger = new Logger();

            ExceptionArgs exceptionArgs = null;

            FlushLogArgs            flushArgs = FlushLogArgsFactory.Create(new[] { logger });
            CreateRequestLogRequest request   = PayloadFactory.Create(flushArgs);

            var kisslogApi = new Mock <IPublicApi>();

            kisslogApi.Setup(p => p.CreateRequestLog(It.IsAny <CreateRequestLogRequest>(), It.IsAny <IEnumerable <File> >()))
            .Returns(new ApiResult <RequestLog>
            {
                Exception = new ApiException
                {
                    ErrorMessage = $"Error {Guid.NewGuid()}"
                }
            });

            FlushOptions options = new FlushOptions
            {
                UseAsync    = false,
                OnException = (ExceptionArgs args) =>
                {
                    exceptionArgs = args;
                }
            };

            Flusher.FlushAsync(options, kisslogApi.Object, flushArgs, request).ConfigureAwait(false);

            Assert.IsNotNull(exceptionArgs);
        }
Ejemplo n.º 2
0
        public void ChangesFlushLogArgsFiles()
        {
            Logger logger = new Logger();

            logger.LogAsFile("Content 1", "File1.txt");
            logger.LogAsFile("Content 2", "File2.txt");

            FlushLogArgs             flushArgs = FlushLogArgsFactory.Create(new[] { logger });
            IEnumerable <LoggedFile> files     = flushArgs.Files;

            CreateRequestLogRequest request = PayloadFactory.Create(flushArgs);

            var kisslogApi = new Mock <IPublicApi>();

            kisslogApi.Setup(p => p.CreateRequestLog(It.IsAny <CreateRequestLogRequest>(), It.IsAny <IEnumerable <File> >()))
            .Returns(new ApiResult <RequestLog>());

            Flusher.FlushAsync(new FlushOptions {
                UseAsync = false
            }, kisslogApi.Object, flushArgs, request).ConfigureAwait(false);

            Assert.AreNotSame(files, flushArgs.Files);
            Assert.AreEqual(files.Count(), flushArgs.Files.Count());

            logger.Reset();
        }
Ejemplo n.º 3
0
        public void CreateRequestPropertiesCopiesAllProperties()
        {
            KissLog.Http.RequestProperties requestProperties = CommonTestHelpers.Factory.CreateRequestProperties();
            var result = PayloadFactory.Create(requestProperties);

            TestRequestProperties(requestProperties, result);
        }
Ejemplo n.º 4
0
        public void CreateExceptionCopiesAllProperties()
        {
            CapturedException exception = CommonTestHelpers.Factory.CreateCapturedException();
            var result = PayloadFactory.Create(exception);

            TestCapturedException(exception, result);
        }
Ejemplo n.º 5
0
        public void CreateCopiesAllProperties()
        {
            FlushLogArgs args        = CommonTestHelpers.Factory.CreateFlushLogArgs();
            var          logMessages = args.MessagesGroups.SelectMany(p => p.Messages).OrderBy(p => p.DateTime).ToList();

            var result = PayloadFactory.Create(args);

            Assert.IsNotNull(result.SdkName);
            Assert.IsNotNull(result.SdkVersion);
            Assert.AreEqual(args.HttpProperties.Request.StartDateTime, result.StartDateTime);
            Assert.IsTrue(result.DurationInMilliseconds >= 0);
            Assert.AreEqual(args.HttpProperties.Request.MachineName, result.MachineName);
            Assert.AreEqual(args.HttpProperties.Request.IsNewSession, result.IsNewSession);
            Assert.AreEqual(args.HttpProperties.Request.SessionId, result.SessionId);
            Assert.AreEqual(args.HttpProperties.Request.IsAuthenticated, result.IsAuthenticated);
            Assert.IsNull(result.User);
            Assert.AreEqual(logMessages.Count, result.LogMessages.Count());
            Assert.AreEqual(args.Exceptions.Count(), result.Exceptions.Count());
            Assert.AreEqual(args.CustomProperties.Count(), result.CustomProperties.Count);

            for (int i = 0; i < logMessages.Count; i++)
            {
                TestLogMessage(logMessages[i], result.LogMessages.ElementAt(i));
            }

            for (int i = 0; i < args.Exceptions.Count(); i++)
            {
                TestCapturedException(args.Exceptions.ElementAt(i), result.Exceptions.ElementAt(i));
            }
        }
Ejemplo n.º 6
0
        public void CreateUriCopiesAllTheProperties()
        {
            Uri uri    = new Uri("http://application/path1/path2?param1=value&param2=anotherValue");
            Url result = PayloadFactory.Create(uri);

            TestUrl(uri, result);
        }
Ejemplo n.º 7
0
        public void CreateResponsePropertiesCopiesAllProperties()
        {
            KissLog.Http.HttpResponse httpResponse = CommonTestHelpers.Factory.CreateHttpResponse();
            var result = PayloadFactory.Create(httpResponse);

            TestResponseProperties(httpResponse, result);
        }
Ejemplo n.º 8
0
        public void CreateLogMessageCopiesAllProperties()
        {
            DateTime startRequestDateTime = DateTime.UtcNow.AddSeconds(-5);

            LogMessage message = CommonTestHelpers.Factory.CreateLogMessage();
            var        result  = PayloadFactory.Create(message, startRequestDateTime);

            TestLogMessage(message, result);
        }
Ejemplo n.º 9
0
        public void CreateHttpPropertiesCopiesAllProperties()
        {
            KissLog.Http.HttpProperties httpProperties = CommonTestHelpers.Factory.CreateHttpProperties();
            var result = PayloadFactory.Create(httpProperties);

            TestUrl(httpProperties.Request.Url, result.Url);
            Assert.AreEqual(httpProperties.Request.UserAgent, result.UserAgent);
            Assert.AreEqual(httpProperties.Request.HttpMethod, result.HttpMethod);
            Assert.AreEqual(httpProperties.Request.HttpReferer, result.HttpReferer);
            Assert.AreEqual(httpProperties.Request.RemoteAddress, result.RemoteAddress);
            TestRequestProperties(httpProperties.Request.Properties, result.Request);
            TestResponseProperties(httpProperties.Response, result.Response);
        }
Ejemplo n.º 10
0
        public void CreatesACopyOfTheFilesAndDeletesThem(bool apiThrowsException)
        {
            Logger logger = new Logger();

            logger.LogAsFile("Content 1", "File1.txt");
            logger.LogAsFile("Content 2", "File2.txt");

            FlushLogArgs            flushArgs = FlushLogArgsFactory.Create(new[] { logger });
            CreateRequestLogRequest request   = PayloadFactory.Create(flushArgs);

            var kisslogApi = new Mock <IPublicApi>();

            kisslogApi.Setup(p => p.CreateRequestLog(It.IsAny <CreateRequestLogRequest>(), It.IsAny <IEnumerable <File> >())).Callback(() =>
            {
                if (apiThrowsException)
                {
                    throw new Exception();
                }
            })
            .Returns(new ApiResult <RequestLog>());

            Flusher.FlushAsync(new FlushOptions {
                UseAsync = false
            }, kisslogApi.Object, flushArgs, request).ConfigureAwait(false);

            IEnumerable <LoggedFile> flushArgsFiles = flushArgs.Files;
            IEnumerable <LoggedFile> loggerFiles    = logger.DataContainer.FilesContainer.GetLoggedFiles();

            foreach (var file in flushArgsFiles)
            {
                Assert.IsFalse(System.IO.File.Exists(file.FilePath));
            }

            foreach (var file in loggerFiles)
            {
                Assert.IsTrue(System.IO.File.Exists(file.FilePath));
            }

            logger.Reset();
        }
Ejemplo n.º 11
0
 public void CreateResponsePropertiesThrowsExceptionForNullArgument()
 {
     KissLog.Http.HttpResponse httpResponse = null;
     var result = PayloadFactory.Create(httpResponse);
 }
Ejemplo n.º 12
0
 public void CreateRequestPropertiesThrowsExceptionForNullArgument()
 {
     KissLog.Http.RequestProperties requestProperties = null;
     var result = PayloadFactory.Create(requestProperties);
 }
Ejemplo n.º 13
0
 public void CreateThrowsExceptionForNullArgument()
 {
     FlushLogArgs args   = null;
     var          result = PayloadFactory.Create(args);
 }
Ejemplo n.º 14
0
 public void CreateUriThrowsExceptionForNullArgument()
 {
     Uri uri    = null;
     var result = PayloadFactory.Create(uri);
 }
Ejemplo n.º 15
0
 public void CreateExceptionThrowsExceptionForNullArgument()
 {
     CapturedException exception = null;
     var result = PayloadFactory.Create(exception);
 }
Ejemplo n.º 16
0
 public void CreateLogMessageThrowsExceptionForNullArgument()
 {
     LogMessage message = null;
     var        result  = PayloadFactory.Create(message, DateTime.UtcNow);
 }