Exemplo n.º 1
0
        public async Task <IHttpActionResult> Patch(Guid id, BrandPatchViewModel model)
        {
            if (model == null)
            {
                return(BadRequest());
            }

            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var brand = await _brandService.GetBrand(id).ConfigureAwait(false);

            if (brand == null)
            {
                return(NotFound());
            }

            if (model.ProductCategoryId.HasValue)
            {
                var productCategory = await _productCategoryService.GetProductCategory(model.ProductCategoryId.Value).ConfigureAwait(false);

                if (productCategory == null)
                {
                    return(BadRequest("The specified product category was not found."));
                }
            }

            _mapping.Map(model, brand);
            await _brandService.UpdateBrand(brand).ConfigureAwait(false);

            return(Ok());
        }
Exemplo n.º 2
0
        public async Task Patch_ShouldReturnOk()
        {
            // Arrange
            var brandUuid = Guid.NewGuid();
            var model     = new BrandPatchViewModel {
                BrandName = "WJsHome"
            };

            Mock.Mock <IBrandService>().Setup(x => x.GetBrand(brandUuid))
            .Returns(Task.FromResult(new AdvertiserProduct()));

            // Act
            var retVal = await Controller.Patch(brandUuid, model);

            // Assert
            Assert.That(retVal, Is.Not.Null);
            Assert.That(retVal, Is.TypeOf <OkResult>());
            Mock.Mock <IBrandService>().Verify(x => x.UpdateBrand(It.Is <AdvertiserProduct>(brand => brand.ProductName == model.BrandName)), Times.Once);
        }