コード例 #1
0
        public static void LogProcessor___Valid___Works()
        {
            var tempFileName = Path.GetTempFileName();

            try
            {
                // Arrange
                var configuration = new FileLogConfig(LogInclusionKindToOriginsMaps.ExceptionsFromAnywhere, tempFileName);
                var processor     = new FileLogWriter(configuration);

                var infoCanary  = A.Dummy <string>();
                var errorCanary = new ArgumentException(A.Dummy <string>());

                // Act
                processor.Log(infoCanary.ToLogEntry().ToLogItem(LogItemOrigin.ItsLogEntryPosted));
                processor.Log(errorCanary.ToLogEntry().ToLogItem(LogItemOrigin.ItsLogEntryPosted));

                // Assert
                var fileContents = File.ReadAllText(tempFileName);
                fileContents.Should().NotContain(infoCanary);
                fileContents.Should().Contain(errorCanary.Message);
            }
            finally
            {
                if (File.Exists(tempFileName))
                {
                    File.Delete(tempFileName);
                }
            }
        }
コード例 #2
0
        public static void LogProcessor___Valid___Works()
        {
            var tempDirectory = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString());

            try
            {
                // Arrange
                var configuration = new TimeSlicedFilesLogConfig(LogInclusionKindToOriginsMaps.AnythingFromAnywhere, tempDirectory, "TestFile", TimeSpan.FromMinutes(1));
                var processor     = new TimeSlicedFilesLogWriter(configuration);

                var infoCanary  = A.Dummy <string>();
                var errorCanary = new ArgumentException(A.Dummy <string>());

                // Act
                processor.Log(infoCanary.ToLogEntry().ToLogItem(LogItemOrigin.ItsLogEntryPosted));
                processor.Log(errorCanary.ToLogEntry().ToLogItem(LogItemOrigin.ItsLogEntryPosted));

                // Assert
                var files = Directory.GetFiles(tempDirectory);
                files.Should().NotBeEmpty();
            }
            finally
            {
                if (Directory.Exists(tempDirectory))
                {
                    Directory.Delete(tempDirectory, true);
                }
            }
        }
コード例 #3
0
        public static void LogProcessor___Valid___Works()
        {
            using (var consoleOut = new StringWriter(CultureInfo.CurrentCulture))
            {
                using (var consoleError = new StringWriter(CultureInfo.CurrentCulture))
                {
                    // Arrange
                    var infoCanary   = A.Dummy <string>();
                    var errorCanary  = new ArgumentException(A.Dummy <string>());
                    var logProcessor = new ConsoleLogWriter(new ConsoleLogConfig(LogInclusionKindToOriginsMaps.AnythingFromAnywhere, LogInclusionKindToOriginsMaps.StringAndObjectsFromItsLogEntryPosted, LogInclusionKindToOriginsMaps.ExceptionsFromAnywhere));
                    Console.SetOut(consoleOut);
                    Console.SetError(consoleError);

                    // Act
                    logProcessor.Log(infoCanary.ToLogEntry().ToLogItem(LogItemOrigin.ItsLogEntryPosted));
                    logProcessor.Log(errorCanary.ToLogEntry().ToLogItem(LogItemOrigin.ItsLogEntryPosted));

                    var consoleOutOutput   = consoleOut.ToString();
                    var consoleErrorOutput = consoleError.ToString();

                    // Assert
                    consoleOutOutput.Should().Contain(infoCanary);
                    consoleOutOutput.Should().NotContain(errorCanary.Message);
                    consoleErrorOutput.Should().Contain(errorCanary.Message);
                    consoleErrorOutput.Should().NotContain(infoCanary);
                }
            }
        }
コード例 #4
0
        public static void LogProcessor___Valid___Works()
        {
            // Arrange
            var configuration = new InMemoryLogConfig(LogInclusionKindToOriginsMaps.AnythingFromAnywhere);
            var processor     = new InMemoryLogWriter(configuration);

            var infoCanary  = A.Dummy <string>();
            var errorCanary = new ArgumentException(A.Dummy <string>());

            // Act
            processor.Log(infoCanary.ToLogEntry().ToLogItem(LogItemOrigin.ItsLogEntryPosted));
            processor.Log(errorCanary.ToLogEntry().ToLogItem(LogItemOrigin.ItsLogEntryPosted));

            // Assert
            processor.LoggedItems.Count.Should().Be(2);
            processor.LoggedItems.Single(_ => _.Context.Origin == LogItemOrigin.ItsLogEntryPosted.ToString() && _.Kind == LogItemKind.String).Subject.Summary.Should().Contain(infoCanary);
            processor.LoggedItems.Single(_ => _.Context.Origin == LogItemOrigin.ItsLogEntryPosted.ToString() && _.Kind == LogItemKind.Exception).Subject.Summary.Should().Contain(errorCanary.Message);
        }