コード例 #1
0
        public async void TestDelete()
        {
            var builder = new WebHostBuilder()
                          .UseEnvironment("Production")
                          .UseStartup <TestStartup>();
            TestServer testServer = new TestServer(builder);

            var client = new ApiClient(testServer.CreateClient());

            var createModel = new ApiVenueRequestModel();

            createModel.SetProperties("B", "B", 1, "B", "B", "B", "B", 1, "B");
            CreateResponse <ApiVenueResponseModel> createResult = await client.VenueCreateAsync(createModel);

            createResult.Success.Should().BeTrue();

            ApiVenueResponseModel getResponse = await client.VenueGetAsync(2);

            getResponse.Should().NotBeNull();

            ActionResponse deleteResult = await client.VenueDeleteAsync(2);

            deleteResult.Success.Should().BeTrue();

            ApiVenueResponseModel verifyResponse = await client.VenueGetAsync(2);

            verifyResponse.Should().BeNull();
        }
コード例 #2
0
        private async Task <ApiVenueResponseModel> CreateRecord()
        {
            var model = new ApiVenueRequestModel();

            model.SetProperties("B", "B", 1, "B", "B", "B", "B", 1, "B");
            CreateResponse <ApiVenueResponseModel> result = await this.Client.VenueCreateAsync(model);

            result.Success.Should().BeTrue();
            return(result.Record);
        }
コード例 #3
0
 public async Task <ValidationResult> ValidateUpdateAsync(int id, ApiVenueRequestModel model)
 {
     this.Address1Rules();
     this.Address2Rules();
     this.AdminIdRules();
     this.EmailRules();
     this.FacebookRules();
     this.NameRules();
     this.PhoneRules();
     this.ProvinceIdRules();
     this.WebsiteRules();
     return(await this.ValidateAsync(model, id));
 }
コード例 #4
0
        public virtual async Task <IActionResult> Create([FromBody] ApiVenueRequestModel model)
        {
            CreateResponse <ApiVenueResponseModel> result = await this.VenueService.Create(model);

            if (result.Success)
            {
                return(this.Created($"{this.Settings.ExternalBaseUrl}/api/Venues/{result.Record.Id}", result));
            }
            else
            {
                return(this.StatusCode(StatusCodes.Status422UnprocessableEntity, result));
            }
        }
コード例 #5
0
        public virtual async Task <CreateResponse <ApiVenueResponseModel> > Create(
            ApiVenueRequestModel model)
        {
            CreateResponse <ApiVenueResponseModel> response = new CreateResponse <ApiVenueResponseModel>(await this.venueModelValidator.ValidateCreateAsync(model));

            if (response.Success)
            {
                var bo     = this.bolVenueMapper.MapModelToBO(default(int), model);
                var record = await this.venueRepository.Create(this.dalVenueMapper.MapBOToEF(bo));

                response.SetRecord(this.bolVenueMapper.MapBOToModel(this.dalVenueMapper.MapEFToBO(record)));
            }

            return(response);
        }
コード例 #6
0
        private async Task <ApiVenueRequestModel> PatchModel(int id, JsonPatchDocument <ApiVenueRequestModel> patch)
        {
            var record = await this.VenueService.Get(id);

            if (record == null)
            {
                return(null);
            }
            else
            {
                ApiVenueRequestModel request = this.VenueModelMapper.MapResponseToRequest(record);
                patch.ApplyTo(request);
                return(request);
            }
        }
コード例 #7
0
        public async void Create()
        {
            var mock  = new ServiceMockFacade <IVenueRepository>();
            var model = new ApiVenueRequestModel();

            mock.RepositoryMock.Setup(x => x.Create(It.IsAny <Venue>())).Returns(Task.FromResult(new Venue()));
            var service = new VenueService(mock.LoggerMock.Object,
                                           mock.RepositoryMock.Object,
                                           mock.ModelValidatorMockFactory.VenueModelValidatorMock.Object,
                                           mock.BOLMapperMockFactory.BOLVenueMapperMock,
                                           mock.DALMapperMockFactory.DALVenueMapperMock);

            CreateResponse <ApiVenueResponseModel> response = await service.Create(model);

            response.Should().NotBeNull();
            mock.ModelValidatorMockFactory.VenueModelValidatorMock.Verify(x => x.ValidateCreateAsync(It.IsAny <ApiVenueRequestModel>()));
            mock.RepositoryMock.Verify(x => x.Create(It.IsAny <Venue>()));
        }
コード例 #8
0
        public async void Delete()
        {
            var mock  = new ServiceMockFacade <IVenueRepository>();
            var model = new ApiVenueRequestModel();

            mock.RepositoryMock.Setup(x => x.Delete(It.IsAny <int>())).Returns(Task.CompletedTask);
            var service = new VenueService(mock.LoggerMock.Object,
                                           mock.RepositoryMock.Object,
                                           mock.ModelValidatorMockFactory.VenueModelValidatorMock.Object,
                                           mock.BOLMapperMockFactory.BOLVenueMapperMock,
                                           mock.DALMapperMockFactory.DALVenueMapperMock);

            ActionResponse response = await service.Delete(default(int));

            response.Should().NotBeNull();
            mock.RepositoryMock.Verify(x => x.Delete(It.IsAny <int>()));
            mock.ModelValidatorMockFactory.VenueModelValidatorMock.Verify(x => x.ValidateDeleteAsync(It.IsAny <int>()));
        }
コード例 #9
0
        public void MapModelToBO()
        {
            var mapper = new BOLVenueMapper();
            ApiVenueRequestModel model = new ApiVenueRequestModel();

            model.SetProperties("A", "A", 1, "A", "A", "A", "A", 1, "A");
            BOVenue response = mapper.MapModelToBO(1, model);

            response.Address1.Should().Be("A");
            response.Address2.Should().Be("A");
            response.AdminId.Should().Be(1);
            response.Email.Should().Be("A");
            response.Facebook.Should().Be("A");
            response.Name.Should().Be("A");
            response.Phone.Should().Be("A");
            response.ProvinceId.Should().Be(1);
            response.Website.Should().Be("A");
        }
コード例 #10
0
        public void MapResponseToRequest()
        {
            var mapper = new ApiVenueModelMapper();
            var model  = new ApiVenueResponseModel();

            model.SetProperties(1, "A", "A", 1, "A", "A", "A", "A", 1, "A");
            ApiVenueRequestModel response = mapper.MapResponseToRequest(model);

            response.Address1.Should().Be("A");
            response.Address2.Should().Be("A");
            response.AdminId.Should().Be(1);
            response.Email.Should().Be("A");
            response.Facebook.Should().Be("A");
            response.Name.Should().Be("A");
            response.Phone.Should().Be("A");
            response.ProvinceId.Should().Be(1);
            response.Website.Should().Be("A");
        }
コード例 #11
0
        public virtual BOVenue MapModelToBO(
            int id,
            ApiVenueRequestModel model
            )
        {
            BOVenue boVenue = new BOVenue();

            boVenue.SetProperties(
                id,
                model.Address1,
                model.Address2,
                model.AdminId,
                model.Email,
                model.Facebook,
                model.Name,
                model.Phone,
                model.ProvinceId,
                model.Website);
            return(boVenue);
        }
コード例 #12
0
        public virtual async Task <UpdateResponse <ApiVenueResponseModel> > Update(
            int id,
            ApiVenueRequestModel model)
        {
            var validationResult = await this.venueModelValidator.ValidateUpdateAsync(id, model);

            if (validationResult.IsValid)
            {
                var bo = this.bolVenueMapper.MapModelToBO(id, model);
                await this.venueRepository.Update(this.dalVenueMapper.MapBOToEF(bo));

                var record = await this.venueRepository.Get(id);

                return(new UpdateResponse <ApiVenueResponseModel>(this.bolVenueMapper.MapBOToModel(this.dalVenueMapper.MapEFToBO(record))));
            }
            else
            {
                return(new UpdateResponse <ApiVenueResponseModel>(validationResult));
            }
        }
コード例 #13
0
        public void CreatePatch()
        {
            var mapper = new ApiVenueModelMapper();
            var model  = new ApiVenueRequestModel();

            model.SetProperties("A", "A", 1, "A", "A", "A", "A", 1, "A");

            JsonPatchDocument <ApiVenueRequestModel> patch = mapper.CreatePatch(model);
            var response = new ApiVenueRequestModel();

            patch.ApplyTo(response);
            response.Address1.Should().Be("A");
            response.Address2.Should().Be("A");
            response.AdminId.Should().Be(1);
            response.Email.Should().Be("A");
            response.Facebook.Should().Be("A");
            response.Name.Should().Be("A");
            response.Phone.Should().Be("A");
            response.ProvinceId.Should().Be(1);
            response.Website.Should().Be("A");
        }
コード例 #14
0
        public virtual async Task <IActionResult> Update(int id, [FromBody] ApiVenueRequestModel model)
        {
            ApiVenueRequestModel request = await this.PatchModel(id, this.VenueModelMapper.CreatePatch(model));

            if (request == null)
            {
                return(this.StatusCode(StatusCodes.Status404NotFound));
            }
            else
            {
                UpdateResponse <ApiVenueResponseModel> result = await this.VenueService.Update(id, request);

                if (result.Success)
                {
                    return(this.Ok(result));
                }
                else
                {
                    return(this.StatusCode(StatusCodes.Status422UnprocessableEntity, result));
                }
            }
        }
コード例 #15
0
        public virtual async Task <IActionResult> Patch(int id, [FromBody] JsonPatchDocument <ApiVenueRequestModel> patch)
        {
            ApiVenueResponseModel record = await this.VenueService.Get(id);

            if (record == null)
            {
                return(this.StatusCode(StatusCodes.Status404NotFound));
            }
            else
            {
                ApiVenueRequestModel model = await this.PatchModel(id, patch);

                UpdateResponse <ApiVenueResponseModel> result = await this.VenueService.Update(id, model);

                if (result.Success)
                {
                    return(this.Ok(result));
                }
                else
                {
                    return(this.StatusCode(StatusCodes.Status422UnprocessableEntity, result));
                }
            }
        }
コード例 #16
0
        public virtual async Task <UpdateResponse <ApiVenueResponseModel> > VenueUpdateAsync(int id, ApiVenueRequestModel item)
        {
            HttpResponseMessage httpResponse = await this.client.PutAsJsonAsync($"api/Venues/{id}", item).ConfigureAwait(false);

            return(JsonConvert.DeserializeObject <UpdateResponse <ApiVenueResponseModel> >(httpResponse.Content.ContentToString()));
        }