示例#1
0
        public async Task <IHttpActionResult> PostDoohPanelLocation(DoohPanelLocationCreateViewModel model)
        {
            if (model == null)
            {
                return(BadRequest());
            }

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

            var doohPanel = await _doohService.GetDoohPanel(model.DoohPanelId.GetValueOrDefault(0)).ConfigureAwait(false);

            if (doohPanel == null)
            {
                return(BadRequest("The specified dooh panel was not found."));
            }

            var doohLocation = await _doohService.GetDoohLocation(model.DoohLocationId.GetValueOrDefault(0)).ConfigureAwait(false);

            if (doohLocation == null)
            {
                return(BadRequest("The specified dooh location was not found."));
            }

            var partner = await _partnerService.GetPartner(model.PartnerId.GetValueOrDefault(0)).ConfigureAwait(false);

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

            var doohPanelLocation = _mapping.Map <DoohPanelLocation>(model);
            await _doohService.CreateDoohPanelLocation(doohPanelLocation).ConfigureAwait(false);                                      // create

            doohPanelLocation = await _doohService.GetDoohPanelLocation(doohPanelLocation.DoohPanelLocationId).ConfigureAwait(false); // reload

            var doohPanelLocationViewModel = _mapping.Map <DoohPanelLocationViewModel>(doohPanelLocation);

            return(CreatedAtRoute("Dooh.PanelLocations.GetById", new { Id = doohPanelLocationViewModel.DoohPanelLocationId }, doohPanelLocationViewModel));
        }
示例#2
0
        public async Task PostDoohPanelLocation_ShouldReturnOk()
        {
            // Arrange
            var model = new DoohPanelLocationCreateViewModel {
                DoohPanelId = 1, DoohLocationId = 1, PartnerId = 1, PanelUrl = "www.wjshome.com"
            };

            var mockedDoohService = Mock.Mock <IDoohService>();

            mockedDoohService.Setup(x => x.GetDoohPanel(model.DoohPanelId.Value)).ReturnsAsync(new DoohPanel());
            mockedDoohService.Setup(x => x.GetDoohLocation(model.DoohLocationId.Value)).ReturnsAsync(new DoohLocation());
            mockedDoohService.Setup(x => x.GetDoohPanelLocation(It.IsAny <int>())).ReturnsAsync(new DoohPanelLocation());

            Mock.Mock <IPartnerService>().Setup(x => x.GetPartner(model.PartnerId.Value)).ReturnsAsync(new Partner());

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

            // Assert
            Assert.That(retVal, Is.Not.Null);
            Assert.That(retVal, Is.TypeOf <CreatedAtRouteNegotiatedContentResult <DoohPanelLocationViewModel> >());
            mockedDoohService.Verify(x => x.CreateDoohPanelLocation(It.Is <DoohPanelLocation>(doohPanelLocation => doohPanelLocation.PanelUrl == model.PanelUrl)), Times.Once);
        }