Beispiel #1
0
        public async Task <IHttpActionResult> PutReview(Guid id, CreativeReviewViewModel model)
        {
            if (model == null)
            {
                return(BadRequest());
            }

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

            var creative = await _creativeService.GetCreative(id).ConfigureAwait(false);

            if (creative == null)
            {
                return(NotFound());
            }

            // check version
            var creativeVersion = creative.UtcModifiedDateTime.ToUnixTimeSeconds();

            if (creativeVersion != model.CreativeVersion)
            {
                ModelState.AddModelError(nameof(model.CreativeVersion), "Creative version is invalid.");
                return(BadRequest(ModelState));
            }

            var creativeReviewModifyOptions = _mapping.Map <CreativeReviewModifyOptions>(model, options => options.Items.Add("creativeUuid", id));

            try
            {
                await _creativeService.CreateOrUpdateCreativeReview(creativeReviewModifyOptions).ConfigureAwait(false);

                return(Ok());
            }
            catch (BrandscreenException ex)
            {
                ModelState.AddModelError("", ex.Message);
                return(BadRequest(ModelState));
            }
        }
Beispiel #2
0
        public async Task PutReview_ShouldReturnOk()
        {
            // Arrange
            var creativeUuid = Guid.NewGuid();
            var model        = new CreativeReviewViewModel
            {
                PartnerId       = 0,
                Status          = "Ready",
                CreativeVersion = 0
            };

            Mock.Mock <ICreativeService>().Setup(x => x.GetCreative(creativeUuid))
            .Returns(Task.FromResult(new Creative {
                UtcModifiedDateTime = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc)
            }));

            // Act
            var retVal = await Controller.PutReview(creativeUuid, model);

            // Assert
            Assert.That(retVal, Is.Not.Null);
            Assert.That(retVal, Is.TypeOf <OkResult>());
            Mock.Mock <ICreativeService>().Verify(x => x.CreateOrUpdateCreativeReview(It.Is <CreativeReviewModifyOptions>(options => options.CreativeUuid == creativeUuid)), Times.Once);
        }