public void CreateFindUpdateTest() { Person createdPerson = new Person(); createdPerson.Name = "gandamu strike freedom"; createdPerson.Document = "ZGMFX20A"; createdPerson.Email = "*****@*****.**"; PeopleRepository repository = new PeopleRepository(); repository.Save(createdPerson); Assert.AreNotEqual(0, createdPerson.Id); Person retrievedPerson = repository.FindSingle(p => p.Id == createdPerson.Id); Assert.AreEqual(createdPerson, retrievedPerson); retrievedPerson.Email = "*****@*****.**"; repository.Save(retrievedPerson); retrievedPerson = repository.FindSingle(p => p.Id == createdPerson.Id); Assert.AreEqual("*****@*****.**", retrievedPerson.Email); }
public void TransactionCommitRollbackTest() { PeopleRepository peopleRepository = new PeopleRepository(); AccountsRepository accountsRepository = new AccountsRepository(); BankDataContextFactory contextFactory = new BankDataContextFactory(); Person createdPerson = new Person(); createdPerson.Name = "transaction test"; createdPerson.Document = "ZGMFX20A"; createdPerson.Email = "*****@*****.**"; Account createdAccount = new Account(); createdAccount.Number = 2354235; createdAccount.Agency = 34; UnitOfWork unitOfWork = contextFactory.CreateUnitOfWork(); peopleRepository.Save(createdPerson, unitOfWork); createdAccount.OwnerId = createdPerson.Id; accountsRepository.Save(createdAccount, unitOfWork); unitOfWork.Commit(); Assert.IsNotNull(peopleRepository.FindSingle(p => p.Name == createdPerson.Name)); Assert.IsNotNull(accountsRepository.FindSingle(a => a.Number == createdAccount.Number)); unitOfWork = contextFactory.CreateUnitOfWork(); accountsRepository.Delete(createdAccount, unitOfWork); peopleRepository.Delete(createdPerson, unitOfWork); unitOfWork.Rollback(); Assert.IsNotNull(peopleRepository.FindSingle(p => p.Name == createdPerson.Name)); Assert.IsNotNull(accountsRepository.FindSingle(a => a.Number == createdAccount.Number)); unitOfWork = contextFactory.CreateUnitOfWork(); accountsRepository.Delete(createdAccount, unitOfWork); peopleRepository.Delete(createdPerson, unitOfWork); unitOfWork.Commit(); Assert.IsNull(peopleRepository.FindSingle(p => p.Name == createdPerson.Name)); Assert.IsNull(accountsRepository.FindSingle(a => a.Number == createdAccount.Number)); }