public async void UpdateUserAsyncTest(string fName, string lName, string mName, string eMail, string phone) { var options = new DbContextOptionsBuilder <UsersContext>() .UseInMemoryDatabase(databaseName: "UpdateUser") .Options; using (var context = new UsersContext(options)) { var repository = new ReceiverRepository(context); repository.Initialize(); } using (var context = new UsersContext(options)) { var repository = new ReceiverRepository(context); var user = repository.GetUsers().FirstOrDefault(); user.FirstName = fName; user.LastName = lName; user.MiddleName = mName; user.EMail = eMail; user.PhoneNumber = phone; await repository.UpdateUserAsync(user, CancellationToken.None); var userTest = repository.GetUsers().FirstOrDefault(); Assert.Equal(fName, userTest.FirstName); Assert.Equal(lName, userTest.LastName); Assert.Equal(mName, userTest.MiddleName); Assert.Equal(eMail, userTest.EMail); Assert.Equal(phone, userTest.PhoneNumber); } }
public async Task AddUserToOrganizationAsyncTest(string orgName) { var options = new DbContextOptionsBuilder <UsersContext>() .UseInMemoryDatabase(databaseName: "AddUserToOrganizationAsync") .Options; using (var context = new UsersContext(options)) { var repository = new ReceiverRepository(context); repository.Initialize(); context.Organizations.Add(new OrganizationDTO { Name = orgName }); context.SaveChanges(); } using (var context = new UsersContext(options)) { var repository = new ReceiverRepository(context); var user = repository.GetUsers().FirstOrDefault(); var org = repository.GetOrganizations().FirstOrDefault(o => o.Name == orgName); await repository.AddUserToOrganizationAsync(user.UserId, org.OrganizationId, CancellationToken.None); var userTest = context.Users.Include(u => u.Organization).FirstOrDefault(); Assert.Equal(orgName, userTest.Organization.Name); } }
public async Task AddUserAsyncTest(string fName, string lName, string mName, string eMail, string phone) { var options = new DbContextOptionsBuilder <UsersContext>() .UseInMemoryDatabase(databaseName: "AddUserAsync") .Options; var userId = 0; using (var context = new UsersContext(options)) { var repository = new ReceiverRepository(context); userId = await repository.AddUserAsync(new UserDTO { FirstName = fName, LastName = lName, MiddleName = mName, EMail = eMail, PhoneNumber = phone }, CancellationToken.None); } using (var context = new UsersContext(options)) { var repository = new ReceiverRepository(context); var user = repository.GetUsers().FirstOrDefault(f => f.UserId == userId); Assert.Equal(fName, user.FirstName); Assert.Equal(lName, user.LastName); Assert.Equal(mName, user.MiddleName); Assert.Equal(eMail, user.EMail); Assert.Equal(phone, user.PhoneNumber); } }