示例#1
0
        public async Task <IHttpActionResult> Post(CreativeCreateViewModel 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 creativeCreateOptions = _mapping.Map <CreativeCreateOptions>(model);

            if (adTagTemplate.CreativeTypeId != (int)creativeCreateOptions.CreativeType)
            {
                return(BadRequest($"The specified template cannot apply to the creative type {creativeCreateOptions.CreativeType}."));
            }

            try
            {
                var creative = await _creativeService.CreateCreative(creativeCreateOptions).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));
            }
        }
示例#2
0
        public async Task Post_ShouldReturnOk()
        {
            // Arrange
            var model = new CreativeCreateViewModel
            {
                BrandUuid       = Guid.NewGuid(),
                CreativeName    = "WJsHome",
                AdTagTemplateId = 1
            };
            var creative = new Creative
            {
                CreativeUuid      = Guid.NewGuid(),
                CreativeName      = model.CreativeName,
                AdvertiserProduct = new AdvertiserProduct {
                    AdvertiserProductUuid = model.BrandUuid.Value
                },
                CreativeFile = new CreativeFile()
            };

            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 <ILanguageService>().Setup(x => x.GetLanguage(It.IsAny <string>()))
            .Returns(Task.FromResult(new Language()));
            Mock.Mock <ICreativeService>().Setup(x => x.CreateCreative(It.IsAny <CreativeCreateOptions>()))
            .Returns(Task.FromResult(creative));
            Mock.Mock <ICreativeService>().Setup(x => x.GetCreative(creative.CreativeUuid))
            .Returns(Task.FromResult(creative));
            Mock.Mock <IAmazonSettings>().SetupGet(x => x.BucketCreativeUrl)
            .Returns("https://creatives.brandscreen.com");

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

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