public async Task UpdateUserAsync_WhenPassingUpdatedUser_ShouldUpdateProperly() { var user = MigrationService.CreateUser(); using (var scope = new TransactionScope(TransactionScopeAsyncFlowOption.Enabled)) { using (var context = new EFCoreSampleDbContext(options)) { context.Users.Add(user); await context.SaveChangesAsync(); } var code = user.Codes.First(); code.CityCode = 3333; using (var context = new EFCoreSampleDbContext(options)) { var dataService = new DataService(context); await dataService.UpdateUserAsync(user); } using (var context = new EFCoreSampleDbContext(options)) { var dataService = new DataService(context); var users = await dataService.GetUsersAsync(); var dbUser = users.Single(u => u.Id == user.Id); dbUser.Codes.Single(c => c.Id == code.Id).CityCode.Should().Be(3333); } } }
public async Task GetUsersAsync_ValidateUser() { var user = MigrationService.CreateUser(); using (var scope = new TransactionScope(TransactionScopeAsyncFlowOption.Enabled)) { using (var context = new EFCoreSampleDbContext(options)) { context.Users.Add(user); await context.SaveChangesAsync(); } using (var context = new EFCoreSampleDbContext(options)) { var dataService = new DataService(context); var users = await dataService.GetUsersAsync(); var dbUser = users.Single(u => u.Id == user.Id); dbUser.Name.Should().Be(user.Name); dbUser.Codes.Count.Should().Be(user.Codes.Count); } } }
public DataServiceTests() { using (var context = new EFCoreSampleDbContext(options)) { context.Database.EnsureCreated(); context.Database.Migrate(); } }
private async Task MigrateAsync(EFCoreSampleDbContext context) { await context.Database.EnsureCreatedAsync(); await context.Database.MigrateAsync(); if (!context.Users.Any()) { var user = CreateUser(); context.Users.Add(user); await context.SaveChangesAsync(); } }
public DataService(EFCoreSampleDbContext context) { this.context = context; }