Exemple #1
0
        public async Task Handle_CustomersExists_ReturnCustomers(
            [Frozen] Mock <IRepository <Entities.Customer> > customerRepoMock,
            GetCustomersQueryHandler sut,
            List <Entities.Customer> customers,
            GetCustomersQuery query
            )
        {
            // Arrange
            customerRepoMock.Setup(x => x.CountAsync(
                                       It.IsAny <CountCustomersSpecification>(),
                                       It.IsAny <CancellationToken>()
                                       ))
            .ReturnsAsync(customers.Count);

            //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>()
                                        ));
            customerRepoMock.Verify(x => x.CountAsync(
                                        It.IsAny <ISpecification <Entities.Customer> >(),
                                        It.IsAny <CancellationToken>()
                                        ));
            result.TotalCustomers.Should().Be(customers.Count);
        }
Exemple #2
0
        public async Task GetCustomers()
        {
            var sut = new GetCustomersQueryHandler(_context, _mapper);

            var result = await sut.Handle(new GetCustomersQuery { PageNumber = 0, RowCount = 10 }, CancellationToken.None);

            result.ShouldBeOfType <PaggingData <CustomersDto> >();
            result.ShouldNotBeNull();
        }
Exemple #3
0
        public async Task Handle_ShouldReturnCustomers()
        {
            A.CallTo(() => _customerRepository.GetAll()).Returns(_customers);

            var result = await _testee.Handle(new GetCustomersQuery(), default);

            A.CallTo(() => _customerRepository.GetAll()).MustHaveHappenedOnceExactly();
            result.Should().BeOfType <List <Customer> >();
            result.Count.Should().Be(2);
        }
Exemple #4
0
        public async Task GetAllAsync()
        {
            var dataAccess = new CustomerDataAccess(this.Context);

            //Act
            var sutCreate    = new CreateCustomerCommandHandler(dataAccess);
            var resultCreate = await sutCreate.Handle(new CreateCustomerCommand
            {
                Data = CustomerTestData.CustomerDataDTO
            }, CancellationToken.None);

            //Act
            var sutGetAll    = new GetCustomersQueryHandler(dataAccess);
            var resultGetAll = await sutGetAll.Handle(new GetCustomersQuery(), CancellationToken.None);

            Assert.IsTrue(resultGetAll?.Data.Count == 1);
        }
Exemple #5
0
        public void Handle_NoCustomersExists_ThrowArgumentNullException(
            [Frozen] Mock <IRepository <Entities.Customer> > customerRepoMock,
            GetCustomersQueryHandler sut,
            GetCustomersQuery query
            )
        {
            // Arrange
            customerRepoMock.Setup(x => x.ListAsync(
                                       It.IsAny <GetCustomersPaginatedSpecification>(),
                                       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')");
        }