public void Setup() { unitOfWorkDomainEventHandler1 = Substitute.For <IUnitOfWorkDomainEventHandler <TestDomainEvent, TestUnitOfWork> >(); unitOfWorkDomainEventHandler2 = Substitute.For <IUnitOfWorkDomainEventHandler <TestDomainEvent, TestUnitOfWork> >(); unitOfWorkDomainEventHandlers = new List <IUnitOfWorkDomainEventHandler <TestDomainEvent, TestUnitOfWork> > { unitOfWorkDomainEventHandler1, unitOfWorkDomainEventHandler2 }; domainEventHandler3 = Substitute.For <IDomainEventHandler <TestDomainEvent> >(); domainEventHandler4 = Substitute.For <IDomainEventHandler <TestDomainEvent> >(); domainEventHandlers = new List <IDomainEventHandler <TestDomainEvent> > { domainEventHandler3, domainEventHandler4 }; eventHandlerResolver = Substitute.For <IDomainEventHandlerResolver>(); unitOfWorkEventHandlerResolver = Substitute.For <IUnitOfWorkDomainEventHandlerResolver>(); unitOfWork = Substitute.For <TestUnitOfWork>(); domainEvent = new TestDomainEvent(Guid.NewGuid()); unitOfWorkEventHandlerResolver.ResolveEventHandlers <IUnitOfWorkDomainEventHandler <TestDomainEvent, TestUnitOfWork> >().Returns(unitOfWorkDomainEventHandlers); eventHandlerResolver.ResolveEventHandlers <IDomainEventHandler <TestDomainEvent> >().Returns(domainEventHandlers); sut = new TestUnitOfWorkDomainRepository(eventHandlerResolver, unitOfWorkEventHandlerResolver, unitOfWork); }
public void TestCustomUnitOfWork() { var stopwatch = Stopwatch.StartNew(); using (var uow = new TestUnitOfWork()) { var users = uow.Users.NewList(); stopwatch.Stop(); Console.WriteLine(stopwatch.ElapsedMilliseconds); foreach (var user in users) { Console.WriteLine($"{user.Id} {user.Login}"); } var dto = new UserDTO { Login = "******", Password = "******" }; dto = uow.Users.Insert(dto); uow.SaveChanges(); var login = dto.Login; dto = uow.Users.DTO(d => d.Login == login); Assert.IsNotNull(dto); Assert.AreNotEqual(dto.Id, 0); Console.WriteLine(dto.Id); dto.Password = "******"; uow.Users.Update(dto, dto.Id); uow.SaveChanges(); Assert.AreEqual(dto.Password, uow.Users.DTO(dto.Id).Password); uow.Users.Delete(dto.Id); uow.SaveChanges(); Assert.IsNull(uow.Users.DTO(dto.Id)); } }
public void GetRepository_OneGeneric_Success_Should_ReturnNull() { var repository = Mock.Of <IRepositoryAsync <TestAggregateRoot, Guid> >(); ITestUnitOfWork unitOfWork = new TestUnitOfWork(_Context, repository); var searchedRepo = unitOfWork.GetRepository <PlaceHolder>(); searchedRepo.Should().BeNull(); }
public async Task CreateTransactionAsync_Success_Should_CreateTransaction() { var aggregateRep = Mock.Of <IRepositoryAsync <TestAggregateRoot, Guid> >(); ITestUnitOfWork unitOfWork = new TestUnitOfWork(_Context, aggregateRep); await unitOfWork.CreateTransactionAsync(); _Context.Database.CurrentTransaction.Should().NotBeNull(); }
public void TestReflection() { using (var uow = new TestUnitOfWork()) { Assert.IsNotNull(uow.Repository <User, UserDTO>(), "uow.Users != null by reflection"); Assert.IsNotNull(uow.Repository <Role, RoleDTO>(), "uow.Roles != null by reflection"); Assert.IsNotNull(uow.Users, "uow.Users != null"); Assert.IsNotNull(uow.Roles, "uow.Roles != null"); } }
public async Task RollbackAsync_Success_Should_DoNothing_Detail_NoTransactionToRollback() { var expCount = 0; var aggregateRep = Mock.Of <IRepositoryAsync <TestAggregateRoot, Guid> >(); ITestUnitOfWork unitOfWork = new TestUnitOfWork(_Context, aggregateRep); await unitOfWork.RollbackAsync(); _Context.TestAggregateRoots.Should().HaveCount(expCount); }
public with_a_test_record_repo() : base() { var baseMappings = new MapperConfigurationExpression(); var _mapperConfiguration = new MapperConfiguration(cfg => { cfg.AddProfile(new TestRecordMapping()); }); _aMapper = _mapperConfiguration.CreateMapper(); _testRepo = new TestRepo(_testRecordContext, _aMapper, new TestDeepUpdater()); _unitOfWork = new TestUnitOfWork(_testRecordContext, _testRepo); }
public void TestReflection() { using (var uow = new TestUnitOfWork()) { Console.WriteLine(uow.UserRolesRegistered); Assert.IsNotNull(uow.Repository <User, UserDTO>(), "uow.Users != null by reflection"); Assert.IsNotNull(uow.Repository <Role, RoleDTO>(), "uow.Roles != null by reflection"); Assert.IsNotNull(uow.Repository <UserRole, UserRoleDTO>(), "uow.UserRoles != null by reflection"); Assert.IsNotNull(uow.Users, "uow.Users != null"); Assert.IsNotNull(uow.Roles, "uow.Roles != null"); Assert.IsNotNull(uow.UserRoles, "uow.UserRoles != null"); } }
public async Task SaveChangesAsync_Success_Should_SaveChanges() { var expCount = 1; var aggregateRep = Mock.Of <IRepositoryAsync <TestAggregateRoot, Guid> >(); ITestUnitOfWork unitOfWork = new TestUnitOfWork(_Context, aggregateRep); var aggregateRoot = new TestAggregateRoot("testing"); _Context.Add(aggregateRoot); await unitOfWork.SaveChangesAsync(); _Context.TestAggregateRoots.Should().HaveCount(expCount); }
public void CanGetCorrectNestedCurrentScope() { using (var level1 = new TestUnitOfWork()) { Assert.AreEqual(level1, UnitOfWorkBase.CurrentScope()); using (var level2 = new TestUnitOfWork()) { Assert.AreEqual(level2, UnitOfWorkBase.CurrentScope()); using (var level3 = new TestUnitOfWork()) { Assert.AreEqual(level3, UnitOfWorkBase.CurrentScope()); } Assert.AreEqual(level2, UnitOfWorkBase.CurrentScope()); } Assert.AreEqual(level1, UnitOfWorkBase.CurrentScope()); } }
public async Task UseTransactionAsync_Success_Should_WriteChangesInDatabase() { var expCount = 1; var aggregateRep = Mock.Of <IRepositoryAsync <TestAggregateRoot, Guid> >(); ITestUnitOfWork unitOfWork = new TestUnitOfWork(_Context, aggregateRep); var aggregateRoot = new TestAggregateRoot("testing"); await unitOfWork.UseTransactionAsync(async() => { _Context.Add(aggregateRoot); await unitOfWork.SaveChangesAsync(); }); _Context.TestAggregateRoots.Should().HaveCount(expCount); }
public void TestInterfaceFieldCustomUnitOfWork() { var stopwatch = new Stopwatch(); stopwatch.Start(); using (var uow = new TestUnitOfWork()) { var numbers = uow.Floats.All(); stopwatch.Stop(); Console.WriteLine(stopwatch.ElapsedMilliseconds); foreach (var number in numbers) { Console.WriteLine(number.Value); } } }
public void TestDoubleRepository() { var stopwatch = new Stopwatch(); stopwatch.Start(); using (var uow = new TestUnitOfWork()) { var numbers = uow.Repository <DoubleValue, FloatValue>().AllBuilt(); stopwatch.Stop(); Console.WriteLine(stopwatch.ElapsedMilliseconds); foreach (var number in numbers) { Console.WriteLine(number.Value); } } }
public void TestCustomUnitOfWork() { var stopwatch = new Stopwatch(); stopwatch.Start(); using (var uow = new TestUnitOfWork()) { var numbers = uow.Doubles.NewList(); stopwatch.Stop(); Console.WriteLine(stopwatch.ElapsedMilliseconds); foreach (var number in numbers) { Console.WriteLine(number.Value); } } }
public void CanGetCorrectNestedCurrentScope() { using (var level1 = new TestUnitOfWork()) { Assert.AreEqual(level1, UnitOfWorkBase.CurrentScope()); using (var level2 = new TestUnitOfWork()) { Assert.AreEqual(level2, UnitOfWorkBase.CurrentScope()); using (var level3 = new TestUnitOfWork()) { Assert.AreEqual(level3, UnitOfWorkBase.CurrentScope()); } Assert.AreEqual(level2, UnitOfWorkBase.CurrentScope()); } Assert.AreEqual(level1, UnitOfWorkBase.CurrentScope()); } }
public void Setup() { unitOfWork = new TestUnitOfWork(); domainEventHandler1 = Substitute.For <IUnitOfWorkDomainEventHandler <TestDomainEvent, TestUnitOfWork> >(); domainEventHandler2 = Substitute.For <IUnitOfWorkDomainEventHandler <TestDomainEvent, TestUnitOfWork> >(); domainEventHandler3 = Substitute.For <IUnitOfWorkDomainEventHandler <AnotherTestDomainEvent, TestUnitOfWork> >(); asyncDomainEventHandler1 = Substitute.For <IAsyncUnitOfWorkDomainEventHandler <TestDomainEvent, TestUnitOfWork> >(); asyncDomainEventHandler2 = Substitute.For <IAsyncUnitOfWorkDomainEventHandler <TestDomainEvent, TestUnitOfWork> >(); asyncDomainEventHandler3 = Substitute.For <IAsyncUnitOfWorkDomainEventHandler <AnotherTestDomainEvent, TestUnitOfWork> >(); resolver = Substitute.For <IUnitOfWorkDomainEventHandlerResolver>(); resolver.ResolveEventHandlers <IUnitOfWorkDomainEventHandler <TestDomainEvent, TestUnitOfWork> >().Returns(new[] { domainEventHandler1, domainEventHandler2 }); resolver.ResolveEventHandlers <IUnitOfWorkDomainEventHandler <TestDomainEvent, TestUnitOfWork> >().Returns(new[] { domainEventHandler1, domainEventHandler2 }); resolver.ResolveEventHandlers <IUnitOfWorkDomainEventHandler <AnotherTestDomainEvent, TestUnitOfWork> >().Returns(new[] { domainEventHandler3 }); resolver.ResolveEventHandlers <IAsyncUnitOfWorkDomainEventHandler <TestDomainEvent, TestUnitOfWork> >().Returns(new[] { asyncDomainEventHandler1, asyncDomainEventHandler2 }); resolver.ResolveEventHandlers <IAsyncUnitOfWorkDomainEventHandler <TestDomainEvent, TestUnitOfWork> >().Returns(new[] { asyncDomainEventHandler1, asyncDomainEventHandler2 }); resolver.ResolveEventHandlers <IAsyncUnitOfWorkDomainEventHandler <AnotherTestDomainEvent, TestUnitOfWork> >().Returns(new[] { asyncDomainEventHandler3 }); sut = new UnitOfWorkDomainEventBroker <TestUnitOfWork>(resolver, unitOfWork); }
public async Task UseTransactionAsync_WithReturn_Success_Should_RollBackChanges() { var expCount = 0; var aggregateRep = Mock.Of <IRepositoryAsync <TestAggregateRoot, Guid> >(); ITestUnitOfWork unitOfWork = new TestUnitOfWork(_Context, aggregateRep); var aggregateRoot = new TestAggregateRoot("testing"); Func <Task> act = () => unitOfWork.UseTransactionAsync <TestAggregateRoot>(async() => { _Context.Add(aggregateRoot); await unitOfWork.SaveChangesAsync(); throw new Exception(); }); await act.Should().ThrowExactlyAsync <Exception>(); _Context.TestAggregateRoots.Should().HaveCount(expCount); }
public async Task RollbackAsync_Success_Should_RollbackTransaction() { var expCount = 0; var aggregateRep = Mock.Of <IRepositoryAsync <TestAggregateRoot, Guid> >(); ITestUnitOfWork unitOfWork = new TestUnitOfWork(_Context, aggregateRep); await unitOfWork.CreateTransactionAsync(); var aggregateRoot = new TestAggregateRoot("testing"); _Context.Add(aggregateRoot); await _Context.SaveChangesAsync(); _Context.ChangeTracker.Clear(); await unitOfWork.RollbackAsync(); _Context.TestAggregateRoots.Should().HaveCount(expCount); }
public void Test_Invoice_Saving() { Invoice invoice = new Invoice { Id = Guid.NewGuid(), Lines = new List <InvoiceLine> { new InvoiceLine { Id = Guid.NewGuid(), Description = "Test Line", Qty = 5, Rate = 12 } }, }; var unitOfWork = new TestUnitOfWork(); unitOfWork.Invoices.Add(invoice); unitOfWork.Commit(); Invoice result = unitOfWork.Invoices.GetById(invoice.Id); Assert.NotNull(result); }
public void Test_Invoice_Paid() { Guid invoiceId = Guid.NewGuid(); var unitOfWork = new TestUnitOfWork(); var mapperMock = new Mock <IMapper>(); var serviceProviderMock = new Mock <IServiceProvider>(); var paymentServiceMock = new Mock <PaymentService>(mapperMock.Object, serviceProviderMock.Object, unitOfWork); var invoiceServiceMock = new Mock <InvoiceService>(mapperMock.Object, serviceProviderMock.Object, unitOfWork); serviceProviderMock.Setup(p => p.GetService(typeof(IInvoiceService))) .Returns(invoiceServiceMock.Object); Invoice invoice = new Invoice { Id = invoiceId, Lines = new List <InvoiceLine> { new InvoiceLine { Qty = 4, Rate = 25m } } }; unitOfWork.Invoices.Add(invoice); unitOfWork.Commit(); PaymentDto paymentDto = new PaymentDto { InvoiceId = invoiceId, Amount = 100m, }; paymentServiceMock.Object.ProcessNewPayment(paymentDto); Invoice updatedInvoice = unitOfWork.Invoices.GetById(invoiceId); Assert.Equal(0m, updatedInvoice.Balance); }
public BidService_Add() { _unitOfWork = new TestUnitOfWork(); _bidService = new BidService(_unitOfWork, new MockEmailService()); }
public TheaterService_Get() { _unitOfWork = new TestUnitOfWork(); _theaterService = new TheaterService(_unitOfWork); }
public UserItemService_Remove() { _unitOfWork = new TestUnitOfWork(); _userItemService = new UserItemService(_unitOfWork, null); }
public AdminServce_Remove() { _unitOfWork = new TestUnitOfWork(); _adminService = new AdminService(_unitOfWork); }
public AdminService_Get() { _unitOfWork = new TestUnitOfWork(); _adminService = new AdminService(_unitOfWork); }
public ItemService_Remove() { _unitOfWork = new TestUnitOfWork(); _itemService = new ItemService(_unitOfWork, null); }
public void Setup() { ConfigTestEnv.Init(); AutoMapperConfiguration.Init <IBaseEntity, IDomainViewModel, IDomainEntityType>(); // DomainEntityTpe G_UnitOfWork = new TestUnitOfWork(); _CacheManager = EngineContext.Current.Resolve <ICacheManager>(); G_IRule = new Moq.Mock <IRule>() { CallBase = true }; G_CommonInfo = new CommonInfo(); G_mockFilterFactory = new Moq.Mock <IFilterFactory>() { CallBase = true }; //Initialize Fakes // Context _Context = new Moq.Mock <ReposContext>() { CallBase = true }; //Repos G_mockSubCategoryRepository = new Moq.Mock <IRepository <SubCategory> >() { CallBase = true }; //Services G_mockServiceHandlerFactory = new Moq.Mock <IServiceHandlerFactory>() { CallBase = true }; G_mockSubCategoriesService = new Moq.Mock <ISubCategoriesService>() { CallBase = true }; G_mockSubCategoryTypesService = new Moq.Mock <ISubCategoryTypesService>() { CallBase = true }; G_mockCategoriesService = new Moq.Mock <ICategoriesService>() { CallBase = true }; G_mockSubCategoryItemsService = new Moq.Mock <ISubCategoryItemsService>() { CallBase = true }; G_mockSubCategoryClassItemService = new Moq.Mock <ISubCategoryClassItemsService> { CallBase = true }; // IQueryable setup //Category category = null; //SubCategory subCategory = null; //BaseEntity baseEntity = null; //IQueryable<BaseEntity> BaseEntityQueryable // = new[] { baseEntity, }.Where(query => query != null).AsQueryable(); var dataCategories = new List <Category> { new TestCategory { CategoryName = new DomainEntityTypeString { Value = "AAA" } }, new TestCategory { CategoryName = new DomainEntityTypeString { Value = "BBB" } }, new TestCategory { CategoryName = new DomainEntityTypeString { Value = "ZZZ" } }, }.AsQueryable(); //Mock Setups _Context.Setup(c => c.SaveChanges()).Returns(1); //var Set = _Context.Object.Set<SubCategory>(); // var DB = new TestDbSet<SubCategory>(); // _Context.Setup(m => m.Set<SubCategory>()).Returns(DB); // services G_mockSubCategoriesService.Setup(s => s.Verify(It.IsAny <ModelStateDictionary>())).Returns(Result.Success); // Repos //IEnumerable<IBaseEntity> Ent = new List<BaseEntity>(); G_mockSubCategoryRepository.Setup(s => s.ModifiedEntities).Returns(It.IsAny <EntityRules>()); //G_mockSubCategoryRepository // .Setup(s => s.Verify(It.IsAny<ServiceRuleFunc<bool>>() // , It.IsAny<ModelStateDictionary>() // , It.IsAny<object>())).Returns(Result.Success); }
void Commit(TestUnitOfWork uow) { uow.Commit(); Console.WriteLine(" - committed - "); Console.WriteLine(); }