public async Task <IHttpActionResult> Patch(Guid id, StrategyPatchViewModel model)
        {
            if (model == null)
            {
                return(BadRequest());
            }

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

            var strategy = await _strategyService.GetStrategy(id).ConfigureAwait(false);

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

            var strategyUpdateOptions = _mapping.Map <StrategyUpdateOptions>(model, options => options.Items.Add(nameof(id), id));

            try
            {
                await _strategyService.UpdateStrategy(strategyUpdateOptions).ConfigureAwait(false);

                return(Ok());
            }
            catch (BrandscreenException ex)
            {
                ModelState.AddModelError("", ex.Message);
                return(BadRequest(ModelState));
            }
        }
示例#2
0
        public async Task Patch_ShouldReturnOk()
        {
            // Arrange
            var adGroupUuid = Guid.NewGuid();
            var model       = new StrategyPatchViewModel
            {
                StrategyName = "WJsHome"
            };
            var adGroup = new AdGroup {
                AdGroupUuid = adGroupUuid, AdGroupName = "My Strategy 1"
            };

            Mock.Mock <IStrategyService>().Setup(x => x.GetStrategy(It.IsAny <Guid>())).Returns(Task.FromResult(adGroup));

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

            // Assert
            Assert.That(retVal, Is.Not.Null);
            Assert.That(retVal, Is.TypeOf <OkResult>());
            Mock.Mock <IStrategyService>().Verify(x => x.UpdateStrategy(It.IsAny <StrategyUpdateOptions>()), Times.Once);
        }