public async Task ThenItShouldReturnTheUserIfFound() { // Act var actual = await _handler.Handle(_query); // Assert Assert.AreSame(_user, actual); }
public async Task Should_get_user_by_id() { var user = await Context.Data.SeedUser(); var userDetails = await _query.Handle(new GetUserByIdQuery(user.Id)); userDetails.Should().BeEquivalentTo(user); }
public async Task GetUserById_UserDoesNotExist_ThrowsNotFoundException() { var sut = new GetUserByIdQueryHandler(_context); await sut.Handle(new GetUserByIdQuery { Id = Guid.NewGuid() }, CancellationToken.None) .ShouldThrowAsync <NotFoundException>(); }
public static UserDto GetUserById(int userId) { var queryObject = new GetUserByIdQuery(userId); var handler = new GetUserByIdQueryHandler(); UserDto user = handler.Handle(queryObject).Result; return(user); }
public async Task GetUserById_UserExists_ReturnsUserViewModel() { var sut = new GetUserByIdQueryHandler(_context); var user = _context.User.First(); var result = await sut.Handle(new GetUserByIdQuery { Id = user.Id }, CancellationToken.None); result.ShouldBeOfType <UserViewModel>(); result.Id.ShouldBe(user.Id); }
public void GetUserById_NotFound(Guid id) { base.UsersRespositoryMock.Setup(x => x.FindSingle(It.IsAny <Expression <Func <User, bool> > >())).ReturnsAsync(value: default); var handler = new GetUserByIdQueryHandler(base.UnitOfWorkMock.Object); var result = handler.Handle(new GetUserByIdQuery(id), default); Assert.IsNotNull(result); Assert.IsInstanceOf <Task <Response <UserVm> > >(result); Assert.AreEqual(StatusCodes.Status404NotFound, result.Result.StatusCode); }
public async Task GetUserByIdQuery_PresentNotExistsUserId_ReturnsNull() { // ---- Arrange ---- var query = new GetUserByIdQuery(Guid.Empty); var handler = new GetUserByIdQueryHandler(_repositoryProviderMock.Object); // ---- Act ---- var user = await handler.Handle(query, CancellationToken.None); // ---- Assert ---- Assert.IsNull(user); }
public async Task Handle_GivenInvalidRequest_ShouldThrowNotFoundException() { // Arrange var query = new GetUserByIdQuery(Guid.NewGuid()); var queryHandler = new GetUserByIdQueryHandler(_fixture.DbContext, _fixture.Mapper); // Act Func <Task <UserDto> > result = () => queryHandler.Handle(query, CancellationToken.None); // Assert await result.Should().ThrowAsync <NotFoundException>(); }
public async Task Handle_GivenValidRequest_ShouldReturnUser() { // Arrange var query = new GetUserByIdQuery(_fixture.KnownUserID); var queryHandler = new GetUserByIdQueryHandler(_fixture.DbContext, _fixture.Mapper); // Act UserDto user = await queryHandler.Handle(query, CancellationToken.None); // Assert user.Should().NotBeNull(); user.UserId.Should().Equals(_fixture.KnownUserID); }
public void GetUserByIdQuery_PresentNotExistsUserIdAllowException_ThrowException() { // ---- Arrange ---- var query = new GetUserByIdQuery(Guid.Empty) { ThrowIfNotExists = true }; var handler = new GetUserByIdQueryHandler(_repositoryProviderMock.Object); // ---- Act & Assert var exception = Assert.ThrowsAsync <UserNotFoundByIdException>(async() => await handler.Handle(query, CancellationToken.None)); Assert.AreEqual(query.UserId, exception.UserId); }
public async Task GivenAnId_WhenGetUserByIdQueryHandler_ThenReturnNotNull() { var user = UserFactory.ValidUser(); var command = new GetUserByIdQuery(user.Id); var mockRepo = new Mock <IUserRepository>(); mockRepo.Setup(db => db.GetByIdAsync(command.Id).Result).Returns(user); var handler = new GetUserByIdQueryHandler(mockRepo.Object); var result = await handler.Handle(command, CancellationToken.None); result.Should().NotBeNull(); result.Id.Should().Be(user.Id); result.Type.Should().Be(user.Type); result.Location.Should().Be(user.Location); result.Username.Should().Be(user.Username); }
public void GetUserById_Successfully(Guid id) { base.UsersRespositoryMock.Setup(x => x.FindSingle(It.IsAny <Expression <Func <User, bool> > >())).ReturnsAsync(new User { Id = id, Name = "test", Email = "test" }); var handler = new GetUserByIdQueryHandler(base.UnitOfWorkMock.Object); var result = handler.Handle(new GetUserByIdQuery(id), default); Assert.IsNotNull(result); Assert.IsInstanceOf <Task <Response <UserVm> > >(result); Assert.AreEqual(StatusCodes.Status200OK, result.Result.StatusCode); }
public async Task ShouldReturn_OneUserExists_ReturnUserViewModel() { var fixture = new Fixture(); var user = fixture.Create <Task <User> >(); var userRepository = new Mock <IUserRepository>(); var getUserByIdQuery = new GetUserByIdQuery(user.Id); var getPeopleByIdQueryHandler = new GetUserByIdQueryHandler(userRepository.Object); userRepository.Setup(pr => pr.GetByIdAsync(user.Id)) .Returns(user); var userResult = await getPeopleByIdQueryHandler.Handle(getUserByIdQuery, new System.Threading.CancellationToken());; Assert.NotNull(userResult); Assert.IsType <UserViewModel>(userResult); }
public async Task GetUserByIdQuery_PresentExistsUserId_ReturnsUser() { // ---- Arrange ---- var userId = Guid.NewGuid(); _usersRepositoryMock.Setup(r => r.Get(userId)) .ReturnsAsync((Guid id) => _userFactory.Get(id)); var query = new GetUserByIdQuery(userId); var handler = new GetUserByIdQueryHandler(_repositoryProviderMock.Object); // ---- Act ---- var user = await handler.Handle(query, CancellationToken.None); // ---- Assert ---- _usersRepositoryMock.Verify(r => r.Get(userId), Times.Once); Assert.NotNull(user); Assert.AreEqual(userId, user.Id); }
public async Task ThreeProjectsExist_Executed_ReturnThreeUserByIdViewModels() { // Arrange var user = new User("Thiago Primo", "*****@*****.**", null, "-dpf!#14", "client"); var userRepositoryMock = new Mock <IUserRepository>(); userRepositoryMock.Setup(u => u.GetByIdAsync(user.Id).Result).Returns(user); var getUserByIdQuery = new GetUserByIdQuery(user.Id); var getUserByIdQueryHandler = new GetUserByIdQueryHandler(userRepositoryMock.Object); // Act var userViewModel = await getUserByIdQueryHandler.Handle(getUserByIdQuery, new CancellationToken()); //Assert Assert.NotNull(userViewModel); userRepositoryMock.Verify(u => u.GetByIdAsync(user.Id).Result, Times.Once); }
public async Task UserWithIdExists_Executed_ReturnUserViewModel() { //Arrange var user = new User("Usuário de teste", "*****@*****.**", Convert.ToDateTime("15/12/1993"), "123456", "client"); var userRepositoryMock = new Mock <IUserRepository>(); var getUserByIdQuery = new GetUserByIdQuery(4); var getUserByIdQueryHandler = new GetUserByIdQueryHandler(userRepositoryMock.Object); userRepositoryMock.Setup(u => u.GetByIdAsync(getUserByIdQuery.id).Result).Returns(user); //Act var userViewModel = await getUserByIdQueryHandler.Handle(getUserByIdQuery, new CancellationToken()); //Assert Assert.NotNull(userViewModel); userRepositoryMock.Verify(pr => pr.GetByIdAsync(It.IsAny <int>()), Times.Once); }