private async Task <ApiInterruptionResponseModel> CreateRecord() { var model = new ApiInterruptionRequestModel(); model.SetProperties(DateTimeOffset.Parse("1/1/1988 12:00:00 AM"), "B", "B", "B", "B", "B", "B", "B", "B", "B"); CreateResponse <ApiInterruptionResponseModel> result = await this.Client.InterruptionCreateAsync(model); result.Success.Should().BeTrue(); return(result.Record); }
public virtual async Task <IActionResult> Create([FromBody] ApiInterruptionRequestModel model) { CreateResponse <ApiInterruptionResponseModel> result = await this.InterruptionService.Create(model); if (result.Success) { return(this.Created($"{this.Settings.ExternalBaseUrl}/api/Interruptions/{result.Record.Id}", result)); } else { return(this.StatusCode(StatusCodes.Status422UnprocessableEntity, result)); } }
public async Task <ValidationResult> ValidateUpdateAsync(string id, ApiInterruptionRequestModel model) { this.CreatedRules(); this.EnvironmentIdRules(); this.JSONRules(); this.ProjectIdRules(); this.RelatedDocumentIdsRules(); this.ResponsibleTeamIdsRules(); this.StatusRules(); this.TaskIdRules(); this.TenantIdRules(); this.TitleRules(); return(await this.ValidateAsync(model, id)); }
public virtual async Task <CreateResponse <ApiInterruptionResponseModel> > Create( ApiInterruptionRequestModel model) { CreateResponse <ApiInterruptionResponseModel> response = new CreateResponse <ApiInterruptionResponseModel>(await this.interruptionModelValidator.ValidateCreateAsync(model)); if (response.Success) { var bo = this.bolInterruptionMapper.MapModelToBO(default(string), model); var record = await this.interruptionRepository.Create(this.dalInterruptionMapper.MapBOToEF(bo)); response.SetRecord(this.bolInterruptionMapper.MapBOToModel(this.dalInterruptionMapper.MapEFToBO(record))); } return(response); }
private async Task <ApiInterruptionRequestModel> PatchModel(string id, JsonPatchDocument <ApiInterruptionRequestModel> patch) { var record = await this.InterruptionService.Get(id); if (record == null) { return(null); } else { ApiInterruptionRequestModel request = this.InterruptionModelMapper.MapResponseToRequest(record); patch.ApplyTo(request); return(request); } }
public async void Create() { var mock = new ServiceMockFacade <IInterruptionRepository>(); var model = new ApiInterruptionRequestModel(); mock.RepositoryMock.Setup(x => x.Create(It.IsAny <Interruption>())).Returns(Task.FromResult(new Interruption())); var service = new InterruptionService(mock.LoggerMock.Object, mock.RepositoryMock.Object, mock.ModelValidatorMockFactory.InterruptionModelValidatorMock.Object, mock.BOLMapperMockFactory.BOLInterruptionMapperMock, mock.DALMapperMockFactory.DALInterruptionMapperMock); CreateResponse <ApiInterruptionResponseModel> response = await service.Create(model); response.Should().NotBeNull(); mock.ModelValidatorMockFactory.InterruptionModelValidatorMock.Verify(x => x.ValidateCreateAsync(It.IsAny <ApiInterruptionRequestModel>())); mock.RepositoryMock.Verify(x => x.Create(It.IsAny <Interruption>())); }
public async void Delete() { var mock = new ServiceMockFacade <IInterruptionRepository>(); var model = new ApiInterruptionRequestModel(); mock.RepositoryMock.Setup(x => x.Delete(It.IsAny <string>())).Returns(Task.CompletedTask); var service = new InterruptionService(mock.LoggerMock.Object, mock.RepositoryMock.Object, mock.ModelValidatorMockFactory.InterruptionModelValidatorMock.Object, mock.BOLMapperMockFactory.BOLInterruptionMapperMock, mock.DALMapperMockFactory.DALInterruptionMapperMock); ActionResponse response = await service.Delete(default(string)); response.Should().NotBeNull(); mock.RepositoryMock.Verify(x => x.Delete(It.IsAny <string>())); mock.ModelValidatorMockFactory.InterruptionModelValidatorMock.Verify(x => x.ValidateDeleteAsync(It.IsAny <string>())); }
public void MapResponseToRequest() { var mapper = new ApiInterruptionModelMapper(); var model = new ApiInterruptionResponseModel(); model.SetProperties("A", DateTimeOffset.Parse("1/1/1987 12:00:00 AM"), "A", "A", "A", "A", "A", "A", "A", "A", "A"); ApiInterruptionRequestModel response = mapper.MapResponseToRequest(model); response.Created.Should().Be(DateTimeOffset.Parse("1/1/1987 12:00:00 AM")); response.EnvironmentId.Should().Be("A"); response.JSON.Should().Be("A"); response.ProjectId.Should().Be("A"); response.RelatedDocumentIds.Should().Be("A"); response.ResponsibleTeamIds.Should().Be("A"); response.Status.Should().Be("A"); response.TaskId.Should().Be("A"); response.TenantId.Should().Be("A"); response.Title.Should().Be("A"); }
public virtual async Task <UpdateResponse <ApiInterruptionResponseModel> > Update( string id, ApiInterruptionRequestModel model) { var validationResult = await this.interruptionModelValidator.ValidateUpdateAsync(id, model); if (validationResult.IsValid) { var bo = this.bolInterruptionMapper.MapModelToBO(id, model); await this.interruptionRepository.Update(this.dalInterruptionMapper.MapBOToEF(bo)); var record = await this.interruptionRepository.Get(id); return(new UpdateResponse <ApiInterruptionResponseModel>(this.bolInterruptionMapper.MapBOToModel(this.dalInterruptionMapper.MapEFToBO(record)))); } else { return(new UpdateResponse <ApiInterruptionResponseModel>(validationResult)); } }
public virtual BOInterruption MapModelToBO( string id, ApiInterruptionRequestModel model ) { BOInterruption boInterruption = new BOInterruption(); boInterruption.SetProperties( id, model.Created, model.EnvironmentId, model.JSON, model.ProjectId, model.RelatedDocumentIds, model.ResponsibleTeamIds, model.Status, model.TaskId, model.TenantId, model.Title); return(boInterruption); }
public void CreatePatch() { var mapper = new ApiInterruptionModelMapper(); var model = new ApiInterruptionRequestModel(); model.SetProperties(DateTimeOffset.Parse("1/1/1987 12:00:00 AM"), "A", "A", "A", "A", "A", "A", "A", "A", "A"); JsonPatchDocument <ApiInterruptionRequestModel> patch = mapper.CreatePatch(model); var response = new ApiInterruptionRequestModel(); patch.ApplyTo(response); response.Created.Should().Be(DateTimeOffset.Parse("1/1/1987 12:00:00 AM")); response.EnvironmentId.Should().Be("A"); response.JSON.Should().Be("A"); response.ProjectId.Should().Be("A"); response.RelatedDocumentIds.Should().Be("A"); response.ResponsibleTeamIds.Should().Be("A"); response.Status.Should().Be("A"); response.TaskId.Should().Be("A"); response.TenantId.Should().Be("A"); response.Title.Should().Be("A"); }
public virtual async Task <IActionResult> Update(string id, [FromBody] ApiInterruptionRequestModel model) { ApiInterruptionRequestModel request = await this.PatchModel(id, this.InterruptionModelMapper.CreatePatch(model)); if (request == null) { return(this.StatusCode(StatusCodes.Status404NotFound)); } else { UpdateResponse <ApiInterruptionResponseModel> result = await this.InterruptionService.Update(id, request); if (result.Success) { return(this.Ok(result)); } else { return(this.StatusCode(StatusCodes.Status422UnprocessableEntity, result)); } } }
public virtual async Task <IActionResult> Patch(string id, [FromBody] JsonPatchDocument <ApiInterruptionRequestModel> patch) { ApiInterruptionResponseModel record = await this.InterruptionService.Get(id); if (record == null) { return(this.StatusCode(StatusCodes.Status404NotFound)); } else { ApiInterruptionRequestModel model = await this.PatchModel(id, patch); UpdateResponse <ApiInterruptionResponseModel> result = await this.InterruptionService.Update(id, model); if (result.Success) { return(this.Ok(result)); } else { return(this.StatusCode(StatusCodes.Status422UnprocessableEntity, result)); } } }