예제 #1
0
        public void RunsExecuteOnExit_OnRegularExit()
        {
            var subBackup = new FakeScmBackup();
            var context   = new FakeContext();
            var logger    = new FakeLogger();

            var sut = new ErrorHandlingScmBackup(subBackup, logger, context);

            sut.Run();

            Assert.True(logger.ExecutedOnExit);
            Assert.True(logger.ExecuteOnExit_Successful);
        }
예제 #2
0
        public void RunsExecuteOnExit_WhenExceptionIsThrown()
        {
            var subBackup = new FakeScmBackup();

            subBackup.ToThrow = new Exception("!!");

            var context = new FakeContext();
            var logger  = new FakeLogger();

            var sut = new ErrorHandlingScmBackup(subBackup, logger, context);

            sut.Run();

            Assert.True(logger.ExecutedOnExit);
            Assert.False(logger.ExecuteOnExit_Successful);
        }
예제 #3
0
        static (FakeEmailSender mail, LogMailingScmBackup sut) BuildFakeLogMailingScmBackup(bool innerReturnValue)
        {
            var subBackup = new FakeScmBackup();

            subBackup.ToReturn = innerReturnValue;

            var messages = new LogMessages();

            messages.AddMessage("1");
            messages.AddMessage("2");

            var mail = new FakeEmailSender();

            var sut = new LogMailingScmBackup(subBackup, messages, mail);

            return(mail, sut);
        }
예제 #4
0
        static (FakeLogger FakeLogger, ErrorHandlingScmBackup ErrorHandlingScmBackup) BuildFakeScmBackup()
        {
            var ex        = new Exception("!!!");
            var subBackup = new FakeScmBackup();

            subBackup.ToThrow = ex;

            var conf = new FakeConfigReader();

            conf.SetDefaultFakeConfig();

            var context = new FakeContext();

            var logger = new FakeLogger();

            var backup = new ErrorHandlingScmBackup(subBackup, logger, context);

            return(logger, backup);
        }
예제 #5
0
        public void RunSendsMail()
        {
            var subBackup = new FakeScmBackup();

            var messages = new LogMessages();

            messages.AddMessage("1");
            messages.AddMessage("2");

            var mail = new FakeEmailSender();

            var sut = new LogMailingScmBackup(subBackup, messages, mail);

            sut.Run();

            Assert.NotNull(mail.LastSubject);
            Assert.NotNull(mail.LastBody);
            Assert.Contains("1", mail.LastBody);
            Assert.Contains("2", mail.LastBody);
        }
        public void LogsWhenExceptionIsThrown()
        {
            var ex        = new Exception("!!!");
            var subBackup = new FakeScmBackup();

            subBackup.ToThrow = ex;

            var conf = new FakeConfigReader();

            conf.SetDefaultFakeConfig();

            var context = new FakeContext();

            var logger = new FakeLogger();

            var backup = new ErrorHandlingScmBackup(subBackup, logger, context);

            backup.Run();

            Assert.True(logger.LoggedSomething);
            Assert.Equal(ErrorLevel.Error, logger.LastErrorLevel);
            // we can't check whether the last exception is the exception from above,
            // because there are more logging outputs after the exception.
        }