public async Task Club_FindByID_ReturnsAView() { _clubService.Setup(c => c.GetClubProfileAsync(It.IsAny <int>())) .ReturnsAsync(() => new ClubProfileDTO { Club = new ClubDTO() }); _mapper.Setup(c => c.Map <ClubProfileDTO, ClubProfileViewModel>(It.IsAny <ClubProfileDTO>())) .Returns(new ClubProfileViewModel()); //action var result = await controller.Club(It.IsAny <int>()); //assert var viewResult = Assert.IsType <ViewResult>(result); Assert.IsAssignableFrom <ClubProfileViewModel>(viewResult.Model); }
public void ClubPageTest() { //arrange repository.Setup(c => c.Club.FindByCondition(It.IsAny <Expression <Func <Club, bool> > >())).Returns(GetTestClubs()); //action var controller = new ClubController(repository.Object, usermanager.Object, hostingEnvironment.Object); var result = controller.Club(1); //assert var viewResult = Assert.IsType <ViewResult>(result); Assert.IsAssignableFrom <ClubViewModel>(viewResult.Model); }
public async Task Club_ReturnsOkObjectResult() { //Arrange var httpContext = new Mock <HttpContext>(); httpContext .Setup(m => m.User.IsInRole("Admin")) .Returns(true); var context = new ControllerContext( new ActionContext( httpContext.Object, new RouteData(), new ControllerActionDescriptor())); _clubController.ControllerContext = context; var clubID = GetClubId(); _mapper .Setup(m => m.Map <ClubProfileDTO, ClubProfileViewModel>(It.IsAny <ClubProfileDTO>())) .Returns(new ClubProfileViewModel() { Club = new ClubViewModel() }); _clubService .Setup(x => x.GetClubProfileAsync(clubID)) .ReturnsAsync(new ClubProfileDTO()); _clubService .Setup(x => x.GetImageBase64Async(It.IsAny <string>())) .ReturnsAsync("string"); //Act var result = await _clubController.Club(clubID); var resultValue = (result as OkObjectResult).Value; //Assert _clubService.Verify(); _mapper.Verify(); Assert.IsNotNull(result); Assert.IsInstanceOf <OkObjectResult>(result); Assert.IsNotNull(resultValue); Assert.IsInstanceOf <ClubProfileViewModel>(resultValue); }