Exemple #1
0
        public async Task PostHtml5_ShouldReturnOk()
        {
            // Arrange
            var model = new CreativeHtml5CreateViewModel
            {
                BrandUuid    = Guid.NewGuid(),
                CreativeName = "WJsHome",
                LanguageCode = "en",
            };
            var creative = new Creative
            {
                CreativeUuid      = Guid.NewGuid(),
                CreativeName      = model.CreativeName,
                AdvertiserProduct = new AdvertiserProduct {
                    AdvertiserProductUuid = model.BrandUuid.Value
                },
            };

            Mock.Mock <IBrandService>().Setup(x => x.GetBrand(model.BrandUuid.Value))
            .Returns(Task.FromResult(creative.AdvertiserProduct));
            Mock.Mock <ILanguageService>().Setup(x => x.GetLanguage(It.IsAny <string>()))
            .Returns(Task.FromResult(new Language()));
            Mock.Mock <ICreativeService>().Setup(x => x.CreateCreative(It.IsAny <CreativeHtml5CreateOptions>()))
            .Returns(Task.FromResult(creative));
            Mock.Mock <ICreativeService>().Setup(x => x.GetCreative(creative.CreativeUuid))
            .Returns(Task.FromResult(creative));

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

            // Assert
            Assert.That(retVal, Is.Not.Null);
            Assert.That(retVal, Is.TypeOf <CreatedAtRouteNegotiatedContentResult <CreativeViewModel> >());
        }
Exemple #2
0
        public async Task <IHttpActionResult> PostHtml5(CreativeHtml5CreateViewModel model)
        {
            if (model == null)
            {
                return(BadRequest());
            }

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

            var brand = await _brandService.GetBrand(model.BrandUuid.GetValueOrDefault(Guid.Empty)).ConfigureAwait(false);

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

            var creativeHtml5CreateOptions = _mapping.Map <CreativeHtml5CreateOptions>(model);

            try
            {
                var creative = await _creativeService.CreateCreative(creativeHtml5CreateOptions).ConfigureAwait(false);

                creative = await _creativeService.GetCreative(creative.CreativeUuid).ConfigureAwait(false); // reload

                var creativeViewModel = _mapping.Map <CreativeViewModel>(creative);
                return(CreatedAtRoute("Creatives.GetById", new { Id = creativeViewModel.CreativeUuid }, creativeViewModel));
            }
            catch (BrandscreenException ex)
            {
                ModelState.AddModelError("", ex.Message);
                return(BadRequest(ModelState));
            }
        }