public virtual ApiPhoneNumberTypeResponseModel MapBOToModel( BOPhoneNumberType boPhoneNumberType) { var model = new ApiPhoneNumberTypeResponseModel(); model.SetProperties(boPhoneNumberType.PhoneNumberTypeID, boPhoneNumberType.ModifiedDate, boPhoneNumberType.Name); return(model); }
public void MapResponseToRequest() { var mapper = new ApiPhoneNumberTypeModelMapper(); var model = new ApiPhoneNumberTypeResponseModel(); model.SetProperties(1, DateTime.Parse("1/1/1987 12:00:00 AM"), "A"); ApiPhoneNumberTypeRequestModel response = mapper.MapResponseToRequest(model); response.ModifiedDate.Should().Be(DateTime.Parse("1/1/1987 12:00:00 AM")); 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()); ApiPhoneNumberTypeResponseModel response = await client.PhoneNumberTypeGetAsync(1); response.Should().NotBeNull(); }
public void MapBOToModel() { var mapper = new BOLPhoneNumberTypeMapper(); BOPhoneNumberType bo = new BOPhoneNumberType(); bo.SetProperties(1, DateTime.Parse("1/1/1987 12:00:00 AM"), "A"); ApiPhoneNumberTypeResponseModel response = mapper.MapBOToModel(bo); response.ModifiedDate.Should().Be(DateTime.Parse("1/1/1987 12:00:00 AM")); response.Name.Should().Be("A"); response.PhoneNumberTypeID.Should().Be(1); }
public async virtual Task <IActionResult> Get(int id) { ApiPhoneNumberTypeResponseModel response = await this.PhoneNumberTypeService.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()); ApiPhoneNumberTypeResponseModel model = await client.PhoneNumberTypeGetAsync(1); ApiPhoneNumberTypeModelMapper mapper = new ApiPhoneNumberTypeModelMapper(); UpdateResponse <ApiPhoneNumberTypeResponseModel> updateResponse = await client.PhoneNumberTypeUpdateAsync(model.PhoneNumberTypeID, mapper.MapResponseToRequest(model)); updateResponse.Record.Should().NotBeNull(); updateResponse.Success.Should().BeTrue(); }
public async void Get_null_record() { var mock = new ServiceMockFacade <IPhoneNumberTypeRepository>(); mock.RepositoryMock.Setup(x => x.Get(It.IsAny <int>())).Returns(Task.FromResult <PhoneNumberType>(null)); var service = new PhoneNumberTypeService(mock.LoggerMock.Object, mock.RepositoryMock.Object, mock.ModelValidatorMockFactory.PhoneNumberTypeModelValidatorMock.Object, mock.BOLMapperMockFactory.BOLPhoneNumberTypeMapperMock, mock.DALMapperMockFactory.DALPhoneNumberTypeMapperMock, mock.BOLMapperMockFactory.BOLPersonPhoneMapperMock, mock.DALMapperMockFactory.DALPersonPhoneMapperMock); ApiPhoneNumberTypeResponseModel response = await service.Get(default(int)); response.Should().BeNull(); mock.RepositoryMock.Verify(x => x.Get(It.IsAny <int>())); }
public async void Create_Errors() { PhoneNumberTypeControllerMockFacade mock = new PhoneNumberTypeControllerMockFacade(); var mockResponse = new Mock <CreateResponse <ApiPhoneNumberTypeResponseModel> >(new FluentValidation.Results.ValidationResult()); var mockRecord = new ApiPhoneNumberTypeResponseModel(); mockResponse.SetupGet(x => x.Success).Returns(false); mock.ServiceMock.Setup(x => x.Create(It.IsAny <ApiPhoneNumberTypeRequestModel>())).Returns(Task.FromResult <CreateResponse <ApiPhoneNumberTypeResponseModel> >(mockResponse.Object)); PhoneNumberTypeController controller = new PhoneNumberTypeController(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 ApiPhoneNumberTypeRequestModel()); response.Should().BeOfType <ObjectResult>(); (response as ObjectResult).StatusCode.Should().Be((int)HttpStatusCode.UnprocessableEntity); mock.ServiceMock.Verify(x => x.Create(It.IsAny <ApiPhoneNumberTypeRequestModel>())); }
public async void All_Exists() { PhoneNumberTypeControllerMockFacade mock = new PhoneNumberTypeControllerMockFacade(); var record = new ApiPhoneNumberTypeResponseModel(); var records = new List <ApiPhoneNumberTypeResponseModel>(); records.Add(record); mock.ServiceMock.Setup(x => x.All(It.IsAny <int>(), It.IsAny <int>())).Returns(Task.FromResult(records)); PhoneNumberTypeController controller = new PhoneNumberTypeController(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 <ApiPhoneNumberTypeResponseModel>; 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 <ApiPhoneNumberTypeRequestModel> patch) { ApiPhoneNumberTypeResponseModel record = await this.PhoneNumberTypeService.Get(id); if (record == null) { return(this.StatusCode(StatusCodes.Status404NotFound)); } else { ApiPhoneNumberTypeRequestModel model = await this.PatchModel(id, patch); UpdateResponse <ApiPhoneNumberTypeResponseModel> result = await this.PhoneNumberTypeService.Update(id, model); if (result.Success) { return(this.Ok(result)); } else { return(this.StatusCode(StatusCodes.Status422UnprocessableEntity, result)); } } }
public async void TestGet() { ApiPhoneNumberTypeResponseModel response = await this.Client.PhoneNumberTypeGetAsync(1); response.Should().NotBeNull(); }