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 ApiDestinationRequestModel(); createModel.SetProperties(1, "B", 2); CreateResponse <ApiDestinationResponseModel> createResult = await client.DestinationCreateAsync(createModel); createResult.Success.Should().BeTrue(); ApiDestinationResponseModel getResponse = await client.DestinationGetAsync(2); getResponse.Should().NotBeNull(); ActionResponse deleteResult = await client.DestinationDeleteAsync(2); deleteResult.Success.Should().BeTrue(); ApiDestinationResponseModel verifyResponse = await client.DestinationGetAsync(2); verifyResponse.Should().BeNull(); }
public virtual ApiDestinationResponseModel MapBOToModel( BODestination boDestination) { var model = new ApiDestinationResponseModel(); model.SetProperties(boDestination.Id, boDestination.CountryId, boDestination.Name, boDestination.Order); 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()); ApiDestinationResponseModel response = await client.DestinationGetAsync(1); response.Should().NotBeNull(); }
public void MapResponseToRequest() { var mapper = new ApiDestinationModelMapper(); var model = new ApiDestinationResponseModel(); model.SetProperties(1, 1, "A", 1); ApiDestinationRequestModel response = mapper.MapResponseToRequest(model); response.CountryId.Should().Be(1); response.Name.Should().Be("A"); response.Order.Should().Be(1); }
public async virtual Task <IActionResult> Get(int id) { ApiDestinationResponseModel response = await this.DestinationService.Get(id); if (response == null) { return(this.StatusCode(StatusCodes.Status404NotFound)); } else { return(this.Ok(response)); } }
public void MapBOToModel() { var mapper = new BOLDestinationMapper(); BODestination bo = new BODestination(); bo.SetProperties(1, 1, "A", 1); ApiDestinationResponseModel response = mapper.MapBOToModel(bo); response.CountryId.Should().Be(1); response.Id.Should().Be(1); response.Name.Should().Be("A"); response.Order.Should().Be(1); }
public async void Get_null_record() { var mock = new ServiceMockFacade <IDestinationRepository>(); mock.RepositoryMock.Setup(x => x.Get(It.IsAny <int>())).Returns(Task.FromResult <Destination>(null)); var service = new DestinationService(mock.LoggerMock.Object, mock.RepositoryMock.Object, mock.ModelValidatorMockFactory.DestinationModelValidatorMock.Object, mock.BOLMapperMockFactory.BOLDestinationMapperMock, mock.DALMapperMockFactory.DALDestinationMapperMock); ApiDestinationResponseModel 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()); ApiDestinationResponseModel model = await client.DestinationGetAsync(1); ApiDestinationModelMapper mapper = new ApiDestinationModelMapper(); UpdateResponse <ApiDestinationResponseModel> updateResponse = await client.DestinationUpdateAsync(model.Id, mapper.MapResponseToRequest(model)); updateResponse.Record.Should().NotBeNull(); updateResponse.Success.Should().BeTrue(); }
public async void Create_Errors() { DestinationControllerMockFacade mock = new DestinationControllerMockFacade(); var mockResponse = new Mock <CreateResponse <ApiDestinationResponseModel> >(new FluentValidation.Results.ValidationResult()); var mockRecord = new ApiDestinationResponseModel(); mockResponse.SetupGet(x => x.Success).Returns(false); mock.ServiceMock.Setup(x => x.Create(It.IsAny <ApiDestinationRequestModel>())).Returns(Task.FromResult <CreateResponse <ApiDestinationResponseModel> >(mockResponse.Object)); DestinationController controller = new DestinationController(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 ApiDestinationRequestModel()); response.Should().BeOfType <ObjectResult>(); (response as ObjectResult).StatusCode.Should().Be((int)HttpStatusCode.UnprocessableEntity); mock.ServiceMock.Verify(x => x.Create(It.IsAny <ApiDestinationRequestModel>())); }
public async void All_Exists() { DestinationControllerMockFacade mock = new DestinationControllerMockFacade(); var record = new ApiDestinationResponseModel(); var records = new List <ApiDestinationResponseModel>(); records.Add(record); mock.ServiceMock.Setup(x => x.All(It.IsAny <int>(), It.IsAny <int>())).Returns(Task.FromResult(records)); DestinationController controller = new DestinationController(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 <ApiDestinationResponseModel>; 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 <ApiDestinationRequestModel> patch) { ApiDestinationResponseModel record = await this.DestinationService.Get(id); if (record == null) { return(this.StatusCode(StatusCodes.Status404NotFound)); } else { ApiDestinationRequestModel model = await this.PatchModel(id, patch); UpdateResponse <ApiDestinationResponseModel> result = await this.DestinationService.Update(id, model); if (result.Success) { return(this.Ok(result)); } else { return(this.StatusCode(StatusCodes.Status422UnprocessableEntity, result)); } } }
public async void TestGet() { ApiDestinationResponseModel response = await this.Client.DestinationGetAsync(1); response.Should().NotBeNull(); }