Пример #1
0
        public void DeleteProductCallsRepositoryRemove()
        {
            //// Arrange
            Guid removedKey = Guid.Empty;

            Guid          productKey    = new Guid();
            ProductActual productActual = CreateFakeProduct(productKey, 20.0M);

            var MockProductService = new Mock <IProductService>();

            MockProductService.Setup(cs => cs.Delete(productActual, It.IsAny <bool>())).Callback <IProductActual, bool>((p, b) => removedKey = p.Key);
            MockProductService.Setup(cs => cs.GetByKey(productKey)).Returns(productActual);

            MerchelloContext merchelloContext = GetMerchelloContext(MockProductService.Object);

            ProductApiController ctrl = new ProductApiController(merchelloContext, tempUmbracoContext);

            ctrl.Request = new HttpRequestMessage();
            ctrl.Request.Properties.Add(HttpPropertyKeys.HttpConfigurationKey, new HttpConfiguration());

            //// Act
            HttpResponseMessage response = ctrl.Delete(productKey);

            //// Assert
            Assert.AreEqual(System.Net.HttpStatusCode.OK, response.StatusCode);

            Assert.AreEqual(productKey, removedKey);
        }