Пример #1
0
        public void Analyze_TooShortFileName_CallLogger()
        {
            // 只需設定ILogger interface
            ILogger     logger   = Substitute.For <ILogger>();
            LogAnalyzer analyzer = new LogAnalyzer(logger);

            analyzer.MinNameLength = 6;
            analyzer.Analyze("a.txt");
            // 詢問這個假物件是否被呼叫過
            //logger.Received().LogError("FileName too short:a.txt");
        }
Пример #2
0
        public void Analye_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"));
            var analyzer = new LogAnalyzer(stubLogger, mockWebService);

            analyzer.MinNameLength = 10;
            analyzer.Analyze("Short.txt");
            mockWebService.Received().Wrtie(Arg.Is <String>(s => s.Contains("fake Exception")));
        }
Пример #3
0
        public void Analye_LoggerThrows_CallsWebServiceWithNSubObjectCompare()
        {
            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"));
            var analyzer = new LogAnalyzer(stubLogger, mockWebService);

            analyzer.MinNameLength = 10;
            analyzer.Analyze("Short.txt");
            mockWebService.Received().Wrtie(Arg.Is <String>(s => s.Contains("fake Exception")));
            //mockWebService.Received().Wrtie(Arg.Is<string>(info =>
            //{
            //    return info.Severity == 1000 && info.Message.Contains("fake Exception");
            //}));

            //var expected = new ErrorInfo(1000, "fake Exception");
            //mockWebService.Received().ErrorInfoWrtie(expected);
        }