Beispiel #1
0
 public async Task <ValidationResult> ValidateUpdateAsync(int id, ApiShoppingCartItemRequestModel model)
 {
     this.DateCreatedRules();
     this.ModifiedDateRules();
     this.ProductIDRules();
     this.QuantityRules();
     this.ShoppingCartIDRules();
     return(await this.ValidateAsync(model, id));
 }
        private async Task <ApiShoppingCartItemResponseModel> CreateRecord(ApiClient client)
        {
            var model = new ApiShoppingCartItemRequestModel();

            model.SetProperties(DateTime.Parse("1/1/1988 12:00:00 AM"), DateTime.Parse("1/1/1988 12:00:00 AM"), 2, 2, "B");
            CreateResponse <ApiShoppingCartItemResponseModel> result = await client.ShoppingCartItemCreateAsync(model);

            result.Success.Should().BeTrue();
            return(result.Record);
        }
Beispiel #3
0
        public virtual async Task <IActionResult> Create([FromBody] ApiShoppingCartItemRequestModel model)
        {
            CreateResponse <ApiShoppingCartItemResponseModel> result = await this.ShoppingCartItemService.Create(model);

            if (result.Success)
            {
                return(this.Created($"{this.Settings.ExternalBaseUrl}/api/ShoppingCartItems/{result.Record.ShoppingCartItemID}", result));
            }
            else
            {
                return(this.StatusCode(StatusCodes.Status422UnprocessableEntity, result));
            }
        }
        public void MapModelToBO()
        {
            var mapper = new BOLShoppingCartItemMapper();
            ApiShoppingCartItemRequestModel model = new ApiShoppingCartItemRequestModel();

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

            response.DateCreated.Should().Be(DateTime.Parse("1/1/1987 12:00:00 AM"));
            response.ModifiedDate.Should().Be(DateTime.Parse("1/1/1987 12:00:00 AM"));
            response.ProductID.Should().Be(1);
            response.Quantity.Should().Be(1);
            response.ShoppingCartID.Should().Be("A");
        }
Beispiel #5
0
        private async Task <ApiShoppingCartItemRequestModel> PatchModel(int id, JsonPatchDocument <ApiShoppingCartItemRequestModel> patch)
        {
            var record = await this.ShoppingCartItemService.Get(id);

            if (record == null)
            {
                return(null);
            }
            else
            {
                ApiShoppingCartItemRequestModel request = this.ShoppingCartItemModelMapper.MapResponseToRequest(record);
                patch.ApplyTo(request);
                return(request);
            }
        }
Beispiel #6
0
        public virtual async Task <CreateResponse <ApiShoppingCartItemResponseModel> > Create(
            ApiShoppingCartItemRequestModel model)
        {
            CreateResponse <ApiShoppingCartItemResponseModel> response = new CreateResponse <ApiShoppingCartItemResponseModel>(await this.ShoppingCartItemModelValidator.ValidateCreateAsync(model));

            if (response.Success)
            {
                var bo     = this.BolShoppingCartItemMapper.MapModelToBO(default(int), model);
                var record = await this.ShoppingCartItemRepository.Create(this.DalShoppingCartItemMapper.MapBOToEF(bo));

                response.SetRecord(this.BolShoppingCartItemMapper.MapBOToModel(this.DalShoppingCartItemMapper.MapEFToBO(record)));
            }

            return(response);
        }
Beispiel #7
0
        public virtual BOShoppingCartItem MapModelToBO(
            int shoppingCartItemID,
            ApiShoppingCartItemRequestModel model
            )
        {
            BOShoppingCartItem boShoppingCartItem = new BOShoppingCartItem();

            boShoppingCartItem.SetProperties(
                shoppingCartItemID,
                model.DateCreated,
                model.ModifiedDate,
                model.ProductID,
                model.Quantity,
                model.ShoppingCartID);
            return(boShoppingCartItem);
        }
Beispiel #8
0
        public void CreatePatch()
        {
            var mapper = new ApiShoppingCartItemModelMapper();
            var model  = new ApiShoppingCartItemRequestModel();

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

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

            patch.ApplyTo(response);
            response.DateCreated.Should().Be(DateTime.Parse("1/1/1987 12:00:00 AM"));
            response.ModifiedDate.Should().Be(DateTime.Parse("1/1/1987 12:00:00 AM"));
            response.ProductID.Should().Be(1);
            response.Quantity.Should().Be(1);
            response.ShoppingCartID.Should().Be("A");
        }
        public async void Create()
        {
            var mock  = new ServiceMockFacade <IShoppingCartItemRepository>();
            var model = new ApiShoppingCartItemRequestModel();

            mock.RepositoryMock.Setup(x => x.Create(It.IsAny <ShoppingCartItem>())).Returns(Task.FromResult(new ShoppingCartItem()));
            var service = new ShoppingCartItemService(mock.LoggerMock.Object,
                                                      mock.RepositoryMock.Object,
                                                      mock.ModelValidatorMockFactory.ShoppingCartItemModelValidatorMock.Object,
                                                      mock.BOLMapperMockFactory.BOLShoppingCartItemMapperMock,
                                                      mock.DALMapperMockFactory.DALShoppingCartItemMapperMock);

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

            response.Should().NotBeNull();
            mock.ModelValidatorMockFactory.ShoppingCartItemModelValidatorMock.Verify(x => x.ValidateCreateAsync(It.IsAny <ApiShoppingCartItemRequestModel>()));
            mock.RepositoryMock.Verify(x => x.Create(It.IsAny <ShoppingCartItem>()));
        }
        public async void Delete()
        {
            var mock  = new ServiceMockFacade <IShoppingCartItemRepository>();
            var model = new ApiShoppingCartItemRequestModel();

            mock.RepositoryMock.Setup(x => x.Delete(It.IsAny <int>())).Returns(Task.CompletedTask);
            var service = new ShoppingCartItemService(mock.LoggerMock.Object,
                                                      mock.RepositoryMock.Object,
                                                      mock.ModelValidatorMockFactory.ShoppingCartItemModelValidatorMock.Object,
                                                      mock.BOLMapperMockFactory.BOLShoppingCartItemMapperMock,
                                                      mock.DALMapperMockFactory.DALShoppingCartItemMapperMock);

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

            response.Should().NotBeNull();
            mock.RepositoryMock.Verify(x => x.Delete(It.IsAny <int>()));
            mock.ModelValidatorMockFactory.ShoppingCartItemModelValidatorMock.Verify(x => x.ValidateDeleteAsync(It.IsAny <int>()));
        }
Beispiel #11
0
        public virtual async Task <UpdateResponse <ApiShoppingCartItemResponseModel> > Update(
            int shoppingCartItemID,
            ApiShoppingCartItemRequestModel model)
        {
            var validationResult = await this.ShoppingCartItemModelValidator.ValidateUpdateAsync(shoppingCartItemID, model);

            if (validationResult.IsValid)
            {
                var bo = this.BolShoppingCartItemMapper.MapModelToBO(shoppingCartItemID, model);
                await this.ShoppingCartItemRepository.Update(this.DalShoppingCartItemMapper.MapBOToEF(bo));

                var record = await this.ShoppingCartItemRepository.Get(shoppingCartItemID);

                return(new UpdateResponse <ApiShoppingCartItemResponseModel>(this.BolShoppingCartItemMapper.MapBOToModel(this.DalShoppingCartItemMapper.MapEFToBO(record))));
            }
            else
            {
                return(new UpdateResponse <ApiShoppingCartItemResponseModel>(validationResult));
            }
        }
Beispiel #12
0
        public virtual async Task <IActionResult> Update(int id, [FromBody] ApiShoppingCartItemRequestModel model)
        {
            ApiShoppingCartItemRequestModel request = await this.PatchModel(id, this.ShoppingCartItemModelMapper.CreatePatch(model));

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

                if (result.Success)
                {
                    return(this.Ok(result));
                }
                else
                {
                    return(this.StatusCode(StatusCodes.Status422UnprocessableEntity, result));
                }
            }
        }
Beispiel #13
0
        public virtual async Task <IActionResult> Patch(int id, [FromBody] JsonPatchDocument <ApiShoppingCartItemRequestModel> patch)
        {
            ApiShoppingCartItemResponseModel record = await this.ShoppingCartItemService.Get(id);

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

                UpdateResponse <ApiShoppingCartItemResponseModel> result = await this.ShoppingCartItemService.Update(id, model);

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