public async void TestDelete() { var builder = new WebHostBuilder() .UseEnvironment("Production") .UseStartup <TestStartup>(); TestServer testServer = new TestServer(builder); var client = new ApiClient(testServer.CreateClient()); var createModel = new ApiTeacherRequestModel(); createModel.SetProperties(DateTime.Parse("1/1/1988 12:00:00 AM"), "B", "B", "B", "B", 1); CreateResponse <ApiTeacherResponseModel> createResult = await client.TeacherCreateAsync(createModel); createResult.Success.Should().BeTrue(); ApiTeacherResponseModel getResponse = await client.TeacherGetAsync(2); getResponse.Should().NotBeNull(); ActionResponse deleteResult = await client.TeacherDeleteAsync(2); deleteResult.Success.Should().BeTrue(); ApiTeacherResponseModel verifyResponse = await client.TeacherGetAsync(2); verifyResponse.Should().BeNull(); }
public virtual ApiTeacherResponseModel MapBOToModel( BOTeacher boTeacher) { var model = new ApiTeacherResponseModel(); model.SetProperties(boTeacher.Id, boTeacher.Birthday, boTeacher.Email, boTeacher.FirstName, boTeacher.LastName, boTeacher.Phone, boTeacher.StudioId); return(model); }
public async void TestGet() { var builder = new WebHostBuilder() .UseEnvironment("Production") .UseStartup <TestStartup>(); TestServer testServer = new TestServer(builder); var client = new ApiClient(testServer.CreateClient()); ApiTeacherResponseModel response = await client.TeacherGetAsync(1); response.Should().NotBeNull(); }
public async virtual Task <IActionResult> Get(int id) { ApiTeacherResponseModel response = await this.TeacherService.Get(id); if (response == null) { return(this.StatusCode(StatusCodes.Status404NotFound)); } else { return(this.Ok(response)); } }
public void MapResponseToRequest() { var mapper = new ApiTeacherModelMapper(); var model = new ApiTeacherResponseModel(); model.SetProperties(1, DateTime.Parse("1/1/1987 12:00:00 AM"), "A", "A", "A", "A", 1); ApiTeacherRequestModel response = mapper.MapResponseToRequest(model); response.Birthday.Should().Be(DateTime.Parse("1/1/1987 12:00:00 AM")); response.Email.Should().Be("A"); response.FirstName.Should().Be("A"); response.LastName.Should().Be("A"); response.Phone.Should().Be("A"); response.UserId.Should().Be(1); }
public void MapBOToModel() { var mapper = new BOLTeacherMapper(); BOTeacher bo = new BOTeacher(); bo.SetProperties(1, DateTime.Parse("1/1/1987 12:00:00 AM"), "A", "A", "A", "A", 1); ApiTeacherResponseModel response = mapper.MapBOToModel(bo); response.Birthday.Should().Be(DateTime.Parse("1/1/1987 12:00:00 AM")); response.Email.Should().Be("A"); response.FirstName.Should().Be("A"); response.Id.Should().Be(1); response.LastName.Should().Be("A"); response.Phone.Should().Be("A"); response.UserId.Should().Be(1); }
public async void TestUpdate() { var builder = new WebHostBuilder() .UseEnvironment("Production") .UseStartup <TestStartup>(); TestServer testServer = new TestServer(builder); var client = new ApiClient(testServer.CreateClient()); ApiTeacherResponseModel model = await client.TeacherGetAsync(1); ApiTeacherModelMapper mapper = new ApiTeacherModelMapper(); UpdateResponse <ApiTeacherResponseModel> updateResponse = await client.TeacherUpdateAsync(model.Id, mapper.MapResponseToRequest(model)); updateResponse.Record.Should().NotBeNull(); updateResponse.Success.Should().BeTrue(); }
public async void Get_null_record() { var mock = new ServiceMockFacade <ITeacherRepository>(); mock.RepositoryMock.Setup(x => x.Get(It.IsAny <int>())).Returns(Task.FromResult <Teacher>(null)); var service = new TeacherService(mock.LoggerMock.Object, mock.RepositoryMock.Object, mock.ModelValidatorMockFactory.TeacherModelValidatorMock.Object, mock.BOLMapperMockFactory.BOLTeacherMapperMock, mock.DALMapperMockFactory.DALTeacherMapperMock, mock.BOLMapperMockFactory.BOLRateMapperMock, mock.DALMapperMockFactory.DALRateMapperMock); ApiTeacherResponseModel response = await service.Get(default(int)); response.Should().BeNull(); mock.RepositoryMock.Verify(x => x.Get(It.IsAny <int>())); }
public async void Create_Errors() { TeacherControllerMockFacade mock = new TeacherControllerMockFacade(); var mockResponse = new Mock <CreateResponse <ApiTeacherResponseModel> >(new FluentValidation.Results.ValidationResult()); var mockRecord = new ApiTeacherResponseModel(); mockResponse.SetupGet(x => x.Success).Returns(false); mock.ServiceMock.Setup(x => x.Create(It.IsAny <ApiTeacherRequestModel>())).Returns(Task.FromResult <CreateResponse <ApiTeacherResponseModel> >(mockResponse.Object)); TeacherController controller = new TeacherController(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 ApiTeacherRequestModel()); response.Should().BeOfType <ObjectResult>(); (response as ObjectResult).StatusCode.Should().Be((int)HttpStatusCode.UnprocessableEntity); mock.ServiceMock.Verify(x => x.Create(It.IsAny <ApiTeacherRequestModel>())); }
public async void All_Exists() { TeacherControllerMockFacade mock = new TeacherControllerMockFacade(); var record = new ApiTeacherResponseModel(); var records = new List <ApiTeacherResponseModel>(); records.Add(record); mock.ServiceMock.Setup(x => x.All(It.IsAny <int>(), It.IsAny <int>())).Returns(Task.FromResult(records)); TeacherController controller = new TeacherController(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 <ApiTeacherResponseModel>; 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 <ApiTeacherRequestModel> patch) { ApiTeacherResponseModel record = await this.TeacherService.Get(id); if (record == null) { return(this.StatusCode(StatusCodes.Status404NotFound)); } else { ApiTeacherRequestModel model = await this.PatchModel(id, patch); UpdateResponse <ApiTeacherResponseModel> result = await this.TeacherService.Update(id, model); if (result.Success) { return(this.Ok(result)); } else { return(this.StatusCode(StatusCodes.Status422UnprocessableEntity, result)); } } }
public async void TestGet() { ApiTeacherResponseModel response = await this.Client.TeacherGetAsync(1); response.Should().NotBeNull(); }