public async Task <ValidationResult> ValidateUpdateAsync(int id, ApiDestinationRequestModel model) { this.CountryIdRules(); this.NameRules(); this.OrderRules(); 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 ApiDestinationRequestModel(); createModel.SetProperties(1, "B", 2); CreateResponse <ApiDestinationResponseModel> createResult = await client.DestinationCreateAsync(createModel); createResult.Success.Should().BeTrue(); ApiDestinationResponseModel getResponse = await client.DestinationGetAsync(2); getResponse.Should().NotBeNull(); ActionResponse deleteResult = await client.DestinationDeleteAsync(2); deleteResult.Success.Should().BeTrue(); ApiDestinationResponseModel verifyResponse = await client.DestinationGetAsync(2); verifyResponse.Should().BeNull(); }
private async Task <ApiDestinationResponseModel> CreateRecord(ApiClient client) { var model = new ApiDestinationRequestModel(); model.SetProperties(1, "B", 2); CreateResponse <ApiDestinationResponseModel> result = await client.DestinationCreateAsync(model); result.Success.Should().BeTrue(); return(result.Record); }
public void MapModelToBO() { var mapper = new BOLDestinationMapper(); ApiDestinationRequestModel model = new ApiDestinationRequestModel(); model.SetProperties(1, "A", 1); BODestination response = mapper.MapModelToBO(1, model); response.CountryId.Should().Be(1); response.Name.Should().Be("A"); response.Order.Should().Be(1); }
public void MapResponseToRequest() { var mapper = new ApiDestinationModelMapper(); var model = new ApiDestinationResponseModel(); model.SetProperties(1, 1, "A", 1); ApiDestinationRequestModel response = mapper.MapResponseToRequest(model); response.CountryId.Should().Be(1); response.Name.Should().Be("A"); response.Order.Should().Be(1); }
public virtual async Task <IActionResult> Create([FromBody] ApiDestinationRequestModel model) { CreateResponse <ApiDestinationResponseModel> result = await this.DestinationService.Create(model); if (result.Success) { return(this.Created($"{this.Settings.ExternalBaseUrl}/api/Destinations/{result.Record.Id}", result)); } else { return(this.StatusCode(StatusCodes.Status422UnprocessableEntity, result)); } }
public virtual BODestination MapModelToBO( int id, ApiDestinationRequestModel model ) { BODestination boDestination = new BODestination(); boDestination.SetProperties( id, model.CountryId, model.Name, model.Order); return(boDestination); }
private async Task <ApiDestinationRequestModel> PatchModel(int id, JsonPatchDocument <ApiDestinationRequestModel> patch) { var record = await this.DestinationService.Get(id); if (record == null) { return(null); } else { ApiDestinationRequestModel request = this.DestinationModelMapper.MapResponseToRequest(record); patch.ApplyTo(request); return(request); } }
public void CreatePatch() { var mapper = new ApiDestinationModelMapper(); var model = new ApiDestinationRequestModel(); model.SetProperties(1, "A", 1); JsonPatchDocument <ApiDestinationRequestModel> patch = mapper.CreatePatch(model); var response = new ApiDestinationRequestModel(); patch.ApplyTo(response); response.CountryId.Should().Be(1); response.Name.Should().Be("A"); response.Order.Should().Be(1); }
public virtual async Task <CreateResponse <ApiDestinationResponseModel> > Create( ApiDestinationRequestModel model) { CreateResponse <ApiDestinationResponseModel> response = new CreateResponse <ApiDestinationResponseModel>(await this.destinationModelValidator.ValidateCreateAsync(model)); if (response.Success) { var bo = this.bolDestinationMapper.MapModelToBO(default(int), model); var record = await this.destinationRepository.Create(this.dalDestinationMapper.MapBOToEF(bo)); response.SetRecord(this.bolDestinationMapper.MapBOToModel(this.dalDestinationMapper.MapEFToBO(record))); } return(response); }
public async void Create() { var mock = new ServiceMockFacade <IDestinationRepository>(); var model = new ApiDestinationRequestModel(); mock.RepositoryMock.Setup(x => x.Create(It.IsAny <Destination>())).Returns(Task.FromResult(new Destination())); var service = new DestinationService(mock.LoggerMock.Object, mock.RepositoryMock.Object, mock.ModelValidatorMockFactory.DestinationModelValidatorMock.Object, mock.BOLMapperMockFactory.BOLDestinationMapperMock, mock.DALMapperMockFactory.DALDestinationMapperMock); CreateResponse <ApiDestinationResponseModel> response = await service.Create(model); response.Should().NotBeNull(); mock.ModelValidatorMockFactory.DestinationModelValidatorMock.Verify(x => x.ValidateCreateAsync(It.IsAny <ApiDestinationRequestModel>())); mock.RepositoryMock.Verify(x => x.Create(It.IsAny <Destination>())); }
public async void Delete() { var mock = new ServiceMockFacade <IDestinationRepository>(); var model = new ApiDestinationRequestModel(); mock.RepositoryMock.Setup(x => x.Delete(It.IsAny <int>())).Returns(Task.CompletedTask); var service = new DestinationService(mock.LoggerMock.Object, mock.RepositoryMock.Object, mock.ModelValidatorMockFactory.DestinationModelValidatorMock.Object, mock.BOLMapperMockFactory.BOLDestinationMapperMock, mock.DALMapperMockFactory.DALDestinationMapperMock); ActionResponse response = await service.Delete(default(int)); response.Should().NotBeNull(); mock.RepositoryMock.Verify(x => x.Delete(It.IsAny <int>())); mock.ModelValidatorMockFactory.DestinationModelValidatorMock.Verify(x => x.ValidateDeleteAsync(It.IsAny <int>())); }
public virtual async Task <UpdateResponse <ApiDestinationResponseModel> > Update( int id, ApiDestinationRequestModel model) { var validationResult = await this.destinationModelValidator.ValidateUpdateAsync(id, model); if (validationResult.IsValid) { var bo = this.bolDestinationMapper.MapModelToBO(id, model); await this.destinationRepository.Update(this.dalDestinationMapper.MapBOToEF(bo)); var record = await this.destinationRepository.Get(id); return(new UpdateResponse <ApiDestinationResponseModel>(this.bolDestinationMapper.MapBOToModel(this.dalDestinationMapper.MapEFToBO(record)))); } else { return(new UpdateResponse <ApiDestinationResponseModel>(validationResult)); } }
public virtual async Task <IActionResult> Update(int id, [FromBody] ApiDestinationRequestModel model) { ApiDestinationRequestModel request = await this.PatchModel(id, this.DestinationModelMapper.CreatePatch(model)); if (request == null) { return(this.StatusCode(StatusCodes.Status404NotFound)); } else { UpdateResponse <ApiDestinationResponseModel> result = await this.DestinationService.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 <ApiDestinationRequestModel> patch) { ApiDestinationResponseModel record = await this.DestinationService.Get(id); if (record == null) { return(this.StatusCode(StatusCodes.Status404NotFound)); } else { ApiDestinationRequestModel model = await this.PatchModel(id, patch); UpdateResponse <ApiDestinationResponseModel> result = await this.DestinationService.Update(id, model); if (result.Success) { return(this.Ok(result)); } else { return(this.StatusCode(StatusCodes.Status422UnprocessableEntity, result)); } } }