public async Task GetUser_UserNotExists_ReturnsNotFound() { // Arrange var mockConfiguration = new Mock <Microsoft.Extensions.Configuration.IConfiguration>(); var mockLogger = new Mock <ILogger <AccountController> >(); var mockUmService = new Mock <IUserManagementService>(); var mockHelperService = new Mock <IHelperService>(); var mapperConfig = new MapperConfiguration(cfg => { cfg.AddProfile(new AutomapperProfiles.UserProfile()); }); var mapper = mapperConfig.CreateMapper(); mockUmService.Setup(umService => umService.FindUserAsync("a")) .ReturnsAsync((ApplicationUser)null) .Verifiable(); var controller = new UsersController(mockConfiguration.Object, mockLogger.Object, mockUmService.Object, mapper, mockHelperService.Object); // Act var result = await controller.GetUser("a"); // Assert var actionResult = Assert.IsType <ActionResult <UserModel> >(result); var returnValue = Assert.IsType <NotFoundResult>(actionResult.Result); mockUmService.Verify(); }
public async Task GetUser_UserExists_ReturnsUser() { // Arrange var mockConfiguration = new Mock <Microsoft.Extensions.Configuration.IConfiguration>(); var mockLogger = new Mock <ILogger <AccountController> >(); var mockUmService = new Mock <IUserManagementService>(); var mockHelperService = new Mock <IHelperService>(); var mapperConfig = new MapperConfiguration(cfg => { cfg.AddProfile(new AutomapperProfiles.UserProfile()); }); var mapper = mapperConfig.CreateMapper(); var a = new ApplicationUser { Id = "a", FirstName = "a", LastName = "b", Email = "[email protected]", UserName = "******" }; mockUmService.Setup(umService => umService.FindUserAsync("a")) .ReturnsAsync(a) .Verifiable(); mockUmService.Setup(umService => umService.GetUserRoleAsync("a", true)) .ReturnsAsync("Employee") .Verifiable(); var controller = new UsersController(mockConfiguration.Object, mockLogger.Object, mockUmService.Object, mapper, mockHelperService.Object); // Act var result = await controller.GetUser("a"); // Assert var actionResult = Assert.IsType <ActionResult <UserModel> >(result); var returnValue = Assert.IsType <UserModel>(actionResult.Value); mockUmService.Verify(); Assert.Equal("[email protected]", returnValue.Email); }