public void UpdateSuccessItemTest() { //Given var databseFactory = new EfCoreDatabaseFactoryBase <SharedLibraryContext>("SharedLibraryContext"); Account testAccount; var repository = new EfCoreAccountRepository(databseFactory); using (var efCoreUnitOfWork = new EfCoreUnitOfWork <SharedLibraryContext>(databseFactory)) { testAccount = repository.Save(AccountEntityHelper.CreateEfTestAccount()); efCoreUnitOfWork.Commit(); //When testAccount.CompanyName = "Updated account"; repository.Save(testAccount); efCoreUnitOfWork.Commit(); } //Then var finalDatabaseFactory = new EfCoreDatabaseFactoryBase <SharedLibraryContext>("SharedLibraryContext"); var finalRepo = new EfCoreAccountRepository(finalDatabaseFactory); var itemToCheck = finalRepo.GetById(testAccount.AccountId); EqualityHelper.PropertyValuesAreEqual(itemToCheck, testAccount, new[] { "LastModified", "Contact" }); }
public void GetByIdExceptionTest() { //Given var databseFactory = new EfCoreDatabaseFactoryBase <SharedLibraryContext>("SharedLibraryContext"); var repository = new EfCoreAccountRepository(databseFactory); //When var shouldBeNull = repository.GetById(-1); //Then Assert.IsNull(shouldBeNull, "The item was found when it should have never existed."); }
public void RetrieveItemByIdTest() { //Given var databseFactory = new EfCoreDatabaseFactoryBase <SharedLibraryContext>("SharedLibraryContext"); var repository = new EfCoreAccountRepository(databseFactory); using (var efCoreUnitOfWork = new EfCoreUnitOfWork <SharedLibraryContext>(databseFactory)) { var addedAccount = repository.Save(AccountEntityHelper.CreateEfTestAccount()); efCoreUnitOfWork.Commit(); //When var retrievedItem = repository.GetById(addedAccount.AccountId); //Then EqualityHelper.PropertyValuesAreEqual(retrievedItem, addedAccount); } }
public void DeleteItemSuccessTest() { //Given var databseFactory = new EfCoreDatabaseFactoryBase <SharedLibraryContext>("SharedLibraryContext"); using (var efCoreUnitOfWork = new EfCoreUnitOfWork <SharedLibraryContext>(databseFactory)) { //Given var repository = new EfCoreAccountRepository(databseFactory); var testAccount = repository.Save(AccountEntityHelper.CreateEfTestAccount()); efCoreUnitOfWork.Commit(); //When repository.Delete(testAccount); efCoreUnitOfWork.Commit(); //Then var retrievedAccount = repository.GetById(testAccount.AccountId); Assert.IsNull(retrievedAccount, "The account was not deleted."); } }