public void Analyze_LoggerThrows_CallsWebService() { var mockWebService = Substitute.For<IWebService>(); var stubLogger = Substitute.For<ILogger>(); stubLogger.When(logger => logger.LogError(Arg.Any<string>())) .Do(info => { throw new Exception("fake exception"); }); LogAnalyzer2 analyzer = new LogAnalyzer2(stubLogger, mockWebService); analyzer.MinNameLength = 10; analyzer.Analyze("Short.txt"); mockWebService.Received() .Write(Arg.Is<string>(s => s.Contains("fake exception"))); }
public void Analyze_LoggerThrows_CallsWebService() { FakeWebService mockWebService = new FakeWebService(); FakeLogger2 stubLogger = new FakeLogger2(); stubLogger.WillThrow = new Exception("fake exception"); LogAnalyzer2 analyzer2 = new LogAnalyzer2(stubLogger, mockWebService); analyzer2.MinNameLength = 8; string tooShortFileName="abc.ext"; analyzer2.Analyze(tooShortFileName); Assert.That(mockWebService.MessageToWebService, Is.StringContaining("fake exception")); }