Ejemplo n.º 1
0
        public async Task GetList_WithoutItemType_PassesExpectedQuery()
        {
            GetSuppliersByNameQuery actualQuery = null;

            var mockMediator = new Mock <IMediator>();

            mockMediator
            .Setup(m => m.Send(It.IsNotNull <IRequest <IEnumerable <ISupplier> > >(), It.IsAny <CancellationToken>()))
            .Callback <IRequest <IEnumerable <ISupplier> >, CancellationToken>((q, _) => actualQuery = (GetSuppliersByNameQuery)q)
            .ReturnsAsync(Array.Empty <ISupplier>());

            const string          expectedName            = "Supplier Name";
            const PublishedStatus expectedPublishedStatus = PublishedStatus.Draft;

            var controller  = new SuppliersController(mockMediator.Object);
            var searchQuery = new SupplierSearchQueryModel
            {
                Name = expectedName,
                SolutionPublicationStatus = expectedPublishedStatus,
            };

            await controller.GetList(searchQuery);

            var expectedQuery = new GetSuppliersByNameQuery(expectedName, expectedPublishedStatus, CatalogueItemType.Solution);

            actualQuery.Should().BeEquivalentTo(expectedQuery);
        }
Ejemplo n.º 2
0
        public async Task GetList_NoSuppliersFound_ReturnsExpectedResponse()
        {
            var expectedSuppliers = Array.Empty <GetSupplierModel>();

            var mockMediator = new Mock <IMediator>();

            mockMediator
            .Setup(m => m.Send(It.IsNotNull <IRequest <IEnumerable <ISupplier> > >(), It.IsAny <CancellationToken>()))
            .ReturnsAsync(Array.Empty <ISupplier>());

            var controller = new SuppliersController(mockMediator.Object);

            var response = await controller.GetList(new SupplierSearchQueryModel());

            response.Should().BeEquivalentTo(
                new ActionResult <IEnumerable <GetSupplierModel> >(new OkObjectResult(expectedSuppliers)));
        }
Ejemplo n.º 3
0
        public async Task GetList_SuppliersFound_ReturnsExpectedResponse()
        {
            var supplier1 = MockSupplier("1", "Uncle Bob's Miracle Cures");
            var supplier2 = MockSupplier("2", "Uncle Bob's Magic Mead");

            var expectedSuppliers = new[]
            {
                new GetSupplierModel(supplier1),
                new GetSupplierModel(supplier2),
            };

            var mockMediator = new Mock <IMediator>();

            mockMediator
            .Setup(m => m.Send(It.IsNotNull <IRequest <IEnumerable <ISupplier> > >(), It.IsAny <CancellationToken>()))
            .ReturnsAsync(new[] { supplier1, supplier2 });

            var controller = new SuppliersController(mockMediator.Object);

            var response = await controller.GetList(new SupplierSearchQueryModel());

            response.Should().BeEquivalentTo(
                new ActionResult <IEnumerable <GetSupplierModel> >(new OkObjectResult(expectedSuppliers)));
        }