Ejemplo n.º 1
0
        public async Task <IHttpActionResult> Put(PlacementPutViewModel model)
        {
            if (model == null)
            {
                return(BadRequest());
            }

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

            var strategy = await _strategyService.GetStrategy(model.StrategyUuid.GetValueOrDefault(Guid.Empty)).ConfigureAwait(false);

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

            var creative = await _creativeService.GetCreative(model.CreativeUuid.GetValueOrDefault(Guid.Empty)).ConfigureAwait(false);

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

            var placementModifyOptions = _mapping.Map <PlacementModifyOptions>(model);
            await _placementService.ModifyPlacement(placementModifyOptions).ConfigureAwait(false);

            return(Ok());
        }
        public async Task Put_ShouldReturnOk()
        {
            // Arrange
            var model = new PlacementPutViewModel
            {
                StrategyUuid = Guid.NewGuid(),
                CreativeUuid = Guid.NewGuid()
            };

            Mock.Mock <IStrategyService>().Setup(x => x.GetStrategy(model.StrategyUuid.Value))
            .Returns(Task.FromResult(new AdGroup()));
            Mock.Mock <ICreativeService>().Setup(x => x.GetCreative(model.CreativeUuid.Value))
            .Returns(Task.FromResult(new Creative {
                AdTagTemplate = new AdTagTemplate()
            }));

            // Act
            var retVal = await Controller.Put(model);

            // Assert
            Assert.That(retVal, Is.Not.Null);
            Assert.That(retVal, Is.TypeOf <OkResult>());
            Mock.Mock <IPlacementService>().Verify(x => x.ModifyPlacement(It.Is <PlacementModifyOptions>(options => options.StrategyUuid == model.StrategyUuid.Value && options.CreativeUuid == model.CreativeUuid.Value)), Times.Once);
        }