Пример #1
0
        private async Task <ApiProductVendorResponseModel> CreateRecord()
        {
            var model = new ApiProductVendorRequestModel();

            model.SetProperties(2, 2, 2m, DateTime.Parse("1/1/1988 12:00:00 AM"), 2, 2, DateTime.Parse("1/1/1988 12:00:00 AM"), 2, 2m, "B");
            CreateResponse <ApiProductVendorResponseModel> result = await this.Client.ProductVendorCreateAsync(model);

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

            if (result.Success)
            {
                return(this.Created($"{this.Settings.ExternalBaseUrl}/api/ProductVendors/{result.Record.ProductID}", result));
            }
            else
            {
                return(this.StatusCode(StatusCodes.Status422UnprocessableEntity, result));
            }
        }
Пример #3
0
 public async Task <ValidationResult> ValidateUpdateAsync(int id, ApiProductVendorRequestModel model)
 {
     this.AverageLeadTimeRules();
     this.BusinessEntityIDRules();
     this.LastReceiptCostRules();
     this.LastReceiptDateRules();
     this.MaxOrderQtyRules();
     this.MinOrderQtyRules();
     this.ModifiedDateRules();
     this.OnOrderQtyRules();
     this.StandardPriceRules();
     this.UnitMeasureCodeRules();
     return(await this.ValidateAsync(model, id));
 }
        private async Task <ApiProductVendorRequestModel> PatchModel(int id, JsonPatchDocument <ApiProductVendorRequestModel> patch)
        {
            var record = await this.ProductVendorService.Get(id);

            if (record == null)
            {
                return(null);
            }
            else
            {
                ApiProductVendorRequestModel request = this.ProductVendorModelMapper.MapResponseToRequest(record);
                patch.ApplyTo(request);
                return(request);
            }
        }
Пример #5
0
        public virtual async Task <CreateResponse <ApiProductVendorResponseModel> > Create(
            ApiProductVendorRequestModel model)
        {
            CreateResponse <ApiProductVendorResponseModel> response = new CreateResponse <ApiProductVendorResponseModel>(await this.productVendorModelValidator.ValidateCreateAsync(model));

            if (response.Success)
            {
                var bo     = this.bolProductVendorMapper.MapModelToBO(default(int), model);
                var record = await this.productVendorRepository.Create(this.dalProductVendorMapper.MapBOToEF(bo));

                response.SetRecord(this.bolProductVendorMapper.MapBOToModel(this.dalProductVendorMapper.MapEFToBO(record)));
            }

            return(response);
        }
Пример #6
0
        public async void Create()
        {
            var mock  = new ServiceMockFacade <IProductVendorRepository>();
            var model = new ApiProductVendorRequestModel();

            mock.RepositoryMock.Setup(x => x.Create(It.IsAny <ProductVendor>())).Returns(Task.FromResult(new ProductVendor()));
            var service = new ProductVendorService(mock.LoggerMock.Object,
                                                   mock.RepositoryMock.Object,
                                                   mock.ModelValidatorMockFactory.ProductVendorModelValidatorMock.Object,
                                                   mock.BOLMapperMockFactory.BOLProductVendorMapperMock,
                                                   mock.DALMapperMockFactory.DALProductVendorMapperMock);

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

            response.Should().NotBeNull();
            mock.ModelValidatorMockFactory.ProductVendorModelValidatorMock.Verify(x => x.ValidateCreateAsync(It.IsAny <ApiProductVendorRequestModel>()));
            mock.RepositoryMock.Verify(x => x.Create(It.IsAny <ProductVendor>()));
        }
Пример #7
0
        public async void Delete()
        {
            var mock  = new ServiceMockFacade <IProductVendorRepository>();
            var model = new ApiProductVendorRequestModel();

            mock.RepositoryMock.Setup(x => x.Delete(It.IsAny <int>())).Returns(Task.CompletedTask);
            var service = new ProductVendorService(mock.LoggerMock.Object,
                                                   mock.RepositoryMock.Object,
                                                   mock.ModelValidatorMockFactory.ProductVendorModelValidatorMock.Object,
                                                   mock.BOLMapperMockFactory.BOLProductVendorMapperMock,
                                                   mock.DALMapperMockFactory.DALProductVendorMapperMock);

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

            response.Should().NotBeNull();
            mock.RepositoryMock.Verify(x => x.Delete(It.IsAny <int>()));
            mock.ModelValidatorMockFactory.ProductVendorModelValidatorMock.Verify(x => x.ValidateDeleteAsync(It.IsAny <int>()));
        }
Пример #8
0
        public void MapResponseToRequest()
        {
            var mapper = new ApiProductVendorModelMapper();
            var model  = new ApiProductVendorResponseModel();

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

            response.AverageLeadTime.Should().Be(1);
            response.BusinessEntityID.Should().Be(1);
            response.LastReceiptCost.Should().Be(1m);
            response.LastReceiptDate.Should().Be(DateTime.Parse("1/1/1987 12:00:00 AM"));
            response.MaxOrderQty.Should().Be(1);
            response.MinOrderQty.Should().Be(1);
            response.ModifiedDate.Should().Be(DateTime.Parse("1/1/1987 12:00:00 AM"));
            response.OnOrderQty.Should().Be(1);
            response.StandardPrice.Should().Be(1m);
            response.UnitMeasureCode.Should().Be("A");
        }
Пример #9
0
        public virtual async Task <UpdateResponse <ApiProductVendorResponseModel> > Update(
            int productID,
            ApiProductVendorRequestModel model)
        {
            var validationResult = await this.productVendorModelValidator.ValidateUpdateAsync(productID, model);

            if (validationResult.IsValid)
            {
                var bo = this.bolProductVendorMapper.MapModelToBO(productID, model);
                await this.productVendorRepository.Update(this.dalProductVendorMapper.MapBOToEF(bo));

                var record = await this.productVendorRepository.Get(productID);

                return(new UpdateResponse <ApiProductVendorResponseModel>(this.bolProductVendorMapper.MapBOToModel(this.dalProductVendorMapper.MapEFToBO(record))));
            }
            else
            {
                return(new UpdateResponse <ApiProductVendorResponseModel>(validationResult));
            }
        }
Пример #10
0
        public virtual BOProductVendor MapModelToBO(
            int productID,
            ApiProductVendorRequestModel model
            )
        {
            BOProductVendor boProductVendor = new BOProductVendor();

            boProductVendor.SetProperties(
                productID,
                model.AverageLeadTime,
                model.BusinessEntityID,
                model.LastReceiptCost,
                model.LastReceiptDate,
                model.MaxOrderQty,
                model.MinOrderQty,
                model.ModifiedDate,
                model.OnOrderQty,
                model.StandardPrice,
                model.UnitMeasureCode);
            return(boProductVendor);
        }
        public virtual async Task <IActionResult> Update(int id, [FromBody] ApiProductVendorRequestModel model)
        {
            ApiProductVendorRequestModel request = await this.PatchModel(id, this.ProductVendorModelMapper.CreatePatch(model));

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

                if (result.Success)
                {
                    return(this.Ok(result));
                }
                else
                {
                    return(this.StatusCode(StatusCodes.Status422UnprocessableEntity, result));
                }
            }
        }
Пример #12
0
        public void CreatePatch()
        {
            var mapper = new ApiProductVendorModelMapper();
            var model  = new ApiProductVendorRequestModel();

            model.SetProperties(1, 1, 1m, DateTime.Parse("1/1/1987 12:00:00 AM"), 1, 1, DateTime.Parse("1/1/1987 12:00:00 AM"), 1, 1m, "A");

            JsonPatchDocument <ApiProductVendorRequestModel> patch = mapper.CreatePatch(model);
            var response = new ApiProductVendorRequestModel();

            patch.ApplyTo(response);
            response.AverageLeadTime.Should().Be(1);
            response.BusinessEntityID.Should().Be(1);
            response.LastReceiptCost.Should().Be(1m);
            response.LastReceiptDate.Should().Be(DateTime.Parse("1/1/1987 12:00:00 AM"));
            response.MaxOrderQty.Should().Be(1);
            response.MinOrderQty.Should().Be(1);
            response.ModifiedDate.Should().Be(DateTime.Parse("1/1/1987 12:00:00 AM"));
            response.OnOrderQty.Should().Be(1);
            response.StandardPrice.Should().Be(1m);
            response.UnitMeasureCode.Should().Be("A");
        }
        public virtual async Task <IActionResult> Patch(int id, [FromBody] JsonPatchDocument <ApiProductVendorRequestModel> patch)
        {
            ApiProductVendorResponseModel record = await this.ProductVendorService.Get(id);

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

                UpdateResponse <ApiProductVendorResponseModel> result = await this.ProductVendorService.Update(id, model);

                if (result.Success)
                {
                    return(this.Ok(result));
                }
                else
                {
                    return(this.StatusCode(StatusCodes.Status422UnprocessableEntity, result));
                }
            }
        }