Example #1
0
        public void WhenConsoleLogIsEnabledShouldContainActiveDatabaseJobLogger()
        {
            //Arrange
            var jobLoggerBuilder = new JobLoggerBuilder(new JobLogger(), mockJobLoggerFactory.Object);
            var jobLogger        = jobLoggerBuilder.EnableDatabaseLog()
                                   .EnableErrorMessage()
                                   .Build();

            //Act
            jobLogger.LogMessage(MessageFixture.CreateError());

            //Assert
            jobLogger.ActiveLoggers[0].Should().NotBeNull();
            jobLogger.ActiveLoggers.Count.Should().NotBe(0);
            jobLogger.ActiveLoggers[0].Should().BeOfType <DatabaseJobLogger>();
        }
Example #2
0
        public void WhenJobLoggerDisabledAllMessagesTypeShouldThrowAnException()
        {
            //Arrange
            var jobLoggerBuilder = new JobLoggerBuilder(new JobLogger(), mockJobLoggerFactory.Object);
            var jobLogger        = jobLoggerBuilder.EnableConsoleLog()
                                   .Build();

            //Act
            Action action = () =>
            {
                jobLogger.LogMessage(MessageFixture.CreateError());
            };

            //Assert
            action.ShouldThrow <JobLoggerConfigurationException>();
        }
Example #3
0
        public void WhenJobLoggerEnableInfoLogErrorPropertyShouldBeTrue()
        {
            //Arrange
            var jobLoggerBuilder = new JobLoggerBuilder(new JobLogger(), mockJobLoggerFactory.Object);
            var jobLogger        = jobLoggerBuilder.EnableFileLog()
                                   .EnableInfoMessage()
                                   .Build();

            //Act
            jobLogger.LogMessage(MessageFixture.CreateError());

            //Assert
            jobLogger.LogErrors.Should().BeFalse();
            jobLogger.LogWarnings.Should().BeFalse();
            jobLogger.LogInfo.Should().BeTrue();
        }
Example #4
0
        public void WhenMessageTextIsEmptyShouldThrowAnException()
        {
            //Arrange
            var jobLoggerBuilder = new JobLoggerBuilder(new JobLogger(), mockJobLoggerFactory.Object);
            var jobLogger        = jobLoggerBuilder.EnableConsoleLog()
                                   .EnableInfoMessage()
                                   .Build();

            //Act
            Action action = () =>
            {
                jobLogger.LogMessage(MessageFixture.CreateNullMessageText());
            };

            //Assert
            action.ShouldThrow <JobLoggerConfigurationException>();
        }
Example #5
0
        public void WhenJobLoggerHasEnabledAllLoggerTypesShouldContainThreeInstancesOfIJobLogger()
        {
            //Arrange
            var jobLoggerBuilder = new JobLoggerBuilder(new JobLogger(), mockJobLoggerFactory.Object);
            var jobLogger        = jobLoggerBuilder.EnableFileLog()
                                   .EnableConsoleLog()
                                   .EnableDatabaseLog()
                                   .EnableErrorMessage()
                                   .Build();

            //Act
            jobLogger.LogMessage(MessageFixture.CreateError());

            //Assert
            jobLogger.ActiveLoggers[0].Should().NotBeNull();
            jobLogger.ActiveLoggers.Count.Should().Be(3);
        }
Example #6
0
        public void WhenEnableAllLoggersShouldCallThem()
        {
            //Arrange
            var jobLoggerBuilder = new JobLoggerBuilder(new JobLogger(), mockJobLoggerFactory.Object);
            var jobLogger        = jobLoggerBuilder.EnableConsoleLog()
                                   .EnableDatabaseLog()
                                   .EnableFileLog()
                                   .EnableInfoMessage()
                                   .EnableErrorMessage()
                                   .EnableWarningMessage()
                                   .Build();

            //Act
            jobLogger.LogMessage(MessageFixture.CreateError());

            //Assert
            mockDatabaseWriter.Verify(w => w.Save(It.IsAny <Message>()), Times.Once);
            mockFileWriter.Verify(w => w.WriteFile(It.IsAny <Message>()), Times.Once);
            mockOutputWriter.Verify(w => w.WriteLine(It.IsAny <Message>()), Times.Once);
        }