예제 #1
0
        public async Task Patch_ShouldReturnOk()
        {
            // Arrange
            var creativeUuid = Guid.NewGuid();
            var model        = new CreativePatchViewModel {
                CreativeName = "WJsHome"
            };

            Mock.Mock <ICreativeService>().Setup(x => x.GetCreative(creativeUuid))
            .Returns(Task.FromResult(new Creative()));

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

            // Assert
            Assert.That(retVal, Is.Not.Null);
            Assert.That(retVal, Is.TypeOf <OkResult>());
            Mock.Mock <ICreativeService>().Verify(x => x.UpdateCreative(It.Is <CreativeUpdateOptions>(options => options.NewCreative.CreativeName == model.CreativeName)), Times.Once);
        }
예제 #2
0
        public async Task <IHttpActionResult> Patch(Guid id, CreativePatchViewModel model)
        {
            if (model == null)
            {
                return(BadRequest());
            }

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

            var creative = await _creativeService.GetCreative(id).ConfigureAwait(false);

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

            var creativeUpdateOptions = _mapping.Map <CreativeUpdateOptions>(model, options => options.Items.Add(nameof(id), id));
            await _creativeService.UpdateCreative(creativeUpdateOptions).ConfigureAwait(false);

            return(Ok());
        }