public void CommitSingleRepositoryTest() { var mockRepo = new Mock <IUnitOfWorkRepository>(); var domainUser = new FakeDomainUser { Id = Guid.NewGuid(), Name = "test" }; var uow = new InMemoryUnitOfWork(); uow.RegisterInsertion(domainUser, mockRepo.Object); domainUser.Name = "test"; uow.RegisterUpdate(domainUser, mockRepo.Object); uow.RegisterDeletion(domainUser, mockRepo.Object); uow.Commit(); mockRepo.Verify(w => w.PersistInsertion(domainUser), Times.Once); mockRepo.Verify(w => w.PersistUpdate(domainUser), Times.Once); mockRepo.Verify(w => w.PersistDeletion(domainUser), Times.Once); }
private static void FindEmployee(InMemoryUnitOfWork inMemoryUnitOfWork) { var employee = inMemoryUnitOfWork.Employees.Single(e => e.Name == "Lenny"); Console.WriteLine(employee.ToString()); inMemoryUnitOfWork.Commit(); }
private void InitSeedData() { DataStore = new InMemoryDataStore(); var unitOfWork = new InMemoryUnitOfWork(DataStore); unitOfWork.GetRepository<Client>() .Add(new Client("Adrian Freemantle", "0845140900")); unitOfWork.Commit(); }
private static void UpdateEmployee(InMemoryUnitOfWork inMemoryUnitOfWork) { var employee = inMemoryUnitOfWork.Employees.Single(e => e.Name == "Mr Burns"); employee.Name = "Waylon Smithers"; Console.WriteLine("Updated {0}", employee); inMemoryUnitOfWork.Commit(); }
private static void RemoveEmployee(InMemoryUnitOfWork inMemoryUnitOfWork) { var employee = inMemoryUnitOfWork.Employees.Single(e => e.Name == "Lenny"); inMemoryUnitOfWork.Employees.DeleteObject(employee); Console.WriteLine("Removed {0}", employee); inMemoryUnitOfWork.Commit(); }
private void InitSeedData() { DataStore = new InMemoryDataStore(); var unitOfWork = new InMemoryUnitOfWork(DataStore); unitOfWork.GetRepository <Client>() .Add(new Client("Adrian Freemantle", "0845140900")); unitOfWork.Commit(); }
public void CanAdd() { using (var unitOfWork = new InMemoryUnitOfWork(_arrayList)) { var countFish = unitOfWork.Repository.Query <Fish>().Count(); unitOfWork.Repository.Add(new Fish()); unitOfWork.Commit(); var newCountFish = unitOfWork.Repository.Query <Fish>().Count(); newCountFish.Should().Be.EqualTo(countFish + 1); } }
public void CanAdd() { using (var unitOfWork = new InMemoryUnitOfWork(_arrayList)) { var countFish = unitOfWork.Repository.Query<Fish>().Count(); unitOfWork.Repository.Add(new Fish()); unitOfWork.Commit(); var newCountFish = unitOfWork.Repository.Query<Fish>().Count(); newCountFish.Should().Be.EqualTo(countFish + 1); } }
private static void AddEmployee(InMemoryUnitOfWork inMemoryUnitOfWork) { var employee = new Employee { Name = "Bart Simpson" }; inMemoryUnitOfWork.Employees.AddObject(employee); Console.WriteLine("Added {0}", employee); inMemoryUnitOfWork.Commit(); }
public void CanUpdate() { using (var unitOfWork = new InMemoryUnitOfWork(_arrayList)) { var fish = unitOfWork.Repository.Query <Fish>().First(); fish.Name.Should().Not.Be.EqualTo("NewName"); fish.Name = "NewName"; unitOfWork.Repository.Update(fish); unitOfWork.Commit(); var updatedFish = unitOfWork.Repository.Query <Fish>().First(x => x.Id == fish.Id); updatedFish.Name.Should().Be.EqualTo("NewName"); } }
public void Commit() { var uow = new InMemoryUnitOfWork(); var employees = uow.Employees; employees.First().Name = "Bob"; employees.Last().Name = "Kim"; Assert.False(uow.Committed); uow.Commit(); Assert.True(uow.Committed); }
public void CommitEmptyTest() { var mockRepo = new Mock <IUnitOfWorkRepository>(); var domainUser = new FakeDomainUser { Id = Guid.NewGuid(), Name = "test" }; var uow = new InMemoryUnitOfWork(); uow.Commit(); mockRepo.Verify(w => w.PersistInsertion(domainUser), Times.Never); mockRepo.Verify(w => w.PersistUpdate(domainUser), Times.Never); mockRepo.Verify(w => w.PersistDeletion(domainUser), Times.Never); }
private void InitSeedData() { DataStore = new InMemoryDataStore(); var unitOfWork = new InMemoryUnitOfWork(DataStore); unitOfWork.GetRepository <Client>() .Add(new Client { ClientName = "Adrian Freemantle", Email = "*****@*****.**", PhoneNumber = "0125551111", Street = "Alon road", City = "Sandton", StreetNumber = "9", PostalCode = "0001", }); unitOfWork.Commit(); }
private void InitSeedData() { DataStore = new InMemoryDataStore(); var unitOfWork = new InMemoryUnitOfWork(DataStore); unitOfWork.GetRepository<Client>() .Add(new Client { ClientName = "Adrian Freemantle", Email = "*****@*****.**", PhoneNumber = "0125551111", Street = "Alon road", City = "Sandton", StreetNumber = "9", PostalCode = "0001", }); unitOfWork.Commit(); }
public void CommitMultipleRepositoriesTest() { var mockRepo1 = new Mock <IUnitOfWorkRepository>(); var domainUser1 = new FakeDomainUser { Id = Guid.NewGuid(), Name = "test" }; var mockRepo2 = new Mock <IUnitOfWorkRepository>(); var domainUser2 = new FakeDomainUser { Id = Guid.NewGuid(), Name = "test2" }; var uow = new InMemoryUnitOfWork(); uow.RegisterInsertion(domainUser1, mockRepo1.Object); uow.RegisterInsertion(domainUser2, mockRepo2.Object); domainUser2.Name = "test22"; uow.RegisterUpdate(domainUser2, mockRepo2.Object); uow.RegisterDeletion(domainUser1, mockRepo1.Object); uow.Commit(); mockRepo1.Verify(w => w.PersistInsertion(domainUser1), Times.Once); mockRepo1.Verify(w => w.PersistUpdate(domainUser1), Times.Never); mockRepo1.Verify(w => w.PersistDeletion(domainUser1), Times.Once); mockRepo2.Verify(w => w.PersistInsertion(domainUser2), Times.Once); mockRepo2.Verify(w => w.PersistUpdate(domainUser2), Times.Once); mockRepo2.Verify(w => w.PersistDeletion(domainUser2), Times.Never); }
private void InitSeedData() { DataStore = new InMemoryDataStore(); var unitOfWork = new InMemoryUnitOfWork(DataStore); unitOfWork.GetRepository <Client>() .Add(new Client { ClientName = "Adrian Freemantle", Email = "*****@*****.**", PhoneNumber = "0125551111", Street = "Alon road", City = "Sandton", StreetNumber = "9", PostalCode = "0001" }); unitOfWork.GetRepository <Account>() .Add(new Account { AccountNumber = "1048163555", Balance = 1000, Closed = false, ClientId = 1 }); unitOfWork.GetRepository <BankCard>() .Add(new BankCard { AccountId = 1, ClientId = 1, Disabled = false }); unitOfWork.Commit(); }
private void InitSeedData() { DataStore = new InMemoryDataStore(); var unitOfWork = new InMemoryUnitOfWork(DataStore); unitOfWork.GetRepository<Client>() .Add(new Client { ClientName = "Adrian Freemantle", Email = "*****@*****.**", PhoneNumber = "0125551111", Street = "Alon road", City = "Sandton", StreetNumber = "9", PostalCode = "0001" }); unitOfWork.GetRepository<Account>() .Add(new Account { AccountNumber = "1048163555", Balance = 1000, Closed = false, ClientId = 1 }); unitOfWork.GetRepository<BankCard>() .Add(new BankCard { AccountId = 1, ClientId = 1, Disabled = false }); unitOfWork.Commit(); }
public void CanUpdate() { using (var unitOfWork = new InMemoryUnitOfWork(_arrayList)) { var fish = unitOfWork.Repository.Query<Fish>().First(); fish.Name.Should().Not.Be.EqualTo("NewName"); fish.Name = "NewName"; unitOfWork.Repository.Update(fish); unitOfWork.Commit(); var updatedFish = unitOfWork.Repository.Query<Fish>().First(x => x.Id == fish.Id); updatedFish.Name.Should().Be.EqualTo("NewName"); } }