Beispiel #1
0
        public void Close_WhenLoggingSeveralErroringCheck_ThenWriteOneLinePerFailure()
        {
            var fileHelper = new Mock<IFileHelper>();
            var logger = new FileLogger(fileHelper.Object);

            logger.Log(new Check
            {
                Url = "http://www.google.com/",
                Status = 500
            });

            logger.Log(new Check
            {
                Url = "http://www.google.co.uk/",
                Status = 500
            });

            logger.Close();

            fileHelper.Verify(f => f.WriteLine(It.IsAny<string>(), It.IsAny<string>()), Times.Exactly(2));
        }
Beispiel #2
0
        public void Close_WhenACheckFailsButEventuallyPasses_ThenItShouldNotGetLogged()
        {
            const string passingUrl = "http://www.google.com/";
            const string failingUrl = "http://www.yahoo.com/";

            var helper = new Mock<IFileHelper>();
            helper.Setup(m => m.CreateFile(It.IsAny<string>()));
            helper.Setup(m => m.FileExists(It.IsAny<string>())).Returns(false);
            helper.Setup(m => m.WriteLine(It.IsAny<string>(), It.IsAny<string>()));

            var logger = new FileLogger(helper.Object);

            var check = new Check
            {
                Url = passingUrl,
                Status = 500
            };

            logger.Log(check);

            check.Status = Check.Ok;

            logger.Log(check);

            var failedCheck = new Check
                {
                    Url = failingUrl,
                    Status = 500
                };

            logger.Log(failedCheck);

            logger.Close();

            helper.Verify(f => f.FileExists(It.IsAny<string>()), Times.Once());
            helper.Verify(f => f.CreateFile(It.IsAny<string>()), Times.Once());
            helper.Verify(f => f.WriteLine(It.IsAny<string>(), failingUrl), Times.Once());
            helper.Verify(f => f.WriteLine(It.IsAny<string>(), passingUrl), Times.Never());
        }
Beispiel #3
0
        public void Close_WhenOnlyAnOkCheckHasBeenLogged_NoFileOperationsShouldBeCalled()
        {
            var fileHelper = new Mock<IFileHelper>();
            var logger = new FileLogger(fileHelper.Object);

            logger.Log(new Check
            {
                Url = "http://www.google.com/",
                Status = Check.Ok
            });

            logger.Close();

            VerifyNoFileOperations(fileHelper);
        }
Beispiel #4
0
        private static void LoggedAnErroringCheckThenClosed(Mock<IFileHelper> fileHelper)
        {
            var logger = new FileLogger(fileHelper.Object);

            logger.Log(new Check
            {
                Url = "http://www.google.com/",
                Status = 500
            });

            logger.Close();
        }
Beispiel #5
0
        public void Log_WhenLoggingWithOkCheck_ThereAreNoFileOperationsCalled()
        {
            var fileHelper = new Mock<IFileHelper>();
            var logger = new FileLogger(fileHelper.Object);

            logger.Log(new Check
            {
                Url = "http://www.google.com/",
                Status = Check.Ok
            });

            VerifyNoFileOperations(fileHelper);
        }
Beispiel #6
0
        public void FileLogger_ImplementsILogger()
        {
            var logger = new FileLogger(new Mock<IFileHelper>().Object);

            Assert.That(logger, Is.InstanceOf<ILogger>());
        }
Beispiel #7
0
        public void Close_WhenThereIsOneCheckWhichFailedButEventuallyPassed_ThenItShouldNotCreateTheFile()
        {
            var helper = new Mock<IFileHelper>();
            helper.Setup(m => m.CreateFile(It.IsAny<string>()));
            helper.Setup(m => m.FileExists(It.IsAny<string>())).Returns(false);
            helper.Setup(m => m.WriteLine(It.IsAny<string>(), It.IsAny<string>()));

            var logger = new FileLogger(helper.Object);

            var check = new Check
                {
                    Url = "http://www.google.com/",
                    Status = 500
                };

            logger.Log(check);

            check.Status = Check.Ok;

            logger.Log(check);

            logger.Close();

            helper.Verify(f => f.FileExists(It.IsAny<string>()), Times.Never());
            helper.Verify(f => f.CreateFile(It.IsAny<string>()), Times.Never());
            helper.Verify(f => f.WriteLine(It.IsAny<string>(), It.IsAny<string>()), Times.Never());
        }