public async Task GetAllUsersQueryShouldReturnList() { // Prepare var list = new List <User> { new User("123", "John Smith", new Address(0, 0, "The Address", true, "")) }; _mockRepo.Setup(c => c.GetAllUsersAsync()).ReturnsAsync(list.AsEnumerable()); var resultToMap = new List <User> { new User("123", "John Smith", new Address(0, 0, "The Address", true, "")) }; var expected = _mapper.Map <IEnumerable <UserSummary> >(resultToMap); var handler = new GetAllUsersQueryHandler(_mockRepo.Object, _mapper); var query = new GetAllUsersQuery(); // Act var actual = await handler.Handle(query, default); // Assert Assert.Collection(actual, item => { Assert.Equal("123", item.Id); Assert.Equal("John Smith", item.Name); Assert.Equal("The Address", item.Address.Name); } ); }
public async Task FourUsersExist_Executed_ReturnUserViewModels() { //Arrange var users = new List <User> { new User("Nome 1", "*****@*****.**", Convert.ToDateTime("15/04/1998"), "123456", "client"), new User("Nome 2", "*****@*****.**", Convert.ToDateTime("06/01/2000"), "@151293vsm", "freelancer"), new User("Nome 3", "*****@*****.**", Convert.ToDateTime("06/06/1989"), "@6789", "freelancer"), new User("Nome 4", "*****@*****.**", Convert.ToDateTime("10/12/1993"), "@151293smv", "client") }; var userRepositoryMock = new Mock <IUserRepository>(); userRepositoryMock.Setup(s => s.GetAllAsync().Result).Returns(users); var getAllUsersQuery = new GetAllUsersQuery(""); var getAllUsersQueryHandler = new GetAllUsersQueryHandler(userRepositoryMock.Object); //Act var userViewModelList = await getAllUsersQueryHandler.Handle(getAllUsersQuery, new CancellationToken()); //Assert Assert.NotNull(userViewModelList); Assert.NotEmpty(userViewModelList); Assert.Equal(users.Count, userViewModelList.Count); userRepositoryMock.Verify(u => u.GetAllAsync().Result, Times.Once); }
public async Task ShouldReturn_ThreeMoviesExists_ReturnPagedListUserViewModel() { var fixture = new Fixture(); var movies = fixture.Create <List <User> >(); var userParameters = new UserParameters(); var pagedListMovie = new PagedList <User>(movies, movies.Count, 0, 0); var movieRepository = new Mock <IUserRepository>(); var getAllMoviesQuery = new GetAllUsersQuery(userParameters); var getAllMovieQueryHandler = new GetAllUsersQueryHandler(movieRepository.Object); movieRepository.Setup(pr => pr.GetAllAsync(userParameters)) .Returns(pagedListMovie); var usersPagedList = await getAllMovieQueryHandler.Handle(getAllMoviesQuery, new System.Threading.CancellationToken());; Assert.NotNull(usersPagedList); Assert.NotEmpty(usersPagedList); Assert.Equal(3, usersPagedList.TotalRecords); Assert.Equal(1, usersPagedList.TotalPages); Assert.Equal(50, usersPagedList.PageSize); Assert.IsType <PagedList <UserViewModel> >(usersPagedList); movieRepository.Verify(mr => mr.GetAllAsync(userParameters), Times.Once); }
public async Task ExistThreeUsers_Executed_ThreeUsersViewModel() { // Arrange var users = new List <User> { new User("Marlon", "marlon.ricci", DateTime.Now), new User("Micael", "micael.ricci", DateTime.Now), new User("Natalia", "natalia.spigolon", DateTime.Now) }; var userRepository = new Mock <IUserRepository>(); userRepository.Setup(sr => sr.GetAll()).Returns(Task.FromResult(users)); var getAllUsersQuery = new GetAllUsersQuery(); var getAllUsersQueryHandler = new GetAllUsersQueryHandler(userRepository.Object); // Act var usersViewModel = await getAllUsersQueryHandler.Handle(getAllUsersQuery, new CancellationToken()); // Assert Assert.NotNull(usersViewModel); Assert.Equal(users.Count, usersViewModel.Count); foreach (var user in users) { var userViewModel = usersViewModel.SingleOrDefault(s => s.Name == user.Name); Assert.NotNull(userViewModel); } userRepository.Verify(ur => ur.GetAll(), Times.Once); }
public async Task GetUserTest() { var sut = new GetAllUsersQueryHandler(_context, _mapper); var result = await sut.Handle(new GetAllUserQuery(), CancellationToken.None); result.ShouldBeOfType <UserDto>(); result.Count.ShouldBe(3); }
public void GetAllUsers_Successfully() { var handler = new GetAllUsersQueryHandler(base.UnitOfWorkMock.Object); var result = handler.Handle(new GetAllUsersQuery(), default); Assert.IsNotNull(result); Assert.IsInstanceOf <Task <Response <IEnumerable <UserVm> > > >(result); Assert.AreEqual(StatusCodes.Status200OK, result.Result.StatusCode); }
public async Task Handle_GivenValidRequest_ShouldReturnUser() { // Arrange var query = new GetAllUsersQuery(); var queryHandler = new GetAllUsersQueryHandler(_fixture.DbContext, _fixture.Mapper); // Act IEnumerable <UserDto> users = await queryHandler.Handle(query, CancellationToken.None); // Assert Assert.True(users.Any()); }
public async Task Handle_GetAllQuery_ShouldReturnEntriesSuccessfully(List <UserOutput> output) { // Arrange _mapperMock.Setup(m => m.Map <List <UserOutput> >(It.IsAny <List <User> >())).Returns(output); // AutoMapper setup var sut = new GetAllUsersQueryHandler(_context, _mapperMock.Object); // creating system under test var temUser = _fixture.Create <User>(); // Act await ContextOperation.CreateEntity(_context, temUser); var result = await sut.Handle(new GetAllUsersQuery(), CancellationToken.None); // Assert result.Count().ShouldBeGreaterThan(0); }
public async Task GivenAList_WhenGetAllUsersQueryHandler_ThenReturnNotNull() { var user1 = UserFactory.ValidUser(); var user2 = UserFactory.ValidUser(); var users = new List <User> { user1, user2 }; var command = new GetAllUsersQuery(); var mockRepo = new Mock <IUserRepository>(); mockRepo.Setup(db => db.GetAllAsync().Result).Returns(users); var handler = new GetAllUsersQueryHandler(mockRepo.Object); var result = await handler.Handle(command, CancellationToken.None); result.Should().NotContainNulls(); result.Should().HaveCount(users.Count); result.Should().Contain(user1); }