Beispiel #1
0
        public void Analyze_WebServiceThrow_EmailInfo_SendsEmail()
        {
            FakeWebService stubService = new FakeWebService();

            stubService.ToThrow = new Exception("fake exception");

            FakeEmailService_WithProperties mockEmail =
                new FakeEmailService_WithProperties();

            LogAnalyzer2_FromBook_2dExample log =
                new LogAnalyzer2_FromBook_2dExample(stubService, mockEmail);

            string tooShortFileName = "abc.ext";

            log.Analyze(tooShortFileName);

            EmailInfo expectedEmail = new EmailInfo
            {
                Body    = "fake exception",
                To      = "*****@*****.**",
                Subject = "can't log"
            };

            Assert.AreEqual(expectedEmail, mockEmail.email);
        }
Beispiel #2
0
        public void Analyze_WebServiceThrows_SendsEmail()
        {
            FakeWebService stubService = new FakeWebService();

            stubService.ToThrow = new Exception("fake exception");

            FakeEmailService mockEmailService = new FakeEmailService();

            LogAnalyzer2 log = new LogAnalyzer2(stubService, mockEmailService);

            string tooShortFileName = "abc.ext";

            log.Analyze(tooShortFileName);

            EmailInfo expectedEmail = new EmailInfo()
            {
                Body    = "fake exception",
                To      = "*****@*****.**",
                Subject = "can't log"
            };

            StringAssert.AreEqualIgnoringCase(expectedEmail.Body, mockEmailService.Email.Body);
            StringAssert.AreEqualIgnoringCase(expectedEmail.To, mockEmailService.Email.To);
            StringAssert.AreEqualIgnoringCase(expectedEmail.Subject, mockEmailService.Email.Subject);

            Assert.AreEqual(expectedEmail.Body, mockEmailService.Email.Body);
            Assert.AreEqual(expectedEmail.To, mockEmailService.Email.To);
            Assert.AreEqual(expectedEmail.Subject, mockEmailService.Email.Subject);

            Assert.AreEqual(expectedEmail, mockEmailService.Email);//失败,不知为何
        }
Beispiel #3
0
        public void Analyze_TooShortFileName_CallsWebService()
        {
            FakeWebService mockService      = new FakeWebService();
            LogAnalyzer    log              = new LogAnalyzer(mockService);
            string         tooShortFileName = "abc.ext";

            log.IsValidLogFileName(tooShortFileName);

            StringAssert.Contains("Filename too short: abc.ext", mockService.LastError);
        }
        public void Analyze_LongEnoughFileName_CallsWebService()
        {
            FakeWebService mockService      = new FakeWebService();
            LogAnalyzer    logAn            = new LogAnalyzer(mockService);
            string         tooShortFileName = "abcdefgh.ext";

            logAn.Analyze(tooShortFileName);

            Assert.IsNull(mockService.LastError);
        }
Beispiel #5
0
        public void Analyze_TooShortFileName_CallsWebService()
        {
            FakeWebService        mockService           = new FakeWebService();
            LogAnalyzerWebService logAnalyzerWebService = new LogAnalyzerWebService(mockService);
            string tooShortFileName = "abc.ext";

            logAnalyzerWebService.Analyze(tooShortFileName);

            StringAssert.Contains("Filename is too short: " + tooShortFileName, mockService.LastError);
        }
        public void Analyze_TooShortFileName_CallsWebService()
        {
            FakeWebService stubService = new FakeWebService();

            FakeEmailService mockEmail = new FakeEmailService();

            LogAnalyzer logAn = new LogAnalyzer(stubService, mockEmail);

            string tooShortFileName = "abc.ext";

            logAn.Analyze(tooShortFileName);

            Assert.IsNull(mockEmail.To);
            Assert.IsNull(mockEmail.Body);
            Assert.IsNull(mockEmail.Subject);
        }
        public void Analyze_LongEnoughFileName_ReturnsNothing()
        {
            FakeWebService stubService = new FakeWebService();

            stubService.ToThrow = new Exception("fake exception");

            FakeEmailService mockEmail = new FakeEmailService();

            LogAnalyzer logAn = new LogAnalyzer(stubService, mockEmail);

            string tooShortFileName = "abcdefgh.ext";

            logAn.Analyze(tooShortFileName);

            Assert.IsNull(mockEmail.To);
            Assert.IsNull(mockEmail.Body);
            Assert.IsNull(mockEmail.Subject);
        }
Beispiel #8
0
        public void Analyze_WebServiceThrow_SendsEmail()
        {
            FakeWebService stubService = new FakeWebService();

            stubService.ToThrow = new Exception("fake exception");

            FakeEmailService mockEmail = new FakeEmailService();

            LogAnalyzer2_FromBook log = new LogAnalyzer2_FromBook(stubService, mockEmail);

            string tooShortFileName = "abc.ext";

            log.Analyze(tooShortFileName);

            StringAssert.Contains("*****@*****.**", mockEmail.To);
            StringAssert.Contains("fake exception", mockEmail.Body);
            StringAssert.Contains("can't log", mockEmail.Subject);
        }
        public void Analyze_WebServiceThrows_SendsEmail()
        {
            FakeWebService stubService = new FakeWebService();

            stubService.ToThrow = new Exception("fake exception");

            FakeEmailService mockEmail = new FakeEmailService();

            LogAnalyzer logAn = new LogAnalyzer(stubService, mockEmail);

            string tooShortFileName = "abc.ext";

            logAn.Analyze(tooShortFileName);

            StringAssert.Contains("*****@*****.**", mockEmail.To);
            StringAssert.Contains("fake exception", mockEmail.Body);
            StringAssert.Contains("can't log", mockEmail.Subject);

            // Note: As soon as an assert fails, the test stops. If you want the other asserts to run, the To, Body, and Subject should be placed within a parameter object
            // 'expectedEmail' of EmailInfo, which corresponds to a property in the mock, and the following assert is used:
            // Assert.AreEqual(expectedEmail, mockEmail.Email)
        }