public async Task GetAllCustomerDetailTests() { var sut = new GetAllCustomersQueryHandler(_logger, _mapper, _context); var result = await sut.Handle(null, CancellationToken.None); var sortedResult = result.OrderBy(x => x.Name).ToList(); //foreach ( var ) Assert.NotNull(sortedResult); Assert.Equal(3, sortedResult.Count); Assert.Collection(sortedResult, item => { Assert.Equal("Test1", item.Name); Assert.Equal("*****@*****.**", item.Email); }, item => { Assert.Equal("Test2", item.Name); Assert.Equal("*****@*****.**", item.Email); }, item => { Assert.Equal("Test3", item.Name); Assert.Equal("*****@*****.**", item.Email); }); }
public async Task Handle_CustomersExists_ReturnCustomers( [Frozen] Mock <IRepository <Entities.Customer> > customerRepoMock, GetAllCustomersQueryHandler sut, List <Entities.IndividualCustomer> customers, GetAllCustomersQuery query ) { // Arrange customerRepoMock.Setup(x => x.ListAsync( It.IsAny <GetAllCustomersSpecification>(), It.IsAny <CancellationToken>() )) .ReturnsAsync(customers.Cast <Entities.Customer>().ToList()); //Act var result = await sut.Handle(query, CancellationToken.None); //Assert result.Should().NotBeNull(); customerRepoMock.Verify(x => x.ListAsync( It.IsAny <ISpecification <Entities.Customer> >(), It.IsAny <CancellationToken>() )); result.Count.Should().Be(customers.Count); }
public async Task Handle_GivenNullRequest_ShouldThrowArgumentNullException() { // Arrange var sut = new GetAllCustomersQueryHandler(this.deletableEntityRepository); // Act & assert await Should.ThrowAsync <ArgumentNullException>(sut.Handle(null, It.IsAny <CancellationToken>())); }
public GetAllCustomerHandlerTests() { _customerList = _fixture.Create <List <Entity.Concrete.Customer> >(); _customerListResponse = new Mock <List <GetAllCustomerQueryResponse> >(); _customerListDataResponse = new Mock <IDataResult <List <GetAllCustomerQueryResponse> > >(); _mapper = new Mock <IMapper>(); _repository = new Mock <IGenericRepository <Entity.Concrete.Customer> >(); _sut = new GetAllCustomersQueryHandler(_repository.Object, _mapper.Object); }
public async Task Handle_GivenValidRequest_ShouldReturnViewModel() { // Arrange var query = new GetAllCustomersQuery(); var sut = new GetAllCustomersQueryHandler(this.deletableEntityRepository); // Act var viewModel = await sut.Handle(query, It.IsAny <CancellationToken>()); viewModel.ShouldNotBeNull(); viewModel.ShouldBeOfType <GetAllCustomersViewModel>(); viewModel.Customers.Count().ShouldBe(1); }
public async Task Test_ForExistingCustomers_ShouldReturnCustomers() { // Arrange var mock = new Mock <ICustomerRepository>(); Fixture.RepeatCount = 9; var customers = Fixture.Create <Customer[]>(); mock.Setup(foo => foo.GetAll()).Returns(customers); var query = new GetAllCustomersQuery(); var queryHandler = new GetAllCustomersQueryHandler(mock.Object); // Act var result = await queryHandler.Handle(query, CancellationToken.None); // Assert Assert.NotNull(result); Assert.NotEmpty(result); Assert.Equal(customers.Length, result.Count()); }
public void Handle_NoCustomersExists_ThrowArgumentNullException( [Frozen] Mock <IRepository <Entities.Customer> > customerRepoMock, GetAllCustomersQueryHandler sut, GetAllCustomersQuery query ) { // Arrange customerRepoMock.Setup(x => x.ListAsync( It.IsAny <GetAllCustomersSpecification>(), It.IsAny <CancellationToken>() )) .ReturnsAsync((List <Entities.Customer>)null); //Act Func <Task> func = async() => await sut.Handle(query, CancellationToken.None); //Assert func.Should().Throw <ArgumentNullException>() .WithMessage("Value cannot be null. (Parameter 'customers')"); }