示例#1
0
        public async Task GetByCode_ReturnsJsonResult_WithOneProductOfCorrectType()
        {
            var productTravel = TestProductDtoFactory.Travel();

            var client = factory.CreateClient();

            var response = await client.DoGetAsync <ProductDto>("/api/Products/" + productTravel.Code);

            Equal(productTravel.Code, response.Code);
            Equal(productTravel.Name, response.Name);
            Equal(productTravel.Description, response.Description);
        }
        public async Task GetByCode_ReturnsJsonResult_WithOneProductOfCorrectType()
        {
            var paramProductCode = TestProductDtoFactory.Travel().Code;

            var mockMediator = new Mock <IMediator>();

            mockMediator.Setup(x => x.Send(It.IsAny <FindProductByCodeQuery>(), It.IsAny <CancellationToken>())).ReturnsAsync(TestProductDtoFactory.Travel());

            var controller = new ProductsController(mockMediator.Object);

            var result = await controller.GetByCode(paramProductCode);

            var jsonResult = Assert.IsType <JsonResult>(result);
            var item       = Assert.IsType <ProductDto>(jsonResult.Value);

            Assert.Equal(paramProductCode, item.Code);
        }
        public async Task GetAll_ReturnsJsonResult_WithListofProducts()
        {
            var mockMediator = new Mock <IMediator>();

            mockMediator.Setup(x => x.Send(It.IsAny <FindAllProductsQuery>(), It.IsAny <CancellationToken>())).ReturnsAsync(new List <ProductDto> {
                TestProductDtoFactory.Travel()
            });

            var controller = new ProductsController(mockMediator.Object);

            var result = await controller.GetAll();

            var jsonResult = Assert.IsType <JsonResult>(result);
            var items      = Assert.IsType <List <ProductDto> >(jsonResult.Value);

            Assert.Single(items);
        }