private async Task <ApiStudentXFamilyResponseModel> CreateRecord() { var model = new ApiStudentXFamilyRequestModel(); model.SetProperties(1, 1); CreateResponse <ApiStudentXFamilyResponseModel> result = await this.Client.StudentXFamilyCreateAsync(model); result.Success.Should().BeTrue(); return(result.Record); }
public void MapModelToBO() { var mapper = new BOLStudentXFamilyMapper(); ApiStudentXFamilyRequestModel model = new ApiStudentXFamilyRequestModel(); model.SetProperties(1, 1); BOStudentXFamily response = mapper.MapModelToBO(1, model); response.FamilyId.Should().Be(1); response.StudentId.Should().Be(1); }
public void MapResponseToRequest() { var mapper = new ApiStudentXFamilyModelMapper(); var model = new ApiStudentXFamilyResponseModel(); model.SetProperties(1, 1, 1); ApiStudentXFamilyRequestModel response = mapper.MapResponseToRequest(model); response.FamilyId.Should().Be(1); response.StudentId.Should().Be(1); }
public virtual BOStudentXFamily MapModelToBO( int id, ApiStudentXFamilyRequestModel model ) { BOStudentXFamily boStudentXFamily = new BOStudentXFamily(); boStudentXFamily.SetProperties( id, model.FamilyId, model.StudentId); return(boStudentXFamily); }
public virtual async Task <IActionResult> Create([FromBody] ApiStudentXFamilyRequestModel model) { CreateResponse <ApiStudentXFamilyResponseModel> result = await this.StudentXFamilyService.Create(model); if (result.Success) { return(this.Created($"{this.Settings.ExternalBaseUrl}/api/StudentXFamilies/{result.Record.Id}", result)); } else { return(this.StatusCode(StatusCodes.Status422UnprocessableEntity, result)); } }
public void CreatePatch() { var mapper = new ApiStudentXFamilyModelMapper(); var model = new ApiStudentXFamilyRequestModel(); model.SetProperties(1, 1); JsonPatchDocument <ApiStudentXFamilyRequestModel> patch = mapper.CreatePatch(model); var response = new ApiStudentXFamilyRequestModel(); patch.ApplyTo(response); response.FamilyId.Should().Be(1); response.StudentId.Should().Be(1); }
private async Task <ApiStudentXFamilyRequestModel> PatchModel(int id, JsonPatchDocument <ApiStudentXFamilyRequestModel> patch) { var record = await this.StudentXFamilyService.Get(id); if (record == null) { return(null); } else { ApiStudentXFamilyRequestModel request = this.StudentXFamilyModelMapper.MapResponseToRequest(record); patch.ApplyTo(request); return(request); } }
public virtual async Task <CreateResponse <ApiStudentXFamilyResponseModel> > Create( ApiStudentXFamilyRequestModel model) { CreateResponse <ApiStudentXFamilyResponseModel> response = new CreateResponse <ApiStudentXFamilyResponseModel>(await this.studentXFamilyModelValidator.ValidateCreateAsync(model)); if (response.Success) { var bo = this.bolStudentXFamilyMapper.MapModelToBO(default(int), model); var record = await this.studentXFamilyRepository.Create(this.dalStudentXFamilyMapper.MapBOToEF(bo)); response.SetRecord(this.bolStudentXFamilyMapper.MapBOToModel(this.dalStudentXFamilyMapper.MapEFToBO(record))); } return(response); }
public async void Create() { var mock = new ServiceMockFacade <IStudentXFamilyRepository>(); var model = new ApiStudentXFamilyRequestModel(); mock.RepositoryMock.Setup(x => x.Create(It.IsAny <StudentXFamily>())).Returns(Task.FromResult(new StudentXFamily())); var service = new StudentXFamilyService(mock.LoggerMock.Object, mock.RepositoryMock.Object, mock.ModelValidatorMockFactory.StudentXFamilyModelValidatorMock.Object, mock.BOLMapperMockFactory.BOLStudentXFamilyMapperMock, mock.DALMapperMockFactory.DALStudentXFamilyMapperMock); CreateResponse <ApiStudentXFamilyResponseModel> response = await service.Create(model); response.Should().NotBeNull(); mock.ModelValidatorMockFactory.StudentXFamilyModelValidatorMock.Verify(x => x.ValidateCreateAsync(It.IsAny <ApiStudentXFamilyRequestModel>())); mock.RepositoryMock.Verify(x => x.Create(It.IsAny <StudentXFamily>())); }
public async void Delete() { var mock = new ServiceMockFacade <IStudentXFamilyRepository>(); var model = new ApiStudentXFamilyRequestModel(); mock.RepositoryMock.Setup(x => x.Delete(It.IsAny <int>())).Returns(Task.CompletedTask); var service = new StudentXFamilyService(mock.LoggerMock.Object, mock.RepositoryMock.Object, mock.ModelValidatorMockFactory.StudentXFamilyModelValidatorMock.Object, mock.BOLMapperMockFactory.BOLStudentXFamilyMapperMock, mock.DALMapperMockFactory.DALStudentXFamilyMapperMock); ActionResponse response = await service.Delete(default(int)); response.Should().NotBeNull(); mock.RepositoryMock.Verify(x => x.Delete(It.IsAny <int>())); mock.ModelValidatorMockFactory.StudentXFamilyModelValidatorMock.Verify(x => x.ValidateDeleteAsync(It.IsAny <int>())); }
public virtual async Task <UpdateResponse <ApiStudentXFamilyResponseModel> > Update( int id, ApiStudentXFamilyRequestModel model) { var validationResult = await this.studentXFamilyModelValidator.ValidateUpdateAsync(id, model); if (validationResult.IsValid) { var bo = this.bolStudentXFamilyMapper.MapModelToBO(id, model); await this.studentXFamilyRepository.Update(this.dalStudentXFamilyMapper.MapBOToEF(bo)); var record = await this.studentXFamilyRepository.Get(id); return(new UpdateResponse <ApiStudentXFamilyResponseModel>(this.bolStudentXFamilyMapper.MapBOToModel(this.dalStudentXFamilyMapper.MapEFToBO(record)))); } else { return(new UpdateResponse <ApiStudentXFamilyResponseModel>(validationResult)); } }
public virtual async Task <IActionResult> Update(int id, [FromBody] ApiStudentXFamilyRequestModel model) { ApiStudentXFamilyRequestModel request = await this.PatchModel(id, this.StudentXFamilyModelMapper.CreatePatch(model)); if (request == null) { return(this.StatusCode(StatusCodes.Status404NotFound)); } else { UpdateResponse <ApiStudentXFamilyResponseModel> result = await this.StudentXFamilyService.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 <ApiStudentXFamilyRequestModel> patch) { ApiStudentXFamilyResponseModel record = await this.StudentXFamilyService.Get(id); if (record == null) { return(this.StatusCode(StatusCodes.Status404NotFound)); } else { ApiStudentXFamilyRequestModel model = await this.PatchModel(id, patch); UpdateResponse <ApiStudentXFamilyResponseModel> result = await this.StudentXFamilyService.Update(id, model); if (result.Success) { return(this.Ok(result)); } else { return(this.StatusCode(StatusCodes.Status422UnprocessableEntity, result)); } } }
public virtual async Task <UpdateResponse <ApiStudentXFamilyResponseModel> > StudentXFamilyUpdateAsync(int id, ApiStudentXFamilyRequestModel item) { HttpResponseMessage httpResponse = await this.client.PutAsJsonAsync($"api/StudentXFamilies/{id}", item).ConfigureAwait(false); return(JsonConvert.DeserializeObject <UpdateResponse <ApiStudentXFamilyResponseModel> >(httpResponse.Content.ContentToString())); }
public async Task <ValidationResult> ValidateUpdateAsync(int id, ApiStudentXFamilyRequestModel model) { this.FamilyIdRules(); this.StudentIdRules(); return(await this.ValidateAsync(model, id)); }