public async Task GetProfile_ThorowsNotFoundException_WhenUserNotFound() { //Arrange Mock <IApplicationUsersRepository> applicationRepository = new Mock <IApplicationUsersRepository>(); Mock <IApplicationUsersUnitOfWork> unitOfWork = new Mock <IApplicationUsersUnitOfWork>(); applicationRepository.Setup(s => s.GetUser(It.IsAny <Guid>())).Throws <NotFoundException>(); unitOfWork.Setup(u => u.ApplicationUsers).Returns(applicationRepository.Object); Mock <IMapper> mapper = new Mock <IMapper>(); mapper.Setup(m => m.Map <UserInfoDetailsViewDto>(It.IsAny <Object>())).Returns(new UserInfoDetailsViewDto()); var handler = new UserGetHandler( unitOfWork.Object, mapper.Object ); //Act/Assert await Assert.ThrowsAsync <NotFoundException>(async() => { await handler.HandleAsync(new UserGetQuery()); }); }
public async Task GetProfile_ReturnsUserProfile_WhenUserFound() { //Arrange Mock <IApplicationUsersRepository> applicationRepository = new Mock <IApplicationUsersRepository>(); Mock <IApplicationUsersUnitOfWork> unitOfWork = new Mock <IApplicationUsersUnitOfWork>(); applicationRepository.Setup(s => s.GetUser(It.IsAny <Guid>())).ReturnsAsync(new ApplicationUser()); unitOfWork.Setup(u => u.ApplicationUsers).Returns(applicationRepository.Object); Mock <IMapper> mapper = new Mock <IMapper>(); mapper.Setup(m => m.Map <UserInfoDetailsViewDto>(It.IsAny <Object>())).Returns(new UserInfoDetailsViewDto()); var handler = new UserGetHandler( unitOfWork.Object, mapper.Object ); //Act var result = await handler.HandleAsync(new UserGetQuery()); //Assert Assert.NotNull(result); Assert.IsAssignableFrom <UserInfoDetailsViewDto>(result); }