コード例 #1
0
ファイル: Listing5-6.cs プロジェクト: kalamaja/aout2
        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")));
        }
コード例 #2
0
ファイル: Listing5-5.cs プロジェクト: ndphuong/aout2
        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"));
        }