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>(); }
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>(); }
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(); }
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>(); }
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); }
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); }