public void MapModelToBO() { var mapper = new BOLServerTaskMapper(); ApiServerTaskRequestModel model = new ApiServerTaskRequestModel(); model.SetProperties(DateTimeOffset.Parse("1/1/1987 12:00:00 AM"), "A", "A", 1, "A", "A", true, true, "A", "A", "A", DateTimeOffset.Parse("1/1/1987 12:00:00 AM"), "A", DateTimeOffset.Parse("1/1/1987 12:00:00 AM"), "A", "A"); BOServerTask response = mapper.MapModelToBO("A", model); response.CompletedTime.Should().Be(DateTimeOffset.Parse("1/1/1987 12:00:00 AM")); response.ConcurrencyTag.Should().Be("A"); response.Description.Should().Be("A"); response.DurationSeconds.Should().Be(1); response.EnvironmentId.Should().Be("A"); response.ErrorMessage.Should().Be("A"); response.HasPendingInterruptions.Should().Be(true); response.HasWarningsOrErrors.Should().Be(true); response.JSON.Should().Be("A"); response.Name.Should().Be("A"); response.ProjectId.Should().Be("A"); response.QueueTime.Should().Be(DateTimeOffset.Parse("1/1/1987 12:00:00 AM")); response.ServerNodeId.Should().Be("A"); response.StartTime.Should().Be(DateTimeOffset.Parse("1/1/1987 12:00:00 AM")); response.State.Should().Be("A"); response.TenantId.Should().Be("A"); }
public void CreatePatch() { var mapper = new ApiServerTaskModelMapper(); var model = new ApiServerTaskRequestModel(); model.SetProperties(DateTimeOffset.Parse("1/1/1987 12:00:00 AM"), "A", "A", 1, "A", "A", true, true, "A", "A", "A", DateTimeOffset.Parse("1/1/1987 12:00:00 AM"), "A", DateTimeOffset.Parse("1/1/1987 12:00:00 AM"), "A", "A"); JsonPatchDocument <ApiServerTaskRequestModel> patch = mapper.CreatePatch(model); var response = new ApiServerTaskRequestModel(); patch.ApplyTo(response); response.CompletedTime.Should().Be(DateTimeOffset.Parse("1/1/1987 12:00:00 AM")); response.ConcurrencyTag.Should().Be("A"); response.Description.Should().Be("A"); response.DurationSeconds.Should().Be(1); response.EnvironmentId.Should().Be("A"); response.ErrorMessage.Should().Be("A"); response.HasPendingInterruptions.Should().Be(true); response.HasWarningsOrErrors.Should().Be(true); response.JSON.Should().Be("A"); response.Name.Should().Be("A"); response.ProjectId.Should().Be("A"); response.QueueTime.Should().Be(DateTimeOffset.Parse("1/1/1987 12:00:00 AM")); response.ServerNodeId.Should().Be("A"); response.StartTime.Should().Be(DateTimeOffset.Parse("1/1/1987 12:00:00 AM")); response.State.Should().Be("A"); response.TenantId.Should().Be("A"); }
public virtual BOServerTask MapModelToBO( string id, ApiServerTaskRequestModel model ) { BOServerTask boServerTask = new BOServerTask(); boServerTask.SetProperties( id, model.CompletedTime, model.ConcurrencyTag, model.Description, model.DurationSeconds, model.EnvironmentId, model.ErrorMessage, model.HasPendingInterruptions, model.HasWarningsOrErrors, model.JSON, model.Name, model.ProjectId, model.QueueTime, model.ServerNodeId, model.StartTime, model.State, model.TenantId); return(boServerTask); }
private async Task <ApiServerTaskResponseModel> CreateRecord() { var model = new ApiServerTaskRequestModel(); model.SetProperties(DateTimeOffset.Parse("1/1/1988 12:00:00 AM"), "B", "B", 2, "B", "B", true, true, "B", "B", "B", DateTimeOffset.Parse("1/1/1988 12:00:00 AM"), "B", DateTimeOffset.Parse("1/1/1988 12:00:00 AM"), "B", "B"); CreateResponse <ApiServerTaskResponseModel> result = await this.Client.ServerTaskCreateAsync(model); result.Success.Should().BeTrue(); return(result.Record); }
public virtual async Task <IActionResult> Create([FromBody] ApiServerTaskRequestModel model) { CreateResponse <ApiServerTaskResponseModel> result = await this.ServerTaskService.Create(model); if (result.Success) { return(this.Created($"{this.Settings.ExternalBaseUrl}/api/ServerTasks/{result.Record.Id}", result)); } else { return(this.StatusCode(StatusCodes.Status422UnprocessableEntity, result)); } }
public virtual async Task <CreateResponse <ApiServerTaskResponseModel> > Create( ApiServerTaskRequestModel model) { CreateResponse <ApiServerTaskResponseModel> response = new CreateResponse <ApiServerTaskResponseModel>(await this.serverTaskModelValidator.ValidateCreateAsync(model)); if (response.Success) { var bo = this.bolServerTaskMapper.MapModelToBO(default(string), model); var record = await this.serverTaskRepository.Create(this.dalServerTaskMapper.MapBOToEF(bo)); response.SetRecord(this.bolServerTaskMapper.MapBOToModel(this.dalServerTaskMapper.MapEFToBO(record))); } return(response); }
private async Task <ApiServerTaskRequestModel> PatchModel(string id, JsonPatchDocument <ApiServerTaskRequestModel> patch) { var record = await this.ServerTaskService.Get(id); if (record == null) { return(null); } else { ApiServerTaskRequestModel request = this.ServerTaskModelMapper.MapResponseToRequest(record); patch.ApplyTo(request); return(request); } }
public async void Create() { var mock = new ServiceMockFacade <IServerTaskRepository>(); var model = new ApiServerTaskRequestModel(); mock.RepositoryMock.Setup(x => x.Create(It.IsAny <ServerTask>())).Returns(Task.FromResult(new ServerTask())); var service = new ServerTaskService(mock.LoggerMock.Object, mock.RepositoryMock.Object, mock.ModelValidatorMockFactory.ServerTaskModelValidatorMock.Object, mock.BOLMapperMockFactory.BOLServerTaskMapperMock, mock.DALMapperMockFactory.DALServerTaskMapperMock); CreateResponse <ApiServerTaskResponseModel> response = await service.Create(model); response.Should().NotBeNull(); mock.ModelValidatorMockFactory.ServerTaskModelValidatorMock.Verify(x => x.ValidateCreateAsync(It.IsAny <ApiServerTaskRequestModel>())); mock.RepositoryMock.Verify(x => x.Create(It.IsAny <ServerTask>())); }
public async void Delete() { var mock = new ServiceMockFacade <IServerTaskRepository>(); var model = new ApiServerTaskRequestModel(); mock.RepositoryMock.Setup(x => x.Delete(It.IsAny <string>())).Returns(Task.CompletedTask); var service = new ServerTaskService(mock.LoggerMock.Object, mock.RepositoryMock.Object, mock.ModelValidatorMockFactory.ServerTaskModelValidatorMock.Object, mock.BOLMapperMockFactory.BOLServerTaskMapperMock, mock.DALMapperMockFactory.DALServerTaskMapperMock); ActionResponse response = await service.Delete(default(string)); response.Should().NotBeNull(); mock.RepositoryMock.Verify(x => x.Delete(It.IsAny <string>())); mock.ModelValidatorMockFactory.ServerTaskModelValidatorMock.Verify(x => x.ValidateDeleteAsync(It.IsAny <string>())); }
public virtual async Task <UpdateResponse <ApiServerTaskResponseModel> > Update( string id, ApiServerTaskRequestModel model) { var validationResult = await this.serverTaskModelValidator.ValidateUpdateAsync(id, model); if (validationResult.IsValid) { var bo = this.bolServerTaskMapper.MapModelToBO(id, model); await this.serverTaskRepository.Update(this.dalServerTaskMapper.MapBOToEF(bo)); var record = await this.serverTaskRepository.Get(id); return(new UpdateResponse <ApiServerTaskResponseModel>(this.bolServerTaskMapper.MapBOToModel(this.dalServerTaskMapper.MapEFToBO(record)))); } else { return(new UpdateResponse <ApiServerTaskResponseModel>(validationResult)); } }
public async Task <ValidationResult> ValidateUpdateAsync(string id, ApiServerTaskRequestModel model) { this.CompletedTimeRules(); this.ConcurrencyTagRules(); this.DescriptionRules(); this.DurationSecondsRules(); this.EnvironmentIdRules(); this.ErrorMessageRules(); this.HasPendingInterruptionsRules(); this.HasWarningsOrErrorsRules(); this.JSONRules(); this.NameRules(); this.ProjectIdRules(); this.QueueTimeRules(); this.ServerNodeIdRules(); this.StartTimeRules(); this.StateRules(); this.TenantIdRules(); return(await this.ValidateAsync(model, id)); }
public virtual async Task <IActionResult> Update(string id, [FromBody] ApiServerTaskRequestModel model) { ApiServerTaskRequestModel request = await this.PatchModel(id, this.ServerTaskModelMapper.CreatePatch(model)); if (request == null) { return(this.StatusCode(StatusCodes.Status404NotFound)); } else { UpdateResponse <ApiServerTaskResponseModel> result = await this.ServerTaskService.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 <ApiServerTaskRequestModel> patch) { ApiServerTaskResponseModel record = await this.ServerTaskService.Get(id); if (record == null) { return(this.StatusCode(StatusCodes.Status404NotFound)); } else { ApiServerTaskRequestModel model = await this.PatchModel(id, patch); UpdateResponse <ApiServerTaskResponseModel> result = await this.ServerTaskService.Update(id, model); if (result.Success) { return(this.Ok(result)); } else { return(this.StatusCode(StatusCodes.Status422UnprocessableEntity, result)); } } }