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 ApiAirlineRequestModel(); createModel.SetProperties("B"); CreateResponse <ApiAirlineResponseModel> createResult = await client.AirlineCreateAsync(createModel); createResult.Success.Should().BeTrue(); ApiAirlineResponseModel getResponse = await client.AirlineGetAsync(2); getResponse.Should().NotBeNull(); ActionResponse deleteResult = await client.AirlineDeleteAsync(2); deleteResult.Success.Should().BeTrue(); ApiAirlineResponseModel verifyResponse = await client.AirlineGetAsync(2); verifyResponse.Should().BeNull(); }
public virtual ApiAirlineResponseModel MapBOToModel( BOAirline boAirline) { var model = new ApiAirlineResponseModel(); model.SetProperties(boAirline.Id, boAirline.Name); return(model); }
public void MapResponseToRequest() { var mapper = new ApiAirlineModelMapper(); var model = new ApiAirlineResponseModel(); model.SetProperties(1, "A"); ApiAirlineRequestModel response = mapper.MapResponseToRequest(model); response.Name.Should().Be("A"); }
public void MapBOToModel() { var mapper = new BOLAirlineMapper(); BOAirline bo = new BOAirline(); bo.SetProperties(1, "A"); ApiAirlineResponseModel response = mapper.MapBOToModel(bo); response.Id.Should().Be(1); response.Name.Should().Be("A"); }
public async void TestGet() { var builder = new WebHostBuilder() .UseEnvironment("Production") .UseStartup <TestStartup>(); TestServer testServer = new TestServer(builder); var client = new ApiClient(testServer.CreateClient()); ApiAirlineResponseModel response = await client.AirlineGetAsync(1); response.Should().NotBeNull(); }
public async virtual Task <IActionResult> Get(int id) { ApiAirlineResponseModel response = await this.AirlineService.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 <IAirlineRepository>(); mock.RepositoryMock.Setup(x => x.Get(It.IsAny <int>())).Returns(Task.FromResult <Airline>(null)); var service = new AirlineService(mock.LoggerMock.Object, mock.RepositoryMock.Object, mock.ModelValidatorMockFactory.AirlineModelValidatorMock.Object, mock.BOLMapperMockFactory.BOLAirlineMapperMock, mock.DALMapperMockFactory.DALAirlineMapperMock); ApiAirlineResponseModel response = await service.Get(default(int)); response.Should().BeNull(); mock.RepositoryMock.Verify(x => x.Get(It.IsAny <int>())); }
public async void TestUpdate() { var builder = new WebHostBuilder() .UseEnvironment("Production") .UseStartup <TestStartup>(); TestServer testServer = new TestServer(builder); var client = new ApiClient(testServer.CreateClient()); ApiAirlineResponseModel model = await client.AirlineGetAsync(1); ApiAirlineModelMapper mapper = new ApiAirlineModelMapper(); UpdateResponse <ApiAirlineResponseModel> updateResponse = await client.AirlineUpdateAsync(model.Id, mapper.MapResponseToRequest(model)); updateResponse.Record.Should().NotBeNull(); updateResponse.Success.Should().BeTrue(); }
public async void Create_Errors() { AirlineControllerMockFacade mock = new AirlineControllerMockFacade(); var mockResponse = new Mock <CreateResponse <ApiAirlineResponseModel> >(new FluentValidation.Results.ValidationResult()); var mockRecord = new ApiAirlineResponseModel(); mockResponse.SetupGet(x => x.Success).Returns(false); mock.ServiceMock.Setup(x => x.Create(It.IsAny <ApiAirlineRequestModel>())).Returns(Task.FromResult <CreateResponse <ApiAirlineResponseModel> >(mockResponse.Object)); AirlineController controller = new AirlineController(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 ApiAirlineRequestModel()); response.Should().BeOfType <ObjectResult>(); (response as ObjectResult).StatusCode.Should().Be((int)HttpStatusCode.UnprocessableEntity); mock.ServiceMock.Verify(x => x.Create(It.IsAny <ApiAirlineRequestModel>())); }
public async void All_Exists() { AirlineControllerMockFacade mock = new AirlineControllerMockFacade(); var record = new ApiAirlineResponseModel(); var records = new List <ApiAirlineResponseModel>(); records.Add(record); mock.ServiceMock.Setup(x => x.All(It.IsAny <int>(), It.IsAny <int>())).Returns(Task.FromResult(records)); AirlineController controller = new AirlineController(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 <ApiAirlineResponseModel>; 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 <ApiAirlineRequestModel> patch) { ApiAirlineResponseModel record = await this.AirlineService.Get(id); if (record == null) { return(this.StatusCode(StatusCodes.Status404NotFound)); } else { ApiAirlineRequestModel model = await this.PatchModel(id, patch); UpdateResponse <ApiAirlineResponseModel> result = await this.AirlineService.Update(id, model); if (result.Success) { return(this.Ok(result)); } else { return(this.StatusCode(StatusCodes.Status422UnprocessableEntity, result)); } } }
public async void TestGet() { ApiAirlineResponseModel response = await this.Client.AirlineGetAsync(1); response.Should().NotBeNull(); }