コード例 #1
0
        public virtual ApiVendorResponseModel MapBOToModel(
            BOVendor boVendor)
        {
            var model = new ApiVendorResponseModel();

            model.SetProperties(boVendor.BusinessEntityID, boVendor.AccountNumber, boVendor.ActiveFlag, boVendor.CreditRating, boVendor.ModifiedDate, boVendor.Name, boVendor.PreferredVendorStatu, boVendor.PurchasingWebServiceURL);

            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());
            ApiVendorResponseModel response = await client.VendorGetAsync(1);

            response.Should().NotBeNull();
        }
コード例 #3
0
        public async virtual Task <IActionResult> Get(int id)
        {
            ApiVendorResponseModel response = await this.VendorService.Get(id);

            if (response == null)
            {
                return(this.StatusCode(StatusCodes.Status404NotFound));
            }
            else
            {
                return(this.Ok(response));
            }
        }
コード例 #4
0
        public async virtual Task <IActionResult> ByAccountNumber(string accountNumber)
        {
            ApiVendorResponseModel response = await this.VendorService.ByAccountNumber(accountNumber);

            if (response == null)
            {
                return(this.StatusCode(StatusCodes.Status404NotFound));
            }
            else
            {
                return(this.Ok(response));
            }
        }
コード例 #5
0
        public void MapResponseToRequest()
        {
            var mapper = new ApiVendorModelMapper();
            var model  = new ApiVendorResponseModel();

            model.SetProperties(1, "A", true, 1, DateTime.Parse("1/1/1987 12:00:00 AM"), "A", true, "A");
            ApiVendorRequestModel response = mapper.MapResponseToRequest(model);

            response.AccountNumber.Should().Be("A");
            response.ActiveFlag.Should().Be(true);
            response.CreditRating.Should().Be(1);
            response.ModifiedDate.Should().Be(DateTime.Parse("1/1/1987 12:00:00 AM"));
            response.Name.Should().Be("A");
            response.PreferredVendorStatu.Should().Be(true);
            response.PurchasingWebServiceURL.Should().Be("A");
        }
コード例 #6
0
        public void MapBOToModel()
        {
            var      mapper = new BOLVendorMapper();
            BOVendor bo     = new BOVendor();

            bo.SetProperties(1, "A", true, 1, DateTime.Parse("1/1/1987 12:00:00 AM"), "A", true, "A");
            ApiVendorResponseModel response = mapper.MapBOToModel(bo);

            response.AccountNumber.Should().Be("A");
            response.ActiveFlag.Should().Be(true);
            response.BusinessEntityID.Should().Be(1);
            response.CreditRating.Should().Be(1);
            response.ModifiedDate.Should().Be(DateTime.Parse("1/1/1987 12:00:00 AM"));
            response.Name.Should().Be("A");
            response.PreferredVendorStatu.Should().Be(true);
            response.PurchasingWebServiceURL.Should().Be("A");
        }
コード例 #7
0
        public async void TestUpdate()
        {
            var builder = new WebHostBuilder()
                          .UseEnvironment("Production")
                          .UseStartup <TestStartup>();
            TestServer testServer = new TestServer(builder);

            var client = new ApiClient(testServer.CreateClient());

            ApiVendorResponseModel model = await client.VendorGetAsync(1);

            ApiVendorModelMapper mapper = new ApiVendorModelMapper();

            UpdateResponse <ApiVendorResponseModel> updateResponse = await client.VendorUpdateAsync(model.BusinessEntityID, mapper.MapResponseToRequest(model));

            updateResponse.Record.Should().NotBeNull();
            updateResponse.Success.Should().BeTrue();
        }
コード例 #8
0
        public async void Get_null_record()
        {
            var mock = new ServiceMockFacade <IVendorRepository>();

            mock.RepositoryMock.Setup(x => x.Get(It.IsAny <int>())).Returns(Task.FromResult <Vendor>(null));
            var service = new VendorService(mock.LoggerMock.Object,
                                            mock.RepositoryMock.Object,
                                            mock.ModelValidatorMockFactory.VendorModelValidatorMock.Object,
                                            mock.BOLMapperMockFactory.BOLVendorMapperMock,
                                            mock.DALMapperMockFactory.DALVendorMapperMock,
                                            mock.BOLMapperMockFactory.BOLProductVendorMapperMock,
                                            mock.DALMapperMockFactory.DALProductVendorMapperMock,
                                            mock.BOLMapperMockFactory.BOLPurchaseOrderHeaderMapperMock,
                                            mock.DALMapperMockFactory.DALPurchaseOrderHeaderMapperMock);

            ApiVendorResponseModel response = await service.Get(default(int));

            response.Should().BeNull();
            mock.RepositoryMock.Verify(x => x.Get(It.IsAny <int>()));
        }
コード例 #9
0
        public async void ByAccountNumber_Not_Exists()
        {
            var mock = new ServiceMockFacade <IVendorRepository>();

            mock.RepositoryMock.Setup(x => x.ByAccountNumber(It.IsAny <string>())).Returns(Task.FromResult <Vendor>(null));
            var service = new VendorService(mock.LoggerMock.Object,
                                            mock.RepositoryMock.Object,
                                            mock.ModelValidatorMockFactory.VendorModelValidatorMock.Object,
                                            mock.BOLMapperMockFactory.BOLVendorMapperMock,
                                            mock.DALMapperMockFactory.DALVendorMapperMock,
                                            mock.BOLMapperMockFactory.BOLProductVendorMapperMock,
                                            mock.DALMapperMockFactory.DALProductVendorMapperMock,
                                            mock.BOLMapperMockFactory.BOLPurchaseOrderHeaderMapperMock,
                                            mock.DALMapperMockFactory.DALPurchaseOrderHeaderMapperMock);

            ApiVendorResponseModel response = await service.ByAccountNumber(default(string));

            response.Should().BeNull();
            mock.RepositoryMock.Verify(x => x.ByAccountNumber(It.IsAny <string>()));
        }
コード例 #10
0
        public async void Create_Errors()
        {
            VendorControllerMockFacade mock = new VendorControllerMockFacade();

            var mockResponse = new Mock <CreateResponse <ApiVendorResponseModel> >(new FluentValidation.Results.ValidationResult());
            var mockRecord   = new ApiVendorResponseModel();

            mockResponse.SetupGet(x => x.Success).Returns(false);

            mock.ServiceMock.Setup(x => x.Create(It.IsAny <ApiVendorRequestModel>())).Returns(Task.FromResult <CreateResponse <ApiVendorResponseModel> >(mockResponse.Object));
            VendorController controller = new VendorController(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 ApiVendorRequestModel());

            response.Should().BeOfType <ObjectResult>();
            (response as ObjectResult).StatusCode.Should().Be((int)HttpStatusCode.UnprocessableEntity);
            mock.ServiceMock.Verify(x => x.Create(It.IsAny <ApiVendorRequestModel>()));
        }
コード例 #11
0
        public async void All_Exists()
        {
            VendorControllerMockFacade mock = new VendorControllerMockFacade();
            var record  = new ApiVendorResponseModel();
            var records = new List <ApiVendorResponseModel>();

            records.Add(record);
            mock.ServiceMock.Setup(x => x.All(It.IsAny <int>(), It.IsAny <int>())).Returns(Task.FromResult(records));
            VendorController controller = new VendorController(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 <ApiVendorResponseModel>;

            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 <ApiVendorRequestModel> patch)
        {
            ApiVendorResponseModel record = await this.VendorService.Get(id);

            if (record == null)
            {
                return(this.StatusCode(StatusCodes.Status404NotFound));
            }
            else
            {
                ApiVendorRequestModel model = await this.PatchModel(id, patch);

                UpdateResponse <ApiVendorResponseModel> result = await this.VendorService.Update(id, model);

                if (result.Success)
                {
                    return(this.Ok(result));
                }
                else
                {
                    return(this.StatusCode(StatusCodes.Status422UnprocessableEntity, result));
                }
            }
        }
コード例 #13
0
        public async void TestGet()
        {
            ApiVendorResponseModel response = await this.Client.VendorGetAsync(1);

            response.Should().NotBeNull();
        }