public async Task Add_ChangesDatabase() { DbContextOptions <MangaContext> options = new DbContextOptionsBuilder <MangaContext>() .UseInMemoryDatabase("test_database") .Options; await using MangaContext context = new MangaContext(options); await context.Database.EnsureCreatedAsync() .ConfigureAwait(false); EntityFactory factory = new EntityFactory(); ICustomer customer = factory.NewCustomer( new SSN("198608177955"), new Name("Ivan Paulovich")); IUser user = factory.NewUser( customer.Id, new ExternalUserId("github/ivanpaulovich"), new Name("Ivan Paulovich")); UserRepository userRepository = new UserRepository(context); await userRepository.Add(user) .ConfigureAwait(false); CustomerRepository customerRepository = new CustomerRepository(context); await customerRepository.Add(customer) .ConfigureAwait(false); await context.SaveChangesAsync() .ConfigureAwait(false); Assert.Equal(2, context.Customers.Count()); }
public async Task Add(ICustomer customer) { await _context.Customers.AddAsync((EntityFrameworkDataAccess.Customer) customer); await _context.SaveChangesAsync(); }
public async Task Add(IUser user) { await _context.Users.AddAsync((EntityFrameworkDataAccess.User) user); await _context.SaveChangesAsync(); }