??????????????£?

????d??UnitTest

 

using System;
using MonitorService;
using MonitorService.Impl;
using Ninject;
using NUnit.Framework;

namespace UnitTestApp
{
    [TestFixture]
    public class MonitorServiceTest_Manual
    {
        public ConfigFileMonitor CurrentFileMonitor
        {
            get;
            set;
        }

        public ILogService LogService
        {
            get;
            set;
        }

        public IEmailService EmailService
        {
            get;
            set;
        }

        [SetUp]
        public void SetUp()
        {
            using (var kernel = new StandardKernel(new ServiceModule()))
            {
                this.CurrentFileMonitor = kernel.Get<ConfigFileMonitor>();
                this.CurrentFileMonitor.LogService = kernel.Get<StubLogService>();
                this.CurrentFileMonitor.EmailService = kernel.Get<MockEmailService>();
            }
        }

        [Test]
        public void FileMonitor_Inject_GetInstance()
        {
            Assert.IsNotNull(CurrentFileMonitor?? "ConfigFileMonitor is not initialized");
        }

        [Test]
        public void FileMonitor_LogService_Inject_GetInstance()
        {
            Assert.IsNotNull(CurrentFileMonitor.LogService?? "ConfigFileMonitor stub LogService is not initialized");
        }

        [Test]
        public void FileMonitor_EmailService_Inject_GetInstance()
        {
            Assert.IsNotNull(CurrentFileMonitor.EmailService?? "ConfigFileMonitor mock EmailService is not initialized");
        }

        [Test]
        public void Analyze_WebServiceThrows_SendEmail()
        {
            CurrentFileMonitor.LogService.ExToThrow = new NotImplementedException("fake exception");
            var shortFileName = "abc.txt";
            CurrentFileMonitor.Analyze(shortFileName);
            Assert.AreEqual(""mailto:jeffwong@cnblogs.com" jeffwong@cnblogs.com "?? CurrentFileMonitor.EmailService.To);
            Assert.AreEqual("filename check"?? CurrentFileMonitor.EmailService.Subject);
            Assert.AreEqual("fake exception"?? CurrentFileMonitor.EmailService.Body);
            //Assert.AreEqual("fake object"?? CurrentFileMonitor.EmailService.Body);
        }

        [TearDown]
        public void TearDown()
        {
            this.CurrentFileMonitor = null;
        }

    }
}

???????У???????????????Ninject??????????????Ч?????????????????????????????????????????

?????????????????????????ó???????α???????????????????Щ???????????????????īд????????????????????????????????????????????????????