private async Task <ApiLessonXStudentResponseModel> CreateRecord() { var model = new ApiLessonXStudentRequestModel(); model.SetProperties(1, 1); CreateResponse <ApiLessonXStudentResponseModel> result = await this.Client.LessonXStudentCreateAsync(model); result.Success.Should().BeTrue(); return(result.Record); }
public void MapResponseToRequest() { var mapper = new ApiLessonXStudentModelMapper(); var model = new ApiLessonXStudentResponseModel(); model.SetProperties(1, 1, 1); ApiLessonXStudentRequestModel response = mapper.MapResponseToRequest(model); response.LessonId.Should().Be(1); response.StudentId.Should().Be(1); }
public void MapModelToBO() { var mapper = new BOLLessonXStudentMapper(); ApiLessonXStudentRequestModel model = new ApiLessonXStudentRequestModel(); model.SetProperties(1, 1); BOLessonXStudent response = mapper.MapModelToBO(1, model); response.LessonId.Should().Be(1); response.StudentId.Should().Be(1); }
public virtual async Task <IActionResult> Create([FromBody] ApiLessonXStudentRequestModel model) { CreateResponse <ApiLessonXStudentResponseModel> result = await this.LessonXStudentService.Create(model); if (result.Success) { return(this.Created($"{this.Settings.ExternalBaseUrl}/api/LessonXStudents/{result.Record.Id}", result)); } else { return(this.StatusCode(StatusCodes.Status422UnprocessableEntity, result)); } }
public virtual BOLessonXStudent MapModelToBO( int id, ApiLessonXStudentRequestModel model ) { BOLessonXStudent boLessonXStudent = new BOLessonXStudent(); boLessonXStudent.SetProperties( id, model.LessonId, model.StudentId); return(boLessonXStudent); }
public void CreatePatch() { var mapper = new ApiLessonXStudentModelMapper(); var model = new ApiLessonXStudentRequestModel(); model.SetProperties(1, 1); JsonPatchDocument <ApiLessonXStudentRequestModel> patch = mapper.CreatePatch(model); var response = new ApiLessonXStudentRequestModel(); patch.ApplyTo(response); response.LessonId.Should().Be(1); response.StudentId.Should().Be(1); }
private async Task <ApiLessonXStudentRequestModel> PatchModel(int id, JsonPatchDocument <ApiLessonXStudentRequestModel> patch) { var record = await this.LessonXStudentService.Get(id); if (record == null) { return(null); } else { ApiLessonXStudentRequestModel request = this.LessonXStudentModelMapper.MapResponseToRequest(record); patch.ApplyTo(request); return(request); } }
public virtual async Task <CreateResponse <ApiLessonXStudentResponseModel> > Create( ApiLessonXStudentRequestModel model) { CreateResponse <ApiLessonXStudentResponseModel> response = new CreateResponse <ApiLessonXStudentResponseModel>(await this.lessonXStudentModelValidator.ValidateCreateAsync(model)); if (response.Success) { var bo = this.bolLessonXStudentMapper.MapModelToBO(default(int), model); var record = await this.lessonXStudentRepository.Create(this.dalLessonXStudentMapper.MapBOToEF(bo)); response.SetRecord(this.bolLessonXStudentMapper.MapBOToModel(this.dalLessonXStudentMapper.MapEFToBO(record))); } return(response); }
public async void Create() { var mock = new ServiceMockFacade <ILessonXStudentRepository>(); var model = new ApiLessonXStudentRequestModel(); mock.RepositoryMock.Setup(x => x.Create(It.IsAny <LessonXStudent>())).Returns(Task.FromResult(new LessonXStudent())); var service = new LessonXStudentService(mock.LoggerMock.Object, mock.RepositoryMock.Object, mock.ModelValidatorMockFactory.LessonXStudentModelValidatorMock.Object, mock.BOLMapperMockFactory.BOLLessonXStudentMapperMock, mock.DALMapperMockFactory.DALLessonXStudentMapperMock); CreateResponse <ApiLessonXStudentResponseModel> response = await service.Create(model); response.Should().NotBeNull(); mock.ModelValidatorMockFactory.LessonXStudentModelValidatorMock.Verify(x => x.ValidateCreateAsync(It.IsAny <ApiLessonXStudentRequestModel>())); mock.RepositoryMock.Verify(x => x.Create(It.IsAny <LessonXStudent>())); }
public async void Delete() { var mock = new ServiceMockFacade <ILessonXStudentRepository>(); var model = new ApiLessonXStudentRequestModel(); mock.RepositoryMock.Setup(x => x.Delete(It.IsAny <int>())).Returns(Task.CompletedTask); var service = new LessonXStudentService(mock.LoggerMock.Object, mock.RepositoryMock.Object, mock.ModelValidatorMockFactory.LessonXStudentModelValidatorMock.Object, mock.BOLMapperMockFactory.BOLLessonXStudentMapperMock, mock.DALMapperMockFactory.DALLessonXStudentMapperMock); ActionResponse response = await service.Delete(default(int)); response.Should().NotBeNull(); mock.RepositoryMock.Verify(x => x.Delete(It.IsAny <int>())); mock.ModelValidatorMockFactory.LessonXStudentModelValidatorMock.Verify(x => x.ValidateDeleteAsync(It.IsAny <int>())); }
public virtual async Task <UpdateResponse <ApiLessonXStudentResponseModel> > Update( int id, ApiLessonXStudentRequestModel model) { var validationResult = await this.lessonXStudentModelValidator.ValidateUpdateAsync(id, model); if (validationResult.IsValid) { var bo = this.bolLessonXStudentMapper.MapModelToBO(id, model); await this.lessonXStudentRepository.Update(this.dalLessonXStudentMapper.MapBOToEF(bo)); var record = await this.lessonXStudentRepository.Get(id); return(new UpdateResponse <ApiLessonXStudentResponseModel>(this.bolLessonXStudentMapper.MapBOToModel(this.dalLessonXStudentMapper.MapEFToBO(record)))); } else { return(new UpdateResponse <ApiLessonXStudentResponseModel>(validationResult)); } }
public virtual async Task <IActionResult> Update(int id, [FromBody] ApiLessonXStudentRequestModel model) { ApiLessonXStudentRequestModel request = await this.PatchModel(id, this.LessonXStudentModelMapper.CreatePatch(model)); if (request == null) { return(this.StatusCode(StatusCodes.Status404NotFound)); } else { UpdateResponse <ApiLessonXStudentResponseModel> result = await this.LessonXStudentService.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 <ApiLessonXStudentRequestModel> patch) { ApiLessonXStudentResponseModel record = await this.LessonXStudentService.Get(id); if (record == null) { return(this.StatusCode(StatusCodes.Status404NotFound)); } else { ApiLessonXStudentRequestModel model = await this.PatchModel(id, patch); UpdateResponse <ApiLessonXStudentResponseModel> result = await this.LessonXStudentService.Update(id, model); if (result.Success) { return(this.Ok(result)); } else { return(this.StatusCode(StatusCodes.Status422UnprocessableEntity, result)); } } }
public virtual async Task <UpdateResponse <ApiLessonXStudentResponseModel> > LessonXStudentUpdateAsync(int id, ApiLessonXStudentRequestModel item) { HttpResponseMessage httpResponse = await this.client.PutAsJsonAsync($"api/LessonXStudents/{id}", item).ConfigureAwait(false); return(JsonConvert.DeserializeObject <UpdateResponse <ApiLessonXStudentResponseModel> >(httpResponse.Content.ContentToString())); }
public async Task <ValidationResult> ValidateUpdateAsync(int id, ApiLessonXStudentRequestModel model) { this.LessonIdRules(); this.StudentIdRules(); return(await this.ValidateAsync(model, id)); }