public void events_should_called_once() { Building(builder => { builder .UseStoveWithNullables(typeof(MyTestBootstrapper)) .RegisterServices(r => r.RegisterAssemblyByConvention(Assembly.GetExecutingAssembly())); }) .Ok(); var testModule = LocalResolver.Resolve <MyTestBootstrapper>(); var otherModule = LocalResolver.Resolve <MyOtherBootstrapper>(); var anotherModule = LocalResolver.Resolve <MyAnotherBootstrapper>(); testModule.PreStartCount.ShouldBe(1); testModule.StartCount.ShouldBe(1); testModule.PostStartCount.ShouldBe(1); otherModule.PreStartCount.ShouldBe(1); otherModule.StartCount.ShouldBe(1); otherModule.PostStartCount.ShouldBe(1); otherModule.CallMeOnStartupCount.ShouldBe(1); anotherModule.PreStartCount.ShouldBe(1); anotherModule.StartCount.ShouldBe(1); anotherModule.PostStartCount.ShouldBe(1); }
public void UsingDbContext(Action <SampleApplicationDbContext> action) { using (var context = LocalResolver.Resolve <SampleApplicationDbContext>()) { context.DisableAllFilters(); action(context); context.SaveChanges(); } }
public T UsingDbContext <T>(Func <SampleApplicationDbContext, T> func) { T result; using (var context = LocalResolver.Resolve <SampleApplicationDbContext>()) { context.DisableAllFilters(); result = func(context); context.SaveChanges(); } return(result); }
public void firstordefault_should_work() { var uowManager = LocalResolver.Resolve <IUnitOfWorkManager>(); var userRepository = LocalResolver.Resolve <IRepository <User> >(); using (IUnitOfWorkCompleteHandle uow = uowManager.Begin()) { User user = userRepository.FirstOrDefault(x => x.Name == "Oğuzhan"); user.ShouldNotBeNull(); uow.Complete(); } }
public void Should_Call_Uow_Methods() { var fakeUow = Substitute.For <IUnitOfWork>(); Building(builder => { builder.RegisterServices(r => r.Register <IUnitOfWorkDefaultOptions, UnitOfWorkDefaultOptions>(Lifetime.Singleton)); builder.RegisterServices(r => r.Register <ICurrentUnitOfWorkProvider, CallContextCurrentUnitOfWorkProvider>(Lifetime.Singleton)); builder.RegisterServices(r => r.Register <IUnitOfWorkManager, UnitOfWorkManager>(Lifetime.Singleton)); builder.RegisterServices(r => r.Register(context => fakeUow, Lifetime.Singleton)); }).Ok(); var uowManager = LocalResolver.Resolve <IUnitOfWorkManager>(); //Starting the first uow using (IUnitOfWorkCompleteHandle uow1 = uowManager.Begin()) { //so, begin will be called fakeUow.Received(1).Begin(Arg.Any <UnitOfWorkOptions>()); //trying to begin a uow (not starting a new one, using the outer) using (IUnitOfWorkCompleteHandle uow2 = uowManager.Begin()) { //Since there is a current uow, begin is not called fakeUow.Received(1).Begin(Arg.Any <UnitOfWorkOptions>()); uow2.Complete(); //complete has no effect since outer uow should complete it fakeUow.DidNotReceive().Complete(); } //trying to begin a uow (forcing to start a NEW one) using (IUnitOfWorkCompleteHandle uow2 = uowManager.Begin(TransactionScopeOption.RequiresNew)) { //So, begin is called again to create an inner uow fakeUow.Received(2).Begin(Arg.Any <UnitOfWorkOptions>()); uow2.Complete(); //And the inner uow should be completed fakeUow.Received(1).Complete(); } //complete the outer uow uow1.Complete(); } fakeUow.Received(2).Complete(); fakeUow.Received(2).Dispose(); }
public void auto_object_mapping_should_work() { Building(builder => { }).Ok(); var mapper = LocalResolver.Resolve <IObjectMapper>(); var person = new Person { Name = "Oğuzhan" }; var personDto = mapper.Map <PersonDto>(person); var personEntity = mapper.Map <Person>(personDto); personDto.ShouldNotBeNull(); personEntity.ShouldNotBeNull(); }
public void Should_Get_Bootstrapper_And_Additional_Assemblies() { Building(builder => { builder .UseStoveWithNullables(typeof(MyStartupBootstrapper)) .RegisterServices(r => r.RegisterAssemblyByConvention(Assembly.GetExecutingAssembly())); }) .Ok(); //Act List <Assembly> assemblies = LocalResolver.Resolve <StoveAssemblyFinder>().GetAllAssemblies(); //Assert assemblies.Count.ShouldBe(3); assemblies.Any(a => a == typeof(MyStartupBootstrapper).Assembly).ShouldBeTrue(); assemblies.Any(a => a == typeof(StoveKernelBootstrapper).Assembly).ShouldBeTrue(); assemblies.Any(a => a == typeof(FactAttribute).Assembly).ShouldBeTrue(); }
public void Should_Resolve_Generic_Repositories() { //Entity 1 (with default PK) var entity1Repository = LocalResolver.Resolve <IRepository <MyEntity1> >(); entity1Repository.ShouldNotBe(null); (entity1Repository is EfRepositoryBase <MyBaseDbContext, MyEntity1>).ShouldBe(true); //Entity 1 (with specified PK) var entity1RepositoryWithPk = LocalResolver.Resolve <IRepository <MyEntity1, int> >(); entity1RepositoryWithPk.ShouldNotBe(null); (entity1RepositoryWithPk is EfRepositoryBase <MyBaseDbContext, MyEntity1, int>).ShouldBe(true); //Entity 1 (with specified Repository forIMyModuleRepository ) var entity1RepositoryWithModuleInterface = LocalResolver.Resolve <IMyModuleRepository <MyEntity1> >(); entity1RepositoryWithModuleInterface.ShouldNotBe(null); (entity1RepositoryWithModuleInterface is MyModuleRepositoryBase <MyEntity1>).ShouldBe(true); (entity1RepositoryWithModuleInterface is EfRepositoryBase <MyModuleDbContext, MyEntity1, int>).ShouldBe(true); //Entity 1 (with specified Repository forIMyModuleRepository ) var entity1RepositoryWithModuleInterfaceWithPk = LocalResolver.Resolve <IMyModuleRepository <MyEntity1, int> >(); entity1RepositoryWithModuleInterfaceWithPk.ShouldNotBe(null); (entity1RepositoryWithModuleInterfaceWithPk is MyModuleRepositoryBase <MyEntity1, int>).ShouldBe(true); (entity1RepositoryWithModuleInterfaceWithPk is EfRepositoryBase <MyModuleDbContext, MyEntity1, int>).ShouldBe(true); //Entity 2 var entity2Repository = LocalResolver.Resolve <IRepository <MyEntity2, long> >(); (entity2Repository is EfRepositoryBase <MyMainDbContext, MyEntity2, long>).ShouldBe(true); entity2Repository.ShouldNotBe(null); //Entity 3 var entity3Repository = LocalResolver.Resolve <IMyModuleRepository <MyEntity3, Guid> >(); (entity3Repository is EfRepositoryBase <MyModuleDbContext, MyEntity3, Guid>).ShouldBe(true); entity3Repository.ShouldNotBe(null); }
public void uow_rollback_should_work_with_repository_insert() { var uowManager = LocalResolver.Resolve <IUnitOfWorkManager>(); var userRepository = LocalResolver.Resolve <IRepository <User> >(); using (IUnitOfWorkCompleteHandle uow = uowManager.Begin()) { userRepository.Insert(new User { Email = "*****@*****.**", Surname = "Sykn", Name = "Oğuz" }); //not complete, should rollback! } using (IUnitOfWorkCompleteHandle uow = uowManager.Begin()) { userRepository.FirstOrDefault(x => x.Email == "*****@*****.**").ShouldBeNull(); } }
public Session_Tests() { Building(builder => { }).Ok(); _session = LocalResolver.Resolve <IStoveSession>(); }