コード例 #1
0
        public void AddScoutTest()
        {
            IUnityContainer          unityContainer       = new UnityContainer();
            Mock <IScoutsRepository> scoutsRepositoryMock = new Mock <IScoutsRepository>();
            Mock <ICampsRepository>  campRepositoryMock   = new Mock <ICampsRepository>();
            Mock <ILoggerService>    loggerServiceMock    = new Mock <ILoggerService>();

            unityContainer.RegisterType <IScoutsService, ScoutsService>(new InjectionConstructor(scoutsRepositoryMock.Object, campRepositoryMock.Object, loggerServiceMock.Object));
            IScoutsService scoutsService = unityContainer.Resolve <IScoutsService>();

            scoutsService.AddScout("Testing Scout", "Here comes Unit test");
            scoutsRepositoryMock.Verify(s => s.SaveScout(It.Is <Scout>(r => r.ScoutName == "Testing Scout")));
        }
コード例 #2
0
        static void Main(string[] args)
        {
            IUnityContainer unityContainer = new UnityContainer();

            CointainerMagic.RegisterElements(unityContainer);

            ILoggerService loggerService = unityContainer.Resolve <ILoggerService>();
            IScoutsService scoutsService = unityContainer.Resolve <IScoutsService>();

            loggerService.WriteLog("Registration for cleanning camps is starting here.");

            scoutsService.BootstrapScouts();
            loggerService.WriteLog("Known scouts are already registered!");

            scoutsService.AddScout("Quality Man", "Testing, Testing..");

            loggerService.WriteLog("Done.");

            Console.ReadKey();
        }