public async Task map_owned_list() { Mapper mapper = new Mapper(); TestDbContext db = await TestDbContext.CreateInMemorySqliteAsync(mapper); db.Roles.Add(new Role { Name = "admin" }); db.Roles.Add(new Role { Name = "user" }); db.UserTypes.Add(new UserType { Name = "system" }); await db.SaveChangesAsync(); User user = new User { Name = "test user", Roles = new List <Role> { db.Find <Role>(1), db.Find <Role>(2) }, Addresses = new List <Address> { new Address { Street = "original street", Number = "123" } }, Profile = new UserProfile { FirstName = "test", LastName = "user" }, UserType = db.Find <UserType>(1) }; db.Users.Add(user); await db.SaveChangesAsync(); User savedUser = await db.Users.Where(u => u.Id == 1) .Include(u => u.Roles) .Include(u => u.Addresses) .Include(u => u.Profile) .Include(u => u.UserType) .FirstOrDefaultAsync(); await db.MapAsync <User>(new EditUserInput { Id = 1, Addresses = new List <Address> { new Address { Street = "new street", Number = "234" } } }); Assert.Equal(1, user.Id); Assert.Equal("test user", user.Name); Assert.NotNull(user.Profile); Assert.Equal("test", user.Profile.FirstName); Assert.Equal("user", user.Profile.LastName); Assert.NotNull(user.Addresses); Assert.Equal(1, user.Addresses.Count); Assert.Equal("new street", user.Addresses[0].Street); Assert.Equal("234", user.Addresses[0].Number); Assert.NotNull(user.Roles); Assert.Equal(2, user.Roles.Count); Assert.Contains(user.Roles, r => r.Id == 1); Assert.Contains(user.Roles, r => r.Id == 2); Assert.NotNull(user.UserType); Assert.Equal(1, user.UserType.Id); }
public async Task map_user() { Mapper mapper = new Mapper(); TestDbContext db = await TestDbContext.CreateInMemorySqliteAsync(mapper); db.Roles.Add(new Role { Id = 1, Name = "admin" }); db.Roles.Add(new Role { Id = 2, Name = "user" }); db.UserTypes.Add(new UserType { Id = 1, Name = "system" }); await db.SaveChangesAsync(); await db.MapAsync <User>(new UserDTO { Id = 1, Name = "cr", Profile = new UserProfileDTO { FirstName = "chris", LastName = "redfield" }, Addresses = new List <AddressDTO> { new AddressDTO { Street = "rc", Number = "123" } }, Roles = new List <RoleDTO> { new RoleDTO { Id = 1 }, new RoleDTO { Id = 2 } }, UserType = new UserTypeDTO { Id = 1 } }); await db.SaveChangesAsync(); User user = await db.Users.Where(u => u.Id == 1) .Include(u => u.Roles) .Include(u => u.Addresses) .Include(u => u.Profile) .Include(u => u.UserType) .FirstOrDefaultAsync(); Assert.Equal(1, user.Id); Assert.Equal("cr", user.Name); Assert.NotNull(user.Profile); Assert.Equal("chris", user.Profile.FirstName); Assert.Equal("redfield", user.Profile.LastName); Assert.NotNull(user.Addresses); Assert.Equal("rc", user.Addresses[0].Street); Assert.Equal("123", user.Addresses[0].Number); Assert.NotNull(user.Roles); Assert.Equal(2, user.Roles.Count); Assert.Contains(user.Roles, r => r.Id == 1); Assert.Contains(user.Roles, r => r.Id == 2); Assert.NotNull(user.UserType); Assert.Equal(1, user.UserType.Id); }