コード例 #1
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);//失败,不知为何
        }
コード例 #2
0
        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);
        }
コード例 #3
0
        public void Analyze_WebServiceThrpws_SendsEmail()
        {
            FakeWebServiceException stubWebServiceException = new FakeWebServiceException();

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

            FakeEmailService mockEmailService = new FakeEmailService();

            LogAnalyzerEmalService logAnalyzerEmalService = new LogAnalyzerEmalService(stubWebServiceException, mockEmailService);

            string tooShortfileName = "abc.ext";

            logAnalyzerEmalService.Analyze(tooShortfileName);

            StringAssert.Contains("*****@*****.**", mockEmailService.To);
            StringAssert.Contains("can't log", mockEmailService.Subject);
            StringAssert.Contains("fake exception", mockEmailService.Body);
        }
コード例 #4
0
        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);
        }
コード例 #5
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);
        }
コード例 #6
0
        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)
        }