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 ApiCountryRequestModel(); createModel.SetProperties("B"); CreateResponse <ApiCountryResponseModel> createResult = await client.CountryCreateAsync(createModel); createResult.Success.Should().BeTrue(); ApiCountryResponseModel getResponse = await client.CountryGetAsync(2); getResponse.Should().NotBeNull(); ActionResponse deleteResult = await client.CountryDeleteAsync(2); deleteResult.Success.Should().BeTrue(); ApiCountryResponseModel verifyResponse = await client.CountryGetAsync(2); verifyResponse.Should().BeNull(); }
public virtual ApiCountryResponseModel MapBOToModel( BOCountry boCountry) { var model = new ApiCountryResponseModel(); model.SetProperties(boCountry.Id, boCountry.Name); return(model); }
public void MapResponseToRequest() { var mapper = new ApiCountryModelMapper(); var model = new ApiCountryResponseModel(); model.SetProperties(1, "A"); ApiCountryRequestModel response = mapper.MapResponseToRequest(model); response.Name.Should().Be("A"); }
public void MapBOToModel() { var mapper = new BOLCountryMapper(); BOCountry bo = new BOCountry(); bo.SetProperties(1, "A"); ApiCountryResponseModel 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()); ApiCountryResponseModel response = await client.CountryGetAsync(1); response.Should().NotBeNull(); }
public async virtual Task <IActionResult> Get(int id) { ApiCountryResponseModel response = await this.CountryService.Get(id); if (response == null) { return(this.StatusCode(StatusCodes.Status404NotFound)); } else { return(this.Ok(response)); } }
public async void TestUpdate() { var builder = new WebHostBuilder() .UseEnvironment("Production") .UseStartup <TestStartup>(); TestServer testServer = new TestServer(builder); var client = new ApiClient(testServer.CreateClient()); ApiCountryResponseModel model = await client.CountryGetAsync(1); ApiCountryModelMapper mapper = new ApiCountryModelMapper(); UpdateResponse <ApiCountryResponseModel> updateResponse = await client.CountryUpdateAsync(model.Id, mapper.MapResponseToRequest(model)); updateResponse.Record.Should().NotBeNull(); updateResponse.Success.Should().BeTrue(); }
public async void Get_null_record() { var mock = new ServiceMockFacade <ICountryRepository>(); mock.RepositoryMock.Setup(x => x.Get(It.IsAny <int>())).Returns(Task.FromResult <Country>(null)); var service = new CountryService(mock.LoggerMock.Object, mock.RepositoryMock.Object, mock.ModelValidatorMockFactory.CountryModelValidatorMock.Object, mock.BOLMapperMockFactory.BOLCountryMapperMock, mock.DALMapperMockFactory.DALCountryMapperMock, mock.BOLMapperMockFactory.BOLProvinceMapperMock, mock.DALMapperMockFactory.DALProvinceMapperMock); ApiCountryResponseModel response = await service.Get(default(int)); response.Should().BeNull(); mock.RepositoryMock.Verify(x => x.Get(It.IsAny <int>())); }
public async void Create_Errors() { CountryControllerMockFacade mock = new CountryControllerMockFacade(); var mockResponse = new Mock <CreateResponse <ApiCountryResponseModel> >(new FluentValidation.Results.ValidationResult()); var mockRecord = new ApiCountryResponseModel(); mockResponse.SetupGet(x => x.Success).Returns(false); mock.ServiceMock.Setup(x => x.Create(It.IsAny <ApiCountryRequestModel>())).Returns(Task.FromResult <CreateResponse <ApiCountryResponseModel> >(mockResponse.Object)); CountryController controller = new CountryController(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 ApiCountryRequestModel()); response.Should().BeOfType <ObjectResult>(); (response as ObjectResult).StatusCode.Should().Be((int)HttpStatusCode.UnprocessableEntity); mock.ServiceMock.Verify(x => x.Create(It.IsAny <ApiCountryRequestModel>())); }
public async void Get() { var mock = new ServiceMockFacade <ICountryRepository>(); var record = new Country(); mock.RepositoryMock.Setup(x => x.Get(It.IsAny <int>())).Returns(Task.FromResult(record)); var service = new CountryService(mock.LoggerMock.Object, mock.RepositoryMock.Object, mock.ModelValidatorMockFactory.CountryModelValidatorMock.Object, mock.BOLMapperMockFactory.BOLCountryMapperMock, mock.DALMapperMockFactory.DALCountryMapperMock, mock.BOLMapperMockFactory.BOLCountryRequirementMapperMock, mock.DALMapperMockFactory.DALCountryRequirementMapperMock, mock.BOLMapperMockFactory.BOLDestinationMapperMock, mock.DALMapperMockFactory.DALDestinationMapperMock); ApiCountryResponseModel response = await service.Get(default(int)); response.Should().NotBeNull(); mock.RepositoryMock.Verify(x => x.Get(It.IsAny <int>())); }
public async void All_Exists() { CountryControllerMockFacade mock = new CountryControllerMockFacade(); var record = new ApiCountryResponseModel(); var records = new List <ApiCountryResponseModel>(); records.Add(record); mock.ServiceMock.Setup(x => x.All(It.IsAny <int>(), It.IsAny <int>())).Returns(Task.FromResult(records)); CountryController controller = new CountryController(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 <ApiCountryResponseModel>; 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 <ApiCountryRequestModel> patch) { ApiCountryResponseModel record = await this.CountryService.Get(id); if (record == null) { return(this.StatusCode(StatusCodes.Status404NotFound)); } else { ApiCountryRequestModel model = await this.PatchModel(id, patch); UpdateResponse <ApiCountryResponseModel> result = await this.CountryService.Update(id, model); if (result.Success) { return(this.Ok(result)); } else { return(this.StatusCode(StatusCodes.Status422UnprocessableEntity, result)); } } }
public async void TestGet() { ApiCountryResponseModel response = await this.Client.CountryGetAsync(1); response.Should().NotBeNull(); }