??????????????

????1????д?????????????????

????д??????????????????????????????????????????????????????????????????????????????????壬???????????д?????????????????????????????

??????1?????д???????????????N??α??????TMD??????????д????????д????????

??????2????Щ?????????????????????????????????????к????з?????д????????д????????

??????3???Щ??????????????????????д???????????????????д????????д????????

??????4????????????????ε????????漰???????????????????д??????д????????д????????

??????5??д??????????????????????????????????TMD???д??飬д????????д????????

???????????????????????????д????????????????????????????д?????????????????????????????????????????????????????????????????????????????????д??????????????á?

????????ó????????д???е????????e???????????????????????????????????????????????????????????????????????????????????????????...

???????????????????????ж??????????????д???????????Ψ???????

????2??????????

?????????????е????????????????????Rhino Mocks(????????????)???????????????????????????????????????е???????

??????1???????????LogService

var mock = new Rhino.Mocks.MockRepository();
            var logService = mock.Stub<ILogService>();
            CurrentFileMonitor.LogService = logService;
            Assert.IsNotNull(CurrentFileMonitor.LogService?? "ConfigFileMonitor stub LogService is not initialized");

??????2????????????EmailService

var mock = new Rhino.Mocks.MockRepository();
            var emailService = mock.DynamicMock<IEmailService>();
            CurrentFileMonitor.EmailService = emailService;
            Assert.IsNotNull(CurrentFileMonitor.EmailService?? "ConfigFileMonitor mock EmailService is not initialized");

??????3?????????

????a??????????-??????

/// <summary>
        /// ??????-????????????
        /// </summary>
        [Test]
        public void RhinoMocks_Analyze_WebServiceThrows_SendEmail()
        {
            var mock = new Rhino.Mocks.MockRepository();
            var logService = mock.Stub<ILogService>();
            var emailService = mock.DynamicMock<IEmailService>();
            using (mock.Record())
            {
                logService.AppendLog("input filename(abc.txt) is too short");
                LastCall.Throw(new NotImplementedException("fake exception")); //????????????????
            }
            CurrentFileMonitor.LogService = logService;
            CurrentFileMonitor.EmailService = emailService;

            var shortFileName = "abc.txt";
            CurrentFileMonitor.Analyze(shortFileName);

            mock.Verify(emailService);//VerifyAll()????Verify(stub)?????????????κζ?????????????????????
        }

????b??????-????-????(AAA)???

/// <summary>
        /// ????-????-????????????? ??Arrange-Act-Assert AAA??
        /// </summary>
        [Test]
        public void RhinoMocks_Analyze_WebServiceThrows_SendEmail_AAA()
        {
            var mock = new Rhino.Mocks.MockRepository();
            var logService = mock.Stub<ILogService>();
            logService.Expect(svc => svc.AppendLog("input filename(abc.txt) is too short"))
                      .Throw(new NotImplementedException("fake exception")); //????????????????

            var emailService = mock.DynamicMock<IEmailService>();
            CurrentFileMonitor.LogService = logService;
            CurrentFileMonitor.EmailService = emailService;

            mock.ReplayAll(); //?????????

            var shortFileName = "abc.txt";
            CurrentFileMonitor.Analyze(shortFileName);

            //???Rhino Mocks??????
            emailService.AssertWasCalled(m => m.SendEmail(mailto:jeffwong@cnblogs.com">jeffwong@cnblogs.com;?? "filename check"?? "fake exception"));//???
            //emailService.AssertWasCalled(m => m.SendEmail(mailto:it@cnblogs.com it@cnblogs.com;"filename check"?? "fake exception"));//???
        }

?????????????????-?????????AAA??Arrange-Act-Assert????????-????-????????????Rhino Mocks????α??????в??????????????????????AAA?????????У?д???????????????????????С???????????????????????demo????????

???????????????????????Moq??Typemock Isolator??EasyMock.NET??NMock??NUnit.Mocks??????Moq????????????????????????????ο????Щ??????????????Щд??????Rhino Mocks?????????????????Moq?????AAAд????Rhino Mocks??????????????AAA??????Moq??????????ο?????????

?????????????????£?????и????????????????????????н??е???????????????????????????????????????????????????????????????????????а???????????????????????????????????????????????????????????????????????????д?????????????????????????????????????????????????????