コード例 #1
0
        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);
        }
コード例 #2
0
        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();
        }
コード例 #3
0
        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));
            }
        }
コード例 #4
0
        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));
            }
        }
コード例 #5
0
        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"));
        }
コード例 #6
0
        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"));
        }
コード例 #7
0
        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>()));
        }
コード例 #8
0
        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>()));
        }
コード例 #9
0
        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();
        }
コード例 #10
0
        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>()));
        }
コード例 #11
0
        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>()));
        }
コード例 #12
0
        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));
                }
            }
        }
コード例 #13
0
        public async void TestGet()
        {
            ApiCreditCardResponseModel response = await this.Client.CreditCardGetAsync(1);

            response.Should().NotBeNull();
        }