public async Task GetExistingUser() { _userMock.Setup(x => x.GetItemAsync(1, false)).Returns(async() => await UserMocks.UserMock()); var service = new UserManagementService(_userMock.Object); var user = await service.GetUser(1); Assert.Equal("Daniel Alderete Merino", user.Name); }
public async Task GetNonExistingUser() { _userMock.Setup(x => x.GetItemAsync(2, true)).Returns(async() => await UserMocks.UserMock()); var service = new UserManagementService(_userMock.Object); var user = await service.GetUser(1); Assert.True(user is null); }
public async Task CreateUser() { var user = await UserMocks.UserMock(); _userMock.Setup(x => x.CreateItemAsync(user)).Returns(Task.FromResult(true)); var service = new UserManagementService(_userMock.Object); bool created = await service.CreateUser(user); Assert.True(created); }
public async Task CreateUserInRepository() { var user = await UserMocks.UserMock(); var created = await _repository.CreateItemAsync(user); Assert.True(created); var savedUser = await _repository.GetItemAsync(user.Id); Assert.Equal(user, savedUser); }
public async Task GetNotExistingUserInRepository() { var user = await UserMocks.UserMock(); var created = await _repository.CreateItemAsync(user); Assert.True(created); var savedUser = await _repository.GetItemAsync(user.Id + 1, true); Assert.True(savedUser.Id == 0); await Assert.ThrowsAsync <KeyNotFoundException>(async() => await _repository.GetItemAsync(user.Id + 1, false)); }
public async Task GetAllExistingUsersInRepository() { var users = (await UserMocks.UsersMock()).OrderBy(i => i.Id).ToList(); await _repository.CreateItemsAsync(users); var savedUsers = (await _repository.GetItemsAsync(i => i.Id != 0)).OrderBy(i => i.Id).ToList(); Assert.Equal(users, savedUsers); var serializedUsers = JsonConvert.SerializeObject(users); var serializedSavedUsers = JsonConvert.SerializeObject(savedUsers); Assert.Equal(serializedUsers, serializedSavedUsers); }
public async Task DeleteUser() { var users = (await UserMocks.UsersMock()).OrderBy(i => i.Id).ToList(); await _repository.CreateItemsAsync(users); var savedUsers = (await _repository.GetItemsAsync(i => i.Id != 0)).OrderBy(i => i.Id).ToList(); Assert.Equal(users, savedUsers); await _repository.DeleteItemAsync(10); var newSavedUsers = (await _repository.GetItemsAsync(i => i.Id != 0)).OrderBy(i => i.Id).ToList(); Assert.True(savedUsers.Count == newSavedUsers.Count + 1); }
public async Task UpdateUser() { var users = (await UserMocks.UsersMock()).OrderBy(i => i.Id).ToList(); await _repository.CreateItemsAsync(users); var savedUsers = (await _repository.GetItemsAsync(i => i.Id != 0)).OrderBy(i => i.Id).ToList(); Assert.Equal(users, savedUsers); var myUser = await UserMocks.UserMock(); await _repository.UpdateItemAsync(10, myUser); var mySavedUser = await _repository.GetItemAsync(10); Assert.Equal(myUser.Name, mySavedUser.Name); }
public async Task GetAllUsers() { _userMock.Setup(x => x.GetItemsAsync(i => i.Id != 0)).Returns(async() => await UserMocks.UsersMock()); var service = new UserManagementService(_userMock.Object); var users = await service.GetAllUsers(); Assert.True(users.Count == 5); Assert.True(users.FirstOrDefault(i => i.Id == 2) is null); Assert.True(users.OrderByDescending(i => i.Id).FirstOrDefault().Id == 10); }