public async Task GetSalesPerson_ShouldReturnSalesPerson_GivenSalesPerson(
            [Frozen] Mock <IMediator> mockMediator,
            Core.Handlers.GetSalesPerson.SalesPersonDto salesPerson,
            [Greedy] SalesPersonController sut,
            GetSalesPersonQuery query
            )
        {
            //Arrange
            mockMediator.Setup(x => x.Send(
                                   It.IsAny <GetSalesPersonQuery>(),
                                   It.IsAny <CancellationToken>()
                                   ))
            .ReturnsAsync(salesPerson);

            //Act
            var actionResult = await sut.GetSalesPerson(query);

            //Assert
            var okObjectResult = actionResult as OkObjectResult;

            okObjectResult.Should().NotBeNull();

            var result = okObjectResult.Value as Core.Models.SalesPerson;

            result.FullName().Should().Be(salesPerson.FullName());
        }
        public async Task Handle_SalesPersonExists_ReturnSalesPerson(
            Core.Entities.SalesPerson salesPerson,
            [Frozen] Mock <IRepository <Core.Entities.SalesPerson> > salesPersonRepoMock,
            GetSalesPersonQueryHandler sut,
            GetSalesPersonQuery query
            )
        {
            //Arrange
            salesPersonRepoMock.Setup(x => x.GetBySpecAsync(
                                          It.IsAny <GetSalesPersonSpecification>(),
                                          It.IsAny <CancellationToken>()
                                          ))
            .ReturnsAsync(salesPerson);

            //Act
            var result = await sut.Handle(query, CancellationToken.None);

            //Assert
            result.Should().NotBeNull();
            salesPersonRepoMock.Verify(x => x.GetBySpecAsync(
                                           It.IsAny <GetSalesPersonSpecification>(),
                                           It.IsAny <CancellationToken>()
                                           ));

            result.FullName().Should().Be(salesPerson.FullName);
        }
Exemple #3
0
        public IActionResult Get(Guid id)
        {
            var query       = new GetSalesPersonQuery(id);
            var salesPerson = _queryProcessor.Process(query);

            return(View(salesPerson));
        }
        public void Handle_SalesPersonsNull_ThrowsArgumentNullException(
            [Frozen] Mock <IRepository <Core.Entities.SalesPerson> > salesPersonRepoMock,
            GetSalesPersonQueryHandler sut,
            GetSalesPersonQuery query
            )
        {
            //Arrange
            salesPersonRepoMock.Setup(x => x.GetBySpecAsync(
                                          It.IsAny <GetSalesPersonSpecification>(),
                                          It.IsAny <CancellationToken>()
                                          ))
            .ReturnsAsync((Core.Entities.SalesPerson)null);

            //Act
            Func <Task> func = async() => await sut.Handle(query, CancellationToken.None);

            //Assert
            func.Should().ThrowAsync <ArgumentNullException>()
            .WithMessage("Value cannot be null. (Parameter 'salesPerson')");
        }
        public async Task GetSalesPerson_ShouldReturnNotFound_GivenNoSalesPerson(
            [Frozen] Mock <IMediator> mockMediator,
            [Greedy] SalesPersonController sut,
            GetSalesPersonQuery query
            )
        {
            //Arrange
            mockMediator.Setup(x => x.Send(
                                   It.IsAny <GetSalesPersonQuery>(),
                                   It.IsAny <CancellationToken>()
                                   ))
            .ReturnsAsync((Core.Handlers.GetSalesPerson.SalesPersonDto)null);

            //Act
            var actionResult = await sut.GetSalesPerson(query);

            //Assert
            var notFoundResult = actionResult as NotFoundResult;

            notFoundResult.Should().NotBeNull();
        }
Exemple #6
0
 public SalesPerson Handle(GetSalesPersonQuery query)
 {
     return(_repository.GetById(query.Id));
 }