public void SaveRepositoryNameChanged() { var repository = new UserMongoRepository(GetRequiredService <IOptions <MongoSettings> >()); var roberto = UserMother.Create(); for (var i = 0; i < 10; i++) { roberto.AddAddress(AddressMother.Create()); } for (var i = 0; i < 5; i++) { roberto.AddEmail(EmailMother.Create()); } repository.Add(roberto); repository.SaveChanges(); var repository2 = new UserMongoRepository(GetRequiredService <IOptions <MongoSettings> >()); var repoUser = repository2.GetById(roberto.Id); Assert.Equal(roberto.Id, repoUser.Id); Assert.Equal(roberto.Name, repoUser.Name); Assert.Equal(5, repoUser.Emails.Count()); Assert.Equal(10, repoUser.Addresses.Count()); }
private async Task LoadTestDataAsync(CancellationToken cancellationToken) { await using var dbContext = GetService <IDbContextFactory <SharedKernelDbContext> >().CreateDbContext(); await dbContext.Database.EnsureDeletedAsync(cancellationToken); await dbContext.Database.MigrateAsync(cancellationToken); var repository = new UserEfCoreRepository(dbContext); var tasks = new List <Task>(); for (var i = 0; i < 11; i++) { var roberto = UserMother.Create(); for (var j = 0; j < 10; j++) { roberto.AddAddress(AddressMother.Create()); } for (var j = 0; j < 5; j++) { roberto.AddEmail(EmailMother.Create()); } tasks.Add(repository.AddAsync(roberto, cancellationToken)); } await Task.WhenAll(tasks); await repository.SaveChangesAsync(cancellationToken); }
public async Task SaveRepositoryNameChanged() { var dbContext = GetService <SharedKernelDbContext>(); await dbContext.Database.EnsureDeletedAsync(); await dbContext.Database.MigrateAsync(); var repository = GetRequiredService <UserEfCoreRepository>(); var roberto = UserMother.Create(); for (var i = 0; i < 10; i++) { roberto.AddAddress(AddressMother.Create()); } for (var i = 0; i < 5; i++) { roberto.AddEmail(EmailMother.Create()); } repository.Add(roberto); repository.SaveChanges(); var repository2 = GetRequiredService <UserEfCoreRepository>(); var repoUser = repository2.GetById(roberto.Id); Assert.Equal(roberto.Id, repoUser.Id); Assert.Equal(roberto.Name, repoUser.Name); Assert.Equal(5, repoUser.Emails.Count()); Assert.Equal(10, repoUser.Addresses.Count()); await dbContext.Database.EnsureDeletedAsync(); await dbContext.Database.MigrateAsync(); }