Beispiel #1
0
        public GetCustomersQueryHandlerTests()
        {
            this.repositoryMock = new Mock <ICustomersRepository>();

            this.handler = new GetCustomersQueryHandler(this.repositoryMock.Object);
            this.fixture = new Fixture();
        }
Beispiel #2
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);
        }
Beispiel #3
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();
        }
Beispiel #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);
        }
Beispiel #5
0
        public GetCustomersQueryHandlerTests()
        {
            _customerRepository = A.Fake <ICustomerRepository>();
            _testee             = new GetCustomersQueryHandler(_customerRepository);

            _customers = new List <Customer>
            {
                new Customer
                {
                    Id  = new Guid(),
                    Age = 42
                },
                new Customer
                {
                    Id  = new Guid(),
                    Age = 22
                }
            };
        }
Beispiel #6
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')");
        }