AOUT.CH5.LogAn.LogAnalyzer2.Analyze C# (CSharp) Method

Analyze() public method

public Analyze ( string fileName ) : void
fileName string
return void
        public void Analyze(string fileName)
        {
            if(fileName.Length<8)
            {
                try
                {
                    service.LogError("Filename too short:" + fileName);
                }
                catch (Exception e)
                {
                    email.SendEmail("a","subject",e.Message);
                }
            }
        }

Usage Example

        public void Analyze_WebServiceThrows_SendsEmail()
        {
            MockRepository mocks = new MockRepository();
            IWebService stubService = mocks.Stub<IWebService>();
            IEmailService mockEmail =mocks.CreateMock<IEmailService>();

            using(mocks.Record())
            {
                stubService.LogError("whatever");
                LastCall.Constraints(Is.Anything());
                LastCall.Throw(new Exception("fake exception"));

                mockEmail.SendEmail("a","subject","fake exception");
            }

            LogAnalyzer2 log = new LogAnalyzer2();
            log.Service = stubService;
            log.Email = mockEmail;

            string tooShortFileName = "abc.ext";
            log.Analyze(tooShortFileName);

            mocks.VerifyAll();
        }
LogAnalyzer2