public async Task <ValidationResult> ValidateUpdateAsync(int id, ApiSpaceRequestModel model) { this.DescriptionRules(); this.NameRules(); this.StudioIdRules(); return(await this.ValidateAsync(model, id)); }
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 ApiSpaceRequestModel(); createModel.SetProperties("B", "B"); CreateResponse <ApiSpaceResponseModel> createResult = await client.SpaceCreateAsync(createModel); createResult.Success.Should().BeTrue(); ApiSpaceResponseModel getResponse = await client.SpaceGetAsync(2); getResponse.Should().NotBeNull(); ActionResponse deleteResult = await client.SpaceDeleteAsync(2); deleteResult.Success.Should().BeTrue(); ApiSpaceResponseModel verifyResponse = await client.SpaceGetAsync(2); verifyResponse.Should().BeNull(); }
private async Task <ApiSpaceResponseModel> CreateRecord() { var model = new ApiSpaceRequestModel(); model.SetProperties("B", "B", 1); CreateResponse <ApiSpaceResponseModel> result = await this.Client.SpaceCreateAsync(model); result.Success.Should().BeTrue(); return(result.Record); }
public void MapResponseToRequest() { var mapper = new ApiSpaceModelMapper(); var model = new ApiSpaceResponseModel(); model.SetProperties(1, "A", "A"); ApiSpaceRequestModel response = mapper.MapResponseToRequest(model); response.Description.Should().Be("A"); response.Name.Should().Be("A"); }
public void MapModelToBO() { var mapper = new BOLSpaceMapper(); ApiSpaceRequestModel model = new ApiSpaceRequestModel(); model.SetProperties("A", "A"); BOSpace response = mapper.MapModelToBO(1, model); response.Description.Should().Be("A"); response.Name.Should().Be("A"); }
public virtual async Task <IActionResult> Create([FromBody] ApiSpaceRequestModel model) { CreateResponse <ApiSpaceResponseModel> result = await this.SpaceService.Create(model); if (result.Success) { return(this.Created($"{this.Settings.ExternalBaseUrl}/api/Spaces/{result.Record.Id}", result)); } else { return(this.StatusCode(StatusCodes.Status422UnprocessableEntity, result)); } }
public virtual BOSpace MapModelToBO( int id, ApiSpaceRequestModel model ) { BOSpace boSpace = new BOSpace(); boSpace.SetProperties( id, model.Description, model.Name); return(boSpace); }
public void CreatePatch() { var mapper = new ApiSpaceModelMapper(); var model = new ApiSpaceRequestModel(); model.SetProperties("A", "A"); JsonPatchDocument <ApiSpaceRequestModel> patch = mapper.CreatePatch(model); var response = new ApiSpaceRequestModel(); patch.ApplyTo(response); response.Description.Should().Be("A"); response.Name.Should().Be("A"); }
public virtual async Task <CreateResponse <ApiSpaceResponseModel> > Create( ApiSpaceRequestModel model) { CreateResponse <ApiSpaceResponseModel> response = new CreateResponse <ApiSpaceResponseModel>(await this.spaceModelValidator.ValidateCreateAsync(model)); if (response.Success) { var bo = this.bolSpaceMapper.MapModelToBO(default(int), model); var record = await this.spaceRepository.Create(this.dalSpaceMapper.MapBOToEF(bo)); response.SetRecord(this.bolSpaceMapper.MapBOToModel(this.dalSpaceMapper.MapEFToBO(record))); } return(response); }
private async Task <ApiSpaceRequestModel> PatchModel(int id, JsonPatchDocument <ApiSpaceRequestModel> patch) { var record = await this.SpaceService.Get(id); if (record == null) { return(null); } else { ApiSpaceRequestModel request = this.SpaceModelMapper.MapResponseToRequest(record); patch.ApplyTo(request); return(request); } }
public async void Create() { var mock = new ServiceMockFacade <ISpaceRepository>(); var model = new ApiSpaceRequestModel(); mock.RepositoryMock.Setup(x => x.Create(It.IsAny <Space>())).Returns(Task.FromResult(new Space())); var service = new SpaceService(mock.LoggerMock.Object, mock.RepositoryMock.Object, mock.ModelValidatorMockFactory.SpaceModelValidatorMock.Object, mock.BOLMapperMockFactory.BOLSpaceMapperMock, mock.DALMapperMockFactory.DALSpaceMapperMock); CreateResponse <ApiSpaceResponseModel> response = await service.Create(model); response.Should().NotBeNull(); mock.ModelValidatorMockFactory.SpaceModelValidatorMock.Verify(x => x.ValidateCreateAsync(It.IsAny <ApiSpaceRequestModel>())); mock.RepositoryMock.Verify(x => x.Create(It.IsAny <Space>())); }
public async void Delete() { var mock = new ServiceMockFacade <ISpaceRepository>(); var model = new ApiSpaceRequestModel(); mock.RepositoryMock.Setup(x => x.Delete(It.IsAny <int>())).Returns(Task.CompletedTask); var service = new SpaceService(mock.LoggerMock.Object, mock.RepositoryMock.Object, mock.ModelValidatorMockFactory.SpaceModelValidatorMock.Object, mock.BOLMapperMockFactory.BOLSpaceMapperMock, mock.DALMapperMockFactory.DALSpaceMapperMock); ActionResponse response = await service.Delete(default(int)); response.Should().NotBeNull(); mock.RepositoryMock.Verify(x => x.Delete(It.IsAny <int>())); mock.ModelValidatorMockFactory.SpaceModelValidatorMock.Verify(x => x.ValidateDeleteAsync(It.IsAny <int>())); }
public virtual async Task <UpdateResponse <ApiSpaceResponseModel> > Update( int id, ApiSpaceRequestModel model) { var validationResult = await this.spaceModelValidator.ValidateUpdateAsync(id, model); if (validationResult.IsValid) { var bo = this.bolSpaceMapper.MapModelToBO(id, model); await this.spaceRepository.Update(this.dalSpaceMapper.MapBOToEF(bo)); var record = await this.spaceRepository.Get(id); return(new UpdateResponse <ApiSpaceResponseModel>(this.bolSpaceMapper.MapBOToModel(this.dalSpaceMapper.MapEFToBO(record)))); } else { return(new UpdateResponse <ApiSpaceResponseModel>(validationResult)); } }
public virtual async Task <IActionResult> Update(int id, [FromBody] ApiSpaceRequestModel model) { ApiSpaceRequestModel request = await this.PatchModel(id, this.SpaceModelMapper.CreatePatch(model)); if (request == null) { return(this.StatusCode(StatusCodes.Status404NotFound)); } else { UpdateResponse <ApiSpaceResponseModel> result = await this.SpaceService.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 <ApiSpaceRequestModel> patch) { ApiSpaceResponseModel record = await this.SpaceService.Get(id); if (record == null) { return(this.StatusCode(StatusCodes.Status404NotFound)); } else { ApiSpaceRequestModel model = await this.PatchModel(id, patch); UpdateResponse <ApiSpaceResponseModel> result = await this.SpaceService.Update(id, model); if (result.Success) { return(this.Ok(result)); } else { return(this.StatusCode(StatusCodes.Status422UnprocessableEntity, result)); } } }
public async Task <ValidationResult> ValidateCreateAsync(ApiSpaceRequestModel model) { this.DescriptionRules(); this.NameRules(); return(await this.ValidateAsync(model)); }
public virtual async Task <UpdateResponse <ApiSpaceResponseModel> > SpaceUpdateAsync(int id, ApiSpaceRequestModel item) { HttpResponseMessage httpResponse = await this.client.PutAsJsonAsync($"api/Spaces/{id}", item).ConfigureAwait(false); return(JsonConvert.DeserializeObject <UpdateResponse <ApiSpaceResponseModel> >(httpResponse.Content.ContentToString())); }