public void MapResponseToRequest()
        {
            var mapper = new ApiSalesOrderHeaderModelMapper();
            var model  = new ApiSalesOrderHeaderResponseModel();

            model.SetProperties(1, "A", 1, "A", "A", 1, 1, 1, DateTime.Parse("1/1/1987 12:00:00 AM"), 1m, DateTime.Parse("1/1/1987 12:00:00 AM"), true, DateTime.Parse("1/1/1987 12:00:00 AM"), "A", 1, Guid.Parse("8420cdcf-d595-ef65-66e7-dff9f98764da"), "A", 1, DateTime.Parse("1/1/1987 12:00:00 AM"), 1, 1, 1, 1m, 1m, 1, 1m);
            ApiSalesOrderHeaderRequestModel response = mapper.MapResponseToRequest(model);

            response.AccountNumber.Should().Be("A");
            response.BillToAddressID.Should().Be(1);
            response.Comment.Should().Be("A");
            response.CreditCardApprovalCode.Should().Be("A");
            response.CreditCardID.Should().Be(1);
            response.CurrencyRateID.Should().Be(1);
            response.CustomerID.Should().Be(1);
            response.DueDate.Should().Be(DateTime.Parse("1/1/1987 12:00:00 AM"));
            response.Freight.Should().Be(1m);
            response.ModifiedDate.Should().Be(DateTime.Parse("1/1/1987 12:00:00 AM"));
            response.OnlineOrderFlag.Should().Be(true);
            response.OrderDate.Should().Be(DateTime.Parse("1/1/1987 12:00:00 AM"));
            response.PurchaseOrderNumber.Should().Be("A");
            response.RevisionNumber.Should().Be(1);
            response.Rowguid.Should().Be(Guid.Parse("8420cdcf-d595-ef65-66e7-dff9f98764da"));
            response.SalesOrderNumber.Should().Be("A");
            response.SalesPersonID.Should().Be(1);
            response.ShipDate.Should().Be(DateTime.Parse("1/1/1987 12:00:00 AM"));
            response.ShipMethodID.Should().Be(1);
            response.ShipToAddressID.Should().Be(1);
            response.Status.Should().Be(1);
            response.SubTotal.Should().Be(1m);
            response.TaxAmt.Should().Be(1m);
            response.TerritoryID.Should().Be(1);
            response.TotalDue.Should().Be(1m);
        }
Exemplo n.º 2
0
 public async Task <ValidationResult> ValidateUpdateAsync(int id, ApiSalesOrderHeaderRequestModel model)
 {
     this.AccountNumberRules();
     this.BillToAddressIDRules();
     this.CommentRules();
     this.CreditCardApprovalCodeRules();
     this.CreditCardIDRules();
     this.CurrencyRateIDRules();
     this.CustomerIDRules();
     this.DueDateRules();
     this.FreightRules();
     this.ModifiedDateRules();
     this.OnlineOrderFlagRules();
     this.OrderDateRules();
     this.PurchaseOrderNumberRules();
     this.RevisionNumberRules();
     this.RowguidRules();
     this.SalesOrderNumberRules();
     this.SalesPersonIDRules();
     this.ShipDateRules();
     this.ShipMethodIDRules();
     this.ShipToAddressIDRules();
     this.StatusRules();
     this.SubTotalRules();
     this.TaxAmtRules();
     this.TerritoryIDRules();
     this.TotalDueRules();
     return(await this.ValidateAsync(model, id));
 }
Exemplo n.º 3
0
        private async Task <ApiSalesOrderHeaderResponseModel> CreateRecord()
        {
            var model = new ApiSalesOrderHeaderRequestModel();

            model.SetProperties("B", 2, "B", "B", 1, 1, 1, DateTime.Parse("1/1/1988 12:00:00 AM"), 2m, DateTime.Parse("1/1/1988 12:00:00 AM"), true, DateTime.Parse("1/1/1988 12:00:00 AM"), "B", 2, Guid.Parse("3842cac4-b9a0-8223-0dcc-509a6f75849b"), "B", 1, DateTime.Parse("1/1/1988 12:00:00 AM"), 2, 2, 2, 2m, 2m, 1, 2m);
            CreateResponse <ApiSalesOrderHeaderResponseModel> result = await this.Client.SalesOrderHeaderCreateAsync(model);

            result.Success.Should().BeTrue();
            return(result.Record);
        }
        public virtual async Task <IActionResult> Create([FromBody] ApiSalesOrderHeaderRequestModel model)
        {
            CreateResponse <ApiSalesOrderHeaderResponseModel> result = await this.SalesOrderHeaderService.Create(model);

            if (result.Success)
            {
                return(this.Created($"{this.Settings.ExternalBaseUrl}/api/SalesOrderHeaders/{result.Record.SalesOrderID}", result));
            }
            else
            {
                return(this.StatusCode(StatusCodes.Status422UnprocessableEntity, result));
            }
        }
        private async Task <ApiSalesOrderHeaderRequestModel> PatchModel(int id, JsonPatchDocument <ApiSalesOrderHeaderRequestModel> patch)
        {
            var record = await this.SalesOrderHeaderService.Get(id);

            if (record == null)
            {
                return(null);
            }
            else
            {
                ApiSalesOrderHeaderRequestModel request = this.SalesOrderHeaderModelMapper.MapResponseToRequest(record);
                patch.ApplyTo(request);
                return(request);
            }
        }
Exemplo n.º 6
0
        public virtual async Task <CreateResponse <ApiSalesOrderHeaderResponseModel> > Create(
            ApiSalesOrderHeaderRequestModel model)
        {
            CreateResponse <ApiSalesOrderHeaderResponseModel> response = new CreateResponse <ApiSalesOrderHeaderResponseModel>(await this.salesOrderHeaderModelValidator.ValidateCreateAsync(model));

            if (response.Success)
            {
                var bo     = this.bolSalesOrderHeaderMapper.MapModelToBO(default(int), model);
                var record = await this.salesOrderHeaderRepository.Create(this.dalSalesOrderHeaderMapper.MapBOToEF(bo));

                response.SetRecord(this.bolSalesOrderHeaderMapper.MapBOToModel(this.dalSalesOrderHeaderMapper.MapEFToBO(record)));
            }

            return(response);
        }
Exemplo n.º 7
0
        public virtual async Task <UpdateResponse <ApiSalesOrderHeaderResponseModel> > Update(
            int salesOrderID,
            ApiSalesOrderHeaderRequestModel model)
        {
            var validationResult = await this.salesOrderHeaderModelValidator.ValidateUpdateAsync(salesOrderID, model);

            if (validationResult.IsValid)
            {
                var bo = this.bolSalesOrderHeaderMapper.MapModelToBO(salesOrderID, model);
                await this.salesOrderHeaderRepository.Update(this.dalSalesOrderHeaderMapper.MapBOToEF(bo));

                var record = await this.salesOrderHeaderRepository.Get(salesOrderID);

                return(new UpdateResponse <ApiSalesOrderHeaderResponseModel>(this.bolSalesOrderHeaderMapper.MapBOToModel(this.dalSalesOrderHeaderMapper.MapEFToBO(record))));
            }
            else
            {
                return(new UpdateResponse <ApiSalesOrderHeaderResponseModel>(validationResult));
            }
        }
        public async void Create()
        {
            var mock  = new ServiceMockFacade <ISalesOrderHeaderRepository>();
            var model = new ApiSalesOrderHeaderRequestModel();

            mock.RepositoryMock.Setup(x => x.Create(It.IsAny <SalesOrderHeader>())).Returns(Task.FromResult(new SalesOrderHeader()));
            var service = new SalesOrderHeaderService(mock.LoggerMock.Object,
                                                      mock.RepositoryMock.Object,
                                                      mock.ModelValidatorMockFactory.SalesOrderHeaderModelValidatorMock.Object,
                                                      mock.BOLMapperMockFactory.BOLSalesOrderHeaderMapperMock,
                                                      mock.DALMapperMockFactory.DALSalesOrderHeaderMapperMock,
                                                      mock.BOLMapperMockFactory.BOLSalesOrderDetailMapperMock,
                                                      mock.DALMapperMockFactory.DALSalesOrderDetailMapperMock);

            CreateResponse <ApiSalesOrderHeaderResponseModel> response = await service.Create(model);

            response.Should().NotBeNull();
            mock.ModelValidatorMockFactory.SalesOrderHeaderModelValidatorMock.Verify(x => x.ValidateCreateAsync(It.IsAny <ApiSalesOrderHeaderRequestModel>()));
            mock.RepositoryMock.Verify(x => x.Create(It.IsAny <SalesOrderHeader>()));
        }
        public async void Delete()
        {
            var mock  = new ServiceMockFacade <ISalesOrderHeaderRepository>();
            var model = new ApiSalesOrderHeaderRequestModel();

            mock.RepositoryMock.Setup(x => x.Delete(It.IsAny <int>())).Returns(Task.CompletedTask);
            var service = new SalesOrderHeaderService(mock.LoggerMock.Object,
                                                      mock.RepositoryMock.Object,
                                                      mock.ModelValidatorMockFactory.SalesOrderHeaderModelValidatorMock.Object,
                                                      mock.BOLMapperMockFactory.BOLSalesOrderHeaderMapperMock,
                                                      mock.DALMapperMockFactory.DALSalesOrderHeaderMapperMock,
                                                      mock.BOLMapperMockFactory.BOLSalesOrderDetailMapperMock,
                                                      mock.DALMapperMockFactory.DALSalesOrderDetailMapperMock);

            ActionResponse response = await service.Delete(default(int));

            response.Should().NotBeNull();
            mock.RepositoryMock.Verify(x => x.Delete(It.IsAny <int>()));
            mock.ModelValidatorMockFactory.SalesOrderHeaderModelValidatorMock.Verify(x => x.ValidateDeleteAsync(It.IsAny <int>()));
        }
        public virtual async Task <IActionResult> Update(int id, [FromBody] ApiSalesOrderHeaderRequestModel model)
        {
            ApiSalesOrderHeaderRequestModel request = await this.PatchModel(id, this.SalesOrderHeaderModelMapper.CreatePatch(model));

            if (request == null)
            {
                return(this.StatusCode(StatusCodes.Status404NotFound));
            }
            else
            {
                UpdateResponse <ApiSalesOrderHeaderResponseModel> result = await this.SalesOrderHeaderService.Update(id, request);

                if (result.Success)
                {
                    return(this.Ok(result));
                }
                else
                {
                    return(this.StatusCode(StatusCodes.Status422UnprocessableEntity, result));
                }
            }
        }
        public virtual async Task <IActionResult> Patch(int id, [FromBody] JsonPatchDocument <ApiSalesOrderHeaderRequestModel> patch)
        {
            ApiSalesOrderHeaderResponseModel record = await this.SalesOrderHeaderService.Get(id);

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

                UpdateResponse <ApiSalesOrderHeaderResponseModel> result = await this.SalesOrderHeaderService.Update(id, model);

                if (result.Success)
                {
                    return(this.Ok(result));
                }
                else
                {
                    return(this.StatusCode(StatusCodes.Status422UnprocessableEntity, result));
                }
            }
        }
        public virtual BOSalesOrderHeader MapModelToBO(
            int salesOrderID,
            ApiSalesOrderHeaderRequestModel model
            )
        {
            BOSalesOrderHeader boSalesOrderHeader = new BOSalesOrderHeader();

            boSalesOrderHeader.SetProperties(
                salesOrderID,
                model.AccountNumber,
                model.BillToAddressID,
                model.Comment,
                model.CreditCardApprovalCode,
                model.CreditCardID,
                model.CurrencyRateID,
                model.CustomerID,
                model.DueDate,
                model.Freight,
                model.ModifiedDate,
                model.OnlineOrderFlag,
                model.OrderDate,
                model.PurchaseOrderNumber,
                model.RevisionNumber,
                model.Rowguid,
                model.SalesOrderNumber,
                model.SalesPersonID,
                model.ShipDate,
                model.ShipMethodID,
                model.ShipToAddressID,
                model.Status,
                model.SubTotal,
                model.TaxAmt,
                model.TerritoryID,
                model.TotalDue);
            return(boSalesOrderHeader);
        }