public virtual ApiCreditCardResponseModel MapBOToModel( BOCreditCard boCreditCard) { var model = new ApiCreditCardResponseModel(); model.SetProperties(boCreditCard.CreditCardID, boCreditCard.CardNumber, boCreditCard.CardType, boCreditCard.ExpMonth, boCreditCard.ExpYear, boCreditCard.ModifiedDate); 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()); ApiCreditCardResponseModel response = await client.CreditCardGetAsync(1); response.Should().NotBeNull(); }
public async virtual Task <IActionResult> Get(int id) { ApiCreditCardResponseModel response = await this.CreditCardService.Get(id); if (response == null) { return(this.StatusCode(StatusCodes.Status404NotFound)); } else { return(this.Ok(response)); } }
public async virtual Task <IActionResult> ByCardNumber(string cardNumber) { ApiCreditCardResponseModel response = await this.CreditCardService.ByCardNumber(cardNumber); if (response == null) { return(this.StatusCode(StatusCodes.Status404NotFound)); } else { return(this.Ok(response)); } }
public void MapResponseToRequest() { var mapper = new ApiCreditCardModelMapper(); var model = new ApiCreditCardResponseModel(); model.SetProperties(1, "A", "A", 1, 1, DateTime.Parse("1/1/1987 12:00:00 AM")); ApiCreditCardRequestModel response = mapper.MapResponseToRequest(model); response.CardNumber.Should().Be("A"); response.CardType.Should().Be("A"); response.ExpMonth.Should().Be(1); response.ExpYear.Should().Be(1); response.ModifiedDate.Should().Be(DateTime.Parse("1/1/1987 12:00:00 AM")); }
public void MapBOToModel() { var mapper = new BOLCreditCardMapper(); BOCreditCard bo = new BOCreditCard(); bo.SetProperties(1, "A", "A", 1, 1, DateTime.Parse("1/1/1987 12:00:00 AM")); ApiCreditCardResponseModel response = mapper.MapBOToModel(bo); response.CardNumber.Should().Be("A"); response.CardType.Should().Be("A"); response.CreditCardID.Should().Be(1); response.ExpMonth.Should().Be(1); response.ExpYear.Should().Be(1); response.ModifiedDate.Should().Be(DateTime.Parse("1/1/1987 12:00:00 AM")); }
public async void Get_null_record() { var mock = new ServiceMockFacade <ICreditCardRepository>(); mock.RepositoryMock.Setup(x => x.Get(It.IsAny <int>())).Returns(Task.FromResult <CreditCard>(null)); var service = new CreditCardService(mock.LoggerMock.Object, mock.RepositoryMock.Object, mock.ModelValidatorMockFactory.CreditCardModelValidatorMock.Object, mock.BOLMapperMockFactory.BOLCreditCardMapperMock, mock.DALMapperMockFactory.DALCreditCardMapperMock, mock.BOLMapperMockFactory.BOLSalesOrderHeaderMapperMock, mock.DALMapperMockFactory.DALSalesOrderHeaderMapperMock); ApiCreditCardResponseModel response = await service.Get(default(int)); response.Should().BeNull(); mock.RepositoryMock.Verify(x => x.Get(It.IsAny <int>())); }
public async void ByCardNumber_Not_Exists() { var mock = new ServiceMockFacade <ICreditCardRepository>(); mock.RepositoryMock.Setup(x => x.ByCardNumber(It.IsAny <string>())).Returns(Task.FromResult <CreditCard>(null)); var service = new CreditCardService(mock.LoggerMock.Object, mock.RepositoryMock.Object, mock.ModelValidatorMockFactory.CreditCardModelValidatorMock.Object, mock.BOLMapperMockFactory.BOLCreditCardMapperMock, mock.DALMapperMockFactory.DALCreditCardMapperMock, mock.BOLMapperMockFactory.BOLSalesOrderHeaderMapperMock, mock.DALMapperMockFactory.DALSalesOrderHeaderMapperMock); ApiCreditCardResponseModel response = await service.ByCardNumber(default(string)); response.Should().BeNull(); mock.RepositoryMock.Verify(x => x.ByCardNumber(It.IsAny <string>())); }
public async void TestUpdate() { var builder = new WebHostBuilder() .UseEnvironment("Production") .UseStartup <TestStartup>(); TestServer testServer = new TestServer(builder); var client = new ApiClient(testServer.CreateClient()); ApiCreditCardResponseModel model = await client.CreditCardGetAsync(1); ApiCreditCardModelMapper mapper = new ApiCreditCardModelMapper(); UpdateResponse <ApiCreditCardResponseModel> updateResponse = await client.CreditCardUpdateAsync(model.CreditCardID, mapper.MapResponseToRequest(model)); updateResponse.Record.Should().NotBeNull(); updateResponse.Success.Should().BeTrue(); }
public async void Create_Errors() { CreditCardControllerMockFacade mock = new CreditCardControllerMockFacade(); var mockResponse = new Mock <CreateResponse <ApiCreditCardResponseModel> >(new FluentValidation.Results.ValidationResult()); var mockRecord = new ApiCreditCardResponseModel(); mockResponse.SetupGet(x => x.Success).Returns(false); mock.ServiceMock.Setup(x => x.Create(It.IsAny <ApiCreditCardRequestModel>())).Returns(Task.FromResult <CreateResponse <ApiCreditCardResponseModel> >(mockResponse.Object)); CreditCardController controller = new CreditCardController(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 ApiCreditCardRequestModel()); response.Should().BeOfType <ObjectResult>(); (response as ObjectResult).StatusCode.Should().Be((int)HttpStatusCode.UnprocessableEntity); mock.ServiceMock.Verify(x => x.Create(It.IsAny <ApiCreditCardRequestModel>())); }
public async void All_Exists() { CreditCardControllerMockFacade mock = new CreditCardControllerMockFacade(); var record = new ApiCreditCardResponseModel(); var records = new List <ApiCreditCardResponseModel>(); records.Add(record); mock.ServiceMock.Setup(x => x.All(It.IsAny <int>(), It.IsAny <int>())).Returns(Task.FromResult(records)); CreditCardController controller = new CreditCardController(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 <ApiCreditCardResponseModel>; 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 <ApiCreditCardRequestModel> patch) { ApiCreditCardResponseModel record = await this.CreditCardService.Get(id); if (record == null) { return(this.StatusCode(StatusCodes.Status404NotFound)); } else { ApiCreditCardRequestModel model = await this.PatchModel(id, patch); UpdateResponse <ApiCreditCardResponseModel> result = await this.CreditCardService.Update(id, model); if (result.Success) { return(this.Ok(result)); } else { return(this.StatusCode(StatusCodes.Status422UnprocessableEntity, result)); } } }
public async void TestGet() { ApiCreditCardResponseModel response = await this.Client.CreditCardGetAsync(1); response.Should().NotBeNull(); }