Esempio n. 1
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);
        }
Esempio n. 2
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));
        }