public async Task AddUserShouldThrowException() { UserProfile user = new UserProfile { UserId = "Jack", FirstName = "Jackson", LastName = "James", Contact = "9812345670", Email = "*****@*****.**", CreatedAt = DateTime.Now }; var mockRepo = new Mock <IUserRepository>(); mockRepo.Setup(repo => repo.GetUser(user.UserId)).Returns(Task.FromResult(user)); var service = new UserService.Services.UserService(mockRepo.Object); var actual = await Assert.ThrowsAsync <UserAlreadyExistsException>(() => service.AddUser(user)); Assert.Equal($"{user.UserId} is already in use", actual.Message); }
public async Task AddUserShouldSuccess() { UserProfile user = new UserProfile { UserId = "John", FirstName = "Johnson", LastName = "dsouza", Contact = "7869543210", Email = "*****@*****.**", CreatedAt = DateTime.Now }; UserProfile _user = null; var mockRepo = new Mock <IUserRepository>(); mockRepo.Setup(repo => repo.GetUser(user.UserId)).Returns(Task.FromResult(_user)); mockRepo.Setup(repo => repo.AddUser(user)).Returns(Task.FromResult(true)); var service = new UserService.Services.UserService(mockRepo.Object); var actual = await service.AddUser(user); Assert.True(actual); }