public void Repository_Can_Update_DetachedAsync() { using (var context = new InMemoryContext()) { IRepository <TabelaTesteWithGuidKey, Guid> repository = new TabelaTesteWithGuidKeyRepository(context, GetUserContextService()); var uow = new UnitOfWork(context, Substitute.For <ILogger <UnitOfWork> >()); var result = repository.AddOrUpdateAsync(new TabelaTesteWithGuidKey() { Propriedade = Guid.NewGuid().ToString() }).Result; var alteracoes = uow.SaveAndCommitAsync().Result; Assert.IsTrue(alteracoes == 1); var chave = repository.FindAsync(p => p.Propriedade == result.Propriedade).Result.FirstOrDefault(); Assert.NotNull(chave); Assert.IsTrue(chave.Id != Guid.Empty); var registro = new TabelaTesteWithGuidKey() { Id = chave.Id, Propriedade = "NewValue_123" }; registro = repository.AddOrUpdateAsync(registro).Result; var contextSaveResult = uow.SaveAndCommitAsync().Result; Assert.IsTrue(alteracoes == 1); registro = repository.GetByIdAsync(registro.Id).Result; Assert.NotNull(registro); Assert.AreEqual(registro.Propriedade, "NewValue_123"); } }
public void Repository_Can_Remove_ByIdAsync() { using (var context = new InMemoryContext()) { IRepository <TabelaTesteWithGuidKey, Guid> repository = new TabelaTesteWithGuidKeyRepository(context, GetUserContextService()); var uow = new UnitOfWork(context, Substitute.For <ILogger <UnitOfWork> >()); var registro = new TabelaTesteWithGuidKey() { Propriedade = Guid.NewGuid().ToString() }; var saveResult = repository.AddOrUpdateAsync(registro).Result; var alteracoes = uow.SaveAndCommitAsync().Result; Assert.IsTrue(alteracoes == 1); var removeResult = repository.RemoveAsync(registro.Id).Result; var saveRemoveResult = uow.SaveAndCommitAsync().Result; Assert.IsTrue(alteracoes == 1); registro = repository.FindAsync(p => p.Id == registro.Id).Result.FirstOrDefault(); Assert.Null(registro); } }
public void Repository_Can_Update_Detached() { using (var context = new InMemoryContext()) using (IRepository <TabelaTesteWithGuidKey, Guid> repository = new TabelaTesteWithGuidKeyRepository(context, GetUserContextService())) { var uow = new UnityOfWork(context, Substitute.For <ILogProvider>()); repository.AddOrUpdate(new TabelaTesteWithGuidKey() { Propriedade = Guid.NewGuid().ToString() }); var alteracoes = uow.SaveAndCommit(); Assert.IsTrue(alteracoes == 1); var chave = repository.GetAll().FirstOrDefault(); Assert.NotNull(chave); Assert.IsTrue(chave.Id != Guid.Empty); var registro = new TabelaTesteWithGuidKey() { Id = chave.Id, Propriedade = "Alterada_123" }; repository.AddOrUpdate(registro); uow.SaveAndCommit(); Assert.IsTrue(alteracoes == 1); registro = repository.GetById(chave.Id); Assert.NotNull(registro); Assert.AreEqual(registro.Propriedade, "Alterada_123"); } }