Esempio n. 1
0
        public async Task <IHttpActionResult> PostAdTag(CreativeAdTagCreateViewModel 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 adTagTemplate = await _adTagTemplateService.GetAdTagTemplate(model.AdTagTemplateId.GetValueOrDefault(0)).ConfigureAwait(false);

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

            var creativeSize = await _creativeSizeService.GetCreativeSize(model.CreativeSizeId.GetValueOrDefault(0)).ConfigureAwait(false);

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

            var creativeAdTagCreateOptions = _mapping.Map <CreativeAdTagCreateOptions>(model);

            try
            {
                var creative = await _creativeService.CreateCreative(creativeAdTagCreateOptions).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));
            }
        }
Esempio n. 2
0
        public async Task PostAdTag_ShouldReturnOk()
        {
            // Arrange
            var model = new CreativeAdTagCreateViewModel
            {
                BrandUuid       = Guid.NewGuid(),
                CreativeName    = "WJsHome",
                CreativeSizeId  = 1,
                AdTagTemplateId = 1
            };
            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 <IAdTagTemplateService>().Setup(x => x.GetAdTagTemplate(model.AdTagTemplateId.Value))
            .Returns(Task.FromResult(new AdTagTemplate {
                CreativeTypeId = 0
            }));
            Mock.Mock <ICreativeSizeService>().Setup(x => x.GetCreativeSize(model.CreativeSizeId.Value))
            .Returns(Task.FromResult(new CreativeSize()));
            Mock.Mock <ILanguageService>().Setup(x => x.GetLanguage(It.IsAny <string>()))
            .Returns(Task.FromResult(new Language()));
            Mock.Mock <ICreativeService>().Setup(x => x.CreateCreative(It.IsAny <CreativeAdTagCreateOptions>()))
            .Returns(Task.FromResult(creative));
            Mock.Mock <ICreativeService>().Setup(x => x.GetCreative(creative.CreativeUuid))
            .Returns(Task.FromResult(creative));

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

            // Assert
            Assert.That(retVal, Is.Not.Null);
            Assert.That(retVal, Is.TypeOf <CreatedAtRouteNegotiatedContentResult <CreativeViewModel> >());
        }