public async Task UpdateSucceedsIfChangeTokenMatches() { DbContextDataProvider <DefaultDataProvider, TestContext> provider = CreateProvider(); string changeToken = Guid.NewGuid().ToString("N"); ITokenGenerator generator = CreateTokenGenerator(changeToken); TestContext testContext = provider.GetContext(); var dbEntity = new DbEntityWithChangeToken() { ChangeToken = changeToken }; testContext.ChangeTokenEntities.Add(dbEntity); await testContext.SaveChangesAsync(); TestContextChangeTokenRepository repository = CreateChangeTokenRepository(provider, generator); await repository.UpdateAsync( new EntityWithChangeToken { Id = dbEntity.Id, ChangeToken = changeToken }, CancellationToken.None); }
public async Task CreateInitializesChangeToken() { DbContextDataProvider <DefaultDataProvider, TestContext> provider = CreateProvider(); string changeToken = Guid.NewGuid().ToString("N"); ITokenGenerator generator = CreateTokenGenerator(changeToken); TestContextChangeTokenRepository repository = CreateChangeTokenRepository(provider, generator); EntityWithChangeToken result = await repository.CreateAsync( new EntityWithChangeToken(), CancellationToken.None); result.ChangeToken.Should() .Be(changeToken); DbEntityWithChangeToken dbEntity = await provider.GetContext() .ChangeTokenEntities.FirstAsync(e => e.Id == result.Id); dbEntity.ChangeToken.Should() .Be(changeToken); }
public async Task UpdateThrowsIfChangeTokenDoesNotMatch() { DbContextDataProvider <DefaultDataProvider, TestContext> provider = CreateProvider(); string changeToken = Guid.NewGuid().ToString("N"); ITokenGenerator generator = CreateTokenGenerator(changeToken); TestContext testContext = provider.GetContext(); var dbEntity = new DbEntityWithChangeToken() { ChangeToken = changeToken }; testContext.ChangeTokenEntities.Add(dbEntity); await testContext.SaveChangesAsync(); TestContextChangeTokenRepository repository = CreateChangeTokenRepository(provider, generator); await Assert.ThrowsAsync <EntityConcurrencyException>( () => repository.UpdateAsync( new EntityWithChangeToken { Id = dbEntity.Id, ChangeToken = "abc" }, CancellationToken.None)); }