Esempio n. 1
0
        public async Task <IHttpActionResult> PostDooh(CreativeDoohCreateViewModel 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 creativeSize = await _creativeSizeService.GetCreativeSize(model.CreativeSizeId.GetValueOrDefault(0)).ConfigureAwait(false);

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

            var creativeDoohCreateOptions = _mapping.Map <CreativeDoohCreateOptions>(model);

            try
            {
                var creative = await _creativeService.CreateCreative(creativeDoohCreateOptions).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 PostDooh_ShouldReturnOk()
        {
            // Arrange
            var model = new CreativeDoohCreateViewModel
            {
                BrandUuid      = Guid.NewGuid(),
                CreativeName   = "WJsHome",
                CreativeSizeId = 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 <ICreativeService>().Setup(x => x.CreateCreative(It.IsAny <CreativeDoohCreateOptions>()))
            .Returns(Task.FromResult(creative));
            Mock.Mock <ICreativeService>().Setup(x => x.GetCreative(creative.CreativeUuid))
            .Returns(Task.FromResult(creative));
            Mock.Mock <ICreativeSizeService>().Setup(x => x.GetCreativeSize(model.CreativeSizeId.Value))
            .Returns(Task.FromResult(new CreativeSize()));
            Mock.Mock <IAmazonSettings>().SetupGet(x => x.BucketCreativeUrl)
            .Returns("https://creatives.brandscreen.com");

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

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