public void Execute_Should_Register_ModelServices_That_Have_Base_ModelService()
        {
            var dependencyResolver = new Mock <TestableDependencyResolver> {
                CallBase = true
            };
            var appDomainHelper = new Mock <IAppDomainHelper>();

            appDomainHelper.Setup(a => a.GetTypes(It.IsAny <Func <Type, bool> >()))
            .Returns(() => new[] { typeof(DummyModel), typeof(InheritedDummyModelService) });

            var task = new AutoRegisterModelServices(dependencyResolver.Object, new[] { appDomainHelper.Object });

            task.Execute();

            dependencyResolver.Verify(d => d.RegisterType(typeof(IModelService <DummyModel>), typeof(InheritedDummyModelService)), Times.Once());
            dependencyResolver.Verify(d => d.RegisterType(It.IsAny <Type>(), It.IsAny <Type>()), Times.Once());
        }
        public void Execute_Should_Register_Multiple_ModelServices_For_ModelEntities_That_Dont_Have_A_Service()
        {
            var dependencyResolver = new Mock <TestableDependencyResolver> {
                CallBase = true
            };
            var appDomainHelper = new Mock <IAppDomainHelper>();

            appDomainHelper.Setup(a => a.GetTypes(It.IsAny <Func <Type, bool> >()))
            .Returns(() => new[] { typeof(DummyModel), typeof(DummyModel2) });

            var task = new AutoRegisterModelServices(dependencyResolver.Object, new[] { appDomainHelper.Object });

            task.Execute();

            dependencyResolver.Verify(d => d.RegisterType(typeof(IModelService <DummyModel>), It.Is <Type>(value => value.Name.StartsWith("DynamicGeneratedModelService"))), Times.Once());
            dependencyResolver.Verify(d => d.RegisterType(typeof(IModelService <DummyModel2>), It.Is <Type>(value => value.Name.StartsWith("DynamicGeneratedModelService"))), Times.Once());
            dependencyResolver.Verify(d => d.RegisterType(It.IsAny <Type>(), It.IsAny <Type>()), Times.Exactly(2));
        }
        public void Execute_Should_Not_Register_ModelServices_For_ModelEntities_If_CreateMissingModelServices_Set_To_False()
        {
            var dependencyResolver = new Mock <TestableDependencyResolver> {
                CallBase = true
            };
            var appDomainHelper = new Mock <IAppDomainHelper>();

            appDomainHelper.Setup(a => a.GetTypes(It.IsAny <Func <Type, bool> >()))
            .Returns(() => new[] { typeof(DummyModel), typeof(DummyModel2) });

            var task = new AutoRegisterModelServices(dependencyResolver.Object, new[] { appDomainHelper.Object });

            AutoRegisterModelServices.CreateMissingModelServices = false;
            task.Execute();
            //reset for other tests :)
            AutoRegisterModelServices.CreateMissingModelServices = true;
            dependencyResolver.Verify(d => d.RegisterType(It.IsAny <Type>(), It.IsAny <Type>()), Times.Never());
        }