private async Task <ApiSchemaVersionsResponseModel> CreateRecord() { var model = new ApiSchemaVersionsRequestModel(); model.SetProperties(DateTime.Parse("1/1/1988 12:00:00 AM"), "B"); CreateResponse <ApiSchemaVersionsResponseModel> result = await this.Client.SchemaVersionsCreateAsync(model); result.Success.Should().BeTrue(); return(result.Record); }
public void MapResponseToRequest() { var mapper = new ApiSchemaVersionsModelMapper(); var model = new ApiSchemaVersionsResponseModel(); model.SetProperties(1, DateTime.Parse("1/1/1987 12:00:00 AM"), "A"); ApiSchemaVersionsRequestModel response = mapper.MapResponseToRequest(model); response.Applied.Should().Be(DateTime.Parse("1/1/1987 12:00:00 AM")); response.ScriptName.Should().Be("A"); }
public void MapModelToBO() { var mapper = new BOLSchemaVersionsMapper(); ApiSchemaVersionsRequestModel model = new ApiSchemaVersionsRequestModel(); model.SetProperties(DateTime.Parse("1/1/1987 12:00:00 AM"), "A"); BOSchemaVersions response = mapper.MapModelToBO(1, model); response.Applied.Should().Be(DateTime.Parse("1/1/1987 12:00:00 AM")); response.ScriptName.Should().Be("A"); }
public virtual async Task <IActionResult> Create([FromBody] ApiSchemaVersionsRequestModel model) { CreateResponse <ApiSchemaVersionsResponseModel> result = await this.SchemaVersionsService.Create(model); if (result.Success) { return(this.Created($"{this.Settings.ExternalBaseUrl}/api/SchemaVersions/{result.Record.Id}", result)); } else { return(this.StatusCode(StatusCodes.Status422UnprocessableEntity, result)); } }
public virtual BOSchemaVersions MapModelToBO( int id, ApiSchemaVersionsRequestModel model ) { BOSchemaVersions boSchemaVersions = new BOSchemaVersions(); boSchemaVersions.SetProperties( id, model.Applied, model.ScriptName); return(boSchemaVersions); }
public void CreatePatch() { var mapper = new ApiSchemaVersionsModelMapper(); var model = new ApiSchemaVersionsRequestModel(); model.SetProperties(DateTime.Parse("1/1/1987 12:00:00 AM"), "A"); JsonPatchDocument <ApiSchemaVersionsRequestModel> patch = mapper.CreatePatch(model); var response = new ApiSchemaVersionsRequestModel(); patch.ApplyTo(response); response.Applied.Should().Be(DateTime.Parse("1/1/1987 12:00:00 AM")); response.ScriptName.Should().Be("A"); }
private async Task <ApiSchemaVersionsRequestModel> PatchModel(int id, JsonPatchDocument <ApiSchemaVersionsRequestModel> patch) { var record = await this.SchemaVersionsService.Get(id); if (record == null) { return(null); } else { ApiSchemaVersionsRequestModel request = this.SchemaVersionsModelMapper.MapResponseToRequest(record); patch.ApplyTo(request); return(request); } }
public virtual async Task <CreateResponse <ApiSchemaVersionsResponseModel> > Create( ApiSchemaVersionsRequestModel model) { CreateResponse <ApiSchemaVersionsResponseModel> response = new CreateResponse <ApiSchemaVersionsResponseModel>(await this.schemaVersionsModelValidator.ValidateCreateAsync(model)); if (response.Success) { var bo = this.bolSchemaVersionsMapper.MapModelToBO(default(int), model); var record = await this.schemaVersionsRepository.Create(this.dalSchemaVersionsMapper.MapBOToEF(bo)); response.SetRecord(this.bolSchemaVersionsMapper.MapBOToModel(this.dalSchemaVersionsMapper.MapEFToBO(record))); } return(response); }
public async void Create() { var mock = new ServiceMockFacade <ISchemaVersionsRepository>(); var model = new ApiSchemaVersionsRequestModel(); mock.RepositoryMock.Setup(x => x.Create(It.IsAny <SchemaVersions>())).Returns(Task.FromResult(new SchemaVersions())); var service = new SchemaVersionsService(mock.LoggerMock.Object, mock.RepositoryMock.Object, mock.ModelValidatorMockFactory.SchemaVersionsModelValidatorMock.Object, mock.BOLMapperMockFactory.BOLSchemaVersionsMapperMock, mock.DALMapperMockFactory.DALSchemaVersionsMapperMock); CreateResponse <ApiSchemaVersionsResponseModel> response = await service.Create(model); response.Should().NotBeNull(); mock.ModelValidatorMockFactory.SchemaVersionsModelValidatorMock.Verify(x => x.ValidateCreateAsync(It.IsAny <ApiSchemaVersionsRequestModel>())); mock.RepositoryMock.Verify(x => x.Create(It.IsAny <SchemaVersions>())); }
public async void Delete() { var mock = new ServiceMockFacade <ISchemaVersionsRepository>(); var model = new ApiSchemaVersionsRequestModel(); mock.RepositoryMock.Setup(x => x.Delete(It.IsAny <int>())).Returns(Task.CompletedTask); var service = new SchemaVersionsService(mock.LoggerMock.Object, mock.RepositoryMock.Object, mock.ModelValidatorMockFactory.SchemaVersionsModelValidatorMock.Object, mock.BOLMapperMockFactory.BOLSchemaVersionsMapperMock, mock.DALMapperMockFactory.DALSchemaVersionsMapperMock); ActionResponse response = await service.Delete(default(int)); response.Should().NotBeNull(); mock.RepositoryMock.Verify(x => x.Delete(It.IsAny <int>())); mock.ModelValidatorMockFactory.SchemaVersionsModelValidatorMock.Verify(x => x.ValidateDeleteAsync(It.IsAny <int>())); }
public virtual async Task <UpdateResponse <ApiSchemaVersionsResponseModel> > Update( int id, ApiSchemaVersionsRequestModel model) { var validationResult = await this.schemaVersionsModelValidator.ValidateUpdateAsync(id, model); if (validationResult.IsValid) { var bo = this.bolSchemaVersionsMapper.MapModelToBO(id, model); await this.schemaVersionsRepository.Update(this.dalSchemaVersionsMapper.MapBOToEF(bo)); var record = await this.schemaVersionsRepository.Get(id); return(new UpdateResponse <ApiSchemaVersionsResponseModel>(this.bolSchemaVersionsMapper.MapBOToModel(this.dalSchemaVersionsMapper.MapEFToBO(record)))); } else { return(new UpdateResponse <ApiSchemaVersionsResponseModel>(validationResult)); } }
public virtual async Task <IActionResult> Update(int id, [FromBody] ApiSchemaVersionsRequestModel model) { ApiSchemaVersionsRequestModel request = await this.PatchModel(id, this.SchemaVersionsModelMapper.CreatePatch(model)); if (request == null) { return(this.StatusCode(StatusCodes.Status404NotFound)); } else { UpdateResponse <ApiSchemaVersionsResponseModel> result = await this.SchemaVersionsService.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 <ApiSchemaVersionsRequestModel> patch) { ApiSchemaVersionsResponseModel record = await this.SchemaVersionsService.Get(id); if (record == null) { return(this.StatusCode(StatusCodes.Status404NotFound)); } else { ApiSchemaVersionsRequestModel model = await this.PatchModel(id, patch); UpdateResponse <ApiSchemaVersionsResponseModel> result = await this.SchemaVersionsService.Update(id, model); if (result.Success) { return(this.Ok(result)); } else { return(this.StatusCode(StatusCodes.Status422UnprocessableEntity, result)); } } }
public async Task <ValidationResult> ValidateUpdateAsync(int id, ApiSchemaVersionsRequestModel model) { this.AppliedRules(); this.ScriptNameRules(); return(await this.ValidateAsync(model, id)); }