Exemple #1
0
        public async void GetProduct_ActionExecutes_ReturnOkResultWithProduct()
        {
            _mockRepository.Setup(x => x.GetAll()).ReturnsAsync(products);

            var result = await _productApiController.GetProduct();

            var okResult       = Assert.IsType <OkObjectResult>(result);
            var returnProducts = Assert.IsAssignableFrom <IEnumerable <Product> >(okResult.Value);

            Assert.Equal <int>(2, returnProducts.ToList().Count);
        }
        public void GetProduct()
        {
            unitOfWork.Data = new MockData
            {
                Products = new List <Product>
                {
                    new Product
                    {
                        code = "code 1",
                        name = "prod 1"
                    },
                    new Product
                    {
                        code = "code2",
                        name = "prod 2"
                    },
                    new Product
                    {
                        code = "ccc",
                        name = "nnnn"
                    }
                }
            };

            var result = controller.GetProduct("code 1");

            Assert.IsNotInstanceOfType(result, typeof(BadRequestErrorMessageResult));
            Assert.IsNotNull(result.GetType().GetProperty("code"));

            result = controller.GetProduct("code%201");
            Assert.IsNotInstanceOfType(result, typeof(BadRequestErrorMessageResult));
            Assert.IsNotNull(result.GetType().GetProperty("code"));

            result = controller.GetProduct("xxx");
            Assert.IsInstanceOfType(result, typeof(BadRequestErrorMessageResult));
        }
Exemple #3
0
        public void GetProductThrowsWhenRepositoryReturnsNull()
        {
            //// Arrange
            Guid productKey = Guid.NewGuid();

            var MockProductService = new Mock <IProductService>();

            MockProductService.Setup(cs => cs.GetByKey(productKey)).Returns((ProductActual)null);

            MerchelloContext merchelloContext = GetMerchelloContext(MockProductService.Object);

            ProductApiController ctrl = new ProductApiController(merchelloContext, tempUmbracoContext);

            //// Act & Assert
            var ex = Assert.Throws <HttpResponseException>(() => ctrl.GetProduct(Guid.Empty));
        }
Exemple #4
0
        public void GetProductByKeyReturnsCorrectItemFromRepository()
        {
            //// Arrange
            Guid          productKey    = Guid.NewGuid();
            ProductActual productActual = MockProductDataMaker.MockProductComplete(productKey) as ProductActual;

            var MockProductService = new Mock <IProductService>();

            MockProductService.Setup(cs => cs.GetByKey(productKey)).Returns(productActual);

            MerchelloContext merchelloContext = GetMerchelloContext(MockProductService.Object);

            ProductApiController ctrl = new ProductApiController(merchelloContext, tempUmbracoContext);

            //// Act
            var result = ctrl.GetProduct(productKey);

            //// Assert
            Assert.AreEqual(productActual, result);
        }