public virtual ApiLessonXStudentResponseModel MapBOToModel( BOLessonXStudent boLessonXStudent) { var model = new ApiLessonXStudentResponseModel(); model.SetProperties(boLessonXStudent.Id, boLessonXStudent.LessonId, boLessonXStudent.StudentId); return(model); }
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 MapBOToModel() { var mapper = new BOLLessonXStudentMapper(); BOLessonXStudent bo = new BOLessonXStudent(); bo.SetProperties(1, 1, 1); ApiLessonXStudentResponseModel response = mapper.MapBOToModel(bo); response.Id.Should().Be(1); response.LessonId.Should().Be(1); response.StudentId.Should().Be(1); }
public async virtual Task <IActionResult> Get(int id) { ApiLessonXStudentResponseModel response = await this.LessonXStudentService.Get(id); if (response == null) { return(this.StatusCode(StatusCodes.Status404NotFound)); } else { return(this.Ok(response)); } }
public async void Get_null_record() { var mock = new ServiceMockFacade <ILessonXStudentRepository>(); mock.RepositoryMock.Setup(x => x.Get(It.IsAny <int>())).Returns(Task.FromResult <LessonXStudent>(null)); var service = new LessonXStudentService(mock.LoggerMock.Object, mock.RepositoryMock.Object, mock.ModelValidatorMockFactory.LessonXStudentModelValidatorMock.Object, mock.BOLMapperMockFactory.BOLLessonXStudentMapperMock, mock.DALMapperMockFactory.DALLessonXStudentMapperMock); ApiLessonXStudentResponseModel response = await service.Get(default(int)); response.Should().BeNull(); mock.RepositoryMock.Verify(x => x.Get(It.IsAny <int>())); }
public async void Create_Errors() { LessonXStudentControllerMockFacade mock = new LessonXStudentControllerMockFacade(); var mockResponse = new Mock <CreateResponse <ApiLessonXStudentResponseModel> >(new FluentValidation.Results.ValidationResult()); var mockRecord = new ApiLessonXStudentResponseModel(); mockResponse.SetupGet(x => x.Success).Returns(false); mock.ServiceMock.Setup(x => x.Create(It.IsAny <ApiLessonXStudentRequestModel>())).Returns(Task.FromResult <CreateResponse <ApiLessonXStudentResponseModel> >(mockResponse.Object)); LessonXStudentController controller = new LessonXStudentController(mock.ApiSettingsMoc.Object, mock.LoggerMock.Object, mock.TransactionCoordinatorMock.Object, mock.ServiceMock.Object, mock.ModelMapperMock.Object); controller.ControllerContext = new ControllerContext(); controller.ControllerContext.HttpContext = new DefaultHttpContext(); IActionResult response = await controller.Create(new ApiLessonXStudentRequestModel()); response.Should().BeOfType <ObjectResult>(); (response as ObjectResult).StatusCode.Should().Be((int)HttpStatusCode.UnprocessableEntity); mock.ServiceMock.Verify(x => x.Create(It.IsAny <ApiLessonXStudentRequestModel>())); }
public async void All_Exists() { LessonXStudentControllerMockFacade mock = new LessonXStudentControllerMockFacade(); var record = new ApiLessonXStudentResponseModel(); var records = new List <ApiLessonXStudentResponseModel>(); records.Add(record); mock.ServiceMock.Setup(x => x.All(It.IsAny <int>(), It.IsAny <int>())).Returns(Task.FromResult(records)); LessonXStudentController controller = new LessonXStudentController(mock.ApiSettingsMoc.Object, mock.LoggerMock.Object, mock.TransactionCoordinatorMock.Object, mock.ServiceMock.Object, mock.ModelMapperMock.Object); controller.ControllerContext = new ControllerContext(); controller.ControllerContext.HttpContext = new DefaultHttpContext(); IActionResult response = await controller.All(1000, 0); response.Should().BeOfType <OkObjectResult>(); (response as OkObjectResult).StatusCode.Should().Be((int)HttpStatusCode.OK); var items = (response as OkObjectResult).Value as List <ApiLessonXStudentResponseModel>; items.Count.Should().Be(1); mock.ServiceMock.Verify(x => x.All(It.IsAny <int>(), It.IsAny <int>())); }
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 async void TestGet() { ApiLessonXStudentResponseModel response = await this.Client.LessonXStudentGetAsync(1); response.Should().NotBeNull(); }