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(); }
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); }
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)); }
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)); } }
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); }
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); } }
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>())); }
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>())); }
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"); }
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"); }
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); }
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)); } }
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"); }
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)); } } }
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)); } } }
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())); }