public void Analyze_WebServiceThrows_SendEmail_Ver2() { FakeWebService stubService = new FakeWebService(); stubService.ToThrow = new Exception("fake exception"); FakeEmailServiceVer2 mockEmail = new FakeEmailServiceVer2(); LogAnalyzerCh4withTwoServiceVer2 log = new LogAnalyzerCh4withTwoServiceVer2(stubService, mockEmail); string tooShortFileName = "abc.ext"; log.Analyze(tooShortFileName); EmailInfo expectedEmail = new EmailInfo() { Body = "fake exception", To = "*****@*****.**", Subject = "can't log" }; //書本內容有點錯 //因為是比位址,所以不能兩個class去比,除非兩個class一樣, //ex: var a = b = new class //範例是 EmailInfo vs FakeEmailServiceVer2.EmailInfo 所以比對會不過 //也可以用 Assert.AreSame Assert.AreEqual(expectedEmail.Body, mockEmail.email.Body); Assert.AreEqual(expectedEmail.To, mockEmail.email.To); Assert.AreEqual(expectedEmail.Subject, mockEmail.email.Subject); }
public void Analyze_TooShortFileName_CallWebService() { FakeWebService mockService = new FakeWebService(); LogAnalyzerCh4 log = new LogAnalyzerCh4(mockService); string tooShortFileName = "abc.ext"; log.Analyze(tooShortFileName); StringAssert.Contains("FileName too short:abc.ext", mockService.LastError); }
public void Analyse_WithInvalidFilename_ReturnsFalse() { var webService = new FakeWebService(); var emailService = new FakeEmailService(); var logAnalyser = new LogAnalyser(webService, emailService); bool result = logAnalyser.Analyse(string.Empty); Assert.AreEqual(false, result); }
public void Analyse_WithInvalidFilename_CallsWebService() { var webService = new FakeWebService(); var emailService = new FakeEmailService(); var logAnalyser = new LogAnalyser(webService, emailService); logAnalyser.Analyse(string.Empty); Assert.AreEqual(true, webService.IsLogErrorCalled); }
public void Analyse_ExceptionRaised_CallsEmailService() { var webService = new FakeWebService(); webService.RaiseExceptionForLogError = true; var emailService = new FakeEmailService(); var logAnalyser = new LogAnalyser(webService, emailService); logAnalyser.Analyse(string.Empty); Assert.AreEqual(true, emailService.IsSendEmailCalled); }
public void IsLoginOK_LoggerThrowsException_CallsToWebService() { FakeLogger2 stubLog = new FakeLogger2(); stubLog.WillThrow = new LoggerException("fake exception"); FakeWebService mockService = new FakeWebService(); LoginManagerWithMockAndStub loginManager = new LoginManagerWithMockAndStub(stubLog, mockService); loginManager.IsLoginOK("", ""); StringAssert.Contains("got exception", mockService.Message); }
public void Analyze_WebServiceThrows_SendsEmail() { FakeWebService stubService = new FakeWebService(); stubService.ToThrow = new Exception("fake exception"); FakeEmailService mockEmail = new FakeEmailService(); LogAnalyzer2 log = new LogAnalyzer2(stubService, mockEmail); string tooShortFileName = "abc.txt"; log.Analyze(tooShortFileName); StringAssert.Contains("*****@*****.**", mockEmail.To); StringAssert.Contains("fake exception", mockEmail.Body); StringAssert.Contains("can't log", mockEmail.Subject); }
public void IsLoginOK_LoggerThrowsException_CallsToWebService() { FakeLogger2 stubLog = new FakeLogger2(); stubLog.WillThrow = new LoggerException("fake exception"); FakeWebService mockService = new FakeWebService(); LoginManagerWithMockAndStub loginManager = new LoginManagerWithMockAndStub(stubLog, mockService); loginManager.IsLoginOK("", ""); StringAssert.Contains("got exception", mockService.Message); }
public void Analyze_TooShortFileName_CallsWebService() { FakeWebService stubService = new FakeWebService(); stubService.ToThrow = new Exception("fake exception"); FakeEmailService mockService = new FakeEmailService(); LogAnalyzer4 log = new LogAnalyzer4(stubService, mockService); string tooShortFileName = "abc.ext"; log.Analyze(tooShortFileName); //create expected EmailInfo expectedEmailInfo = new EmailInfo("*****@*****.**", "can't log", "fake exception"); Assert.AreEqual(expectedEmailInfo, mockService.email); }
public void Analyze_TooShortFileName_CallsWebService() { FakeWebService stubService = new FakeWebService(); stubService.ToThrow = new Exception("fake exception"); FakeEmailService mockEmail = new FakeEmailService(); LogAnalyzer2 log = new LogAnalyzer2(stubService, mockEmail); string tooShortFileName = "abc.ext"; log.Analyze(tooShortFileName); EmailInfo expectedEmail = new EmailInfo { Body = "fake exception", To = "*****@*****.**", Subject = "can’t log" }; Assert.AreSame(expectedEmail, mockEmail.email); }