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); }
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(); }
public void CreateRequestPropertiesCopiesAllProperties() { KissLog.Http.RequestProperties requestProperties = CommonTestHelpers.Factory.CreateRequestProperties(); var result = PayloadFactory.Create(requestProperties); TestRequestProperties(requestProperties, result); }
public void CreateExceptionCopiesAllProperties() { CapturedException exception = CommonTestHelpers.Factory.CreateCapturedException(); var result = PayloadFactory.Create(exception); TestCapturedException(exception, result); }
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)); } }
public void CreateUriCopiesAllTheProperties() { Uri uri = new Uri("http://application/path1/path2?param1=value¶m2=anotherValue"); Url result = PayloadFactory.Create(uri); TestUrl(uri, result); }
public void CreateResponsePropertiesCopiesAllProperties() { KissLog.Http.HttpResponse httpResponse = CommonTestHelpers.Factory.CreateHttpResponse(); var result = PayloadFactory.Create(httpResponse); TestResponseProperties(httpResponse, result); }
public void CreateLogMessageCopiesAllProperties() { DateTime startRequestDateTime = DateTime.UtcNow.AddSeconds(-5); LogMessage message = CommonTestHelpers.Factory.CreateLogMessage(); var result = PayloadFactory.Create(message, startRequestDateTime); TestLogMessage(message, result); }
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); }
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(); }
public void CreateResponsePropertiesThrowsExceptionForNullArgument() { KissLog.Http.HttpResponse httpResponse = null; var result = PayloadFactory.Create(httpResponse); }
public void CreateRequestPropertiesThrowsExceptionForNullArgument() { KissLog.Http.RequestProperties requestProperties = null; var result = PayloadFactory.Create(requestProperties); }
public void CreateThrowsExceptionForNullArgument() { FlushLogArgs args = null; var result = PayloadFactory.Create(args); }
public void CreateUriThrowsExceptionForNullArgument() { Uri uri = null; var result = PayloadFactory.Create(uri); }
public void CreateExceptionThrowsExceptionForNullArgument() { CapturedException exception = null; var result = PayloadFactory.Create(exception); }
public void CreateLogMessageThrowsExceptionForNullArgument() { LogMessage message = null; var result = PayloadFactory.Create(message, DateTime.UtcNow); }