Esempio n. 1
0
        public async Task PatchConversions_ShouldReturnOk()
        {
            // Arrange
            var id    = 1;
            var model = new SegmentConversionPatchViewModel
            {
                Name                    = "WJsHome",
                Url                     = "www.google.com",
                AttributionModel        = ConversionAttributionModelEnum.LastClick.ToString(),
                PostClickLifetime       = 1,
                PostClickLifetimePeriod = PeriodTypeEnum.PerDay.ToString(),
                AttributionCountingMode = ConversionAttributionCountingModeEnum.OncePerLifetime.ToString()
            };

            Mock.Mock <ISegmentService>().Setup(x => x.GetSegment(id))
            .Returns(Task.FromResult(new Segment()));

            // Act
            var retVal = await Controller.PatchConversions(id, model);

            // Assert
            Assert.That(retVal, Is.Not.Null);
            Assert.That(retVal, Is.TypeOf <OkResult>());
            Mock.Mock <ISegmentService>().Verify(x => x.UpdateSegment(It.IsAny <Segment>()), Times.Once);
        }
Esempio n. 2
0
        public async Task <IHttpActionResult> PatchConversions(int id, SegmentConversionPatchViewModel model)
        {
            if (model == null)
            {
                return(BadRequest());
            }

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

            var segment = await _segmentService.GetSegment(id).ConfigureAwait(false);

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

            _mapping.Map(model, segment);
            await _segmentService.UpdateSegment(segment).ConfigureAwait(false);

            return(Ok());
        }