public async Task Customer_Null_BadRequest()
        {
            // Given
            var returnModel = new ReturnModel <int>();
            var model       = new ShoppingCartSave
            {
                CustomerInfo = new CustomerInfo
                {
                    CustomerId = 1
                }
            };

            var productServiceMock             = new Mock <IProductService>();
            var shoppingCartItemRepositoryMock = new Mock <IRepository <ShoppingCartItem> >();

            var customerServiceMock = new Mock <ICustomerService>();

            customerServiceMock.Setup(x => x.CheckCustomer(model.CustomerInfo.CustomerId.Value)).Returns(Task.FromResult(returnModel));

            var service    = new ShoppingCartItemService(productServiceMock.Object, customerServiceMock.Object, shoppingCartItemRepositoryMock.Object);
            var controller = new ShoppingCartController(service);

            // When
            var result = await controller.Post(model);

            // Assertions
            Assert.IsInstanceOfType(result, typeof(BadRequestObjectResult));
        }
        public async void Get_null_record()
        {
            var mock = new ServiceMockFacade <IShoppingCartItemRepository>();

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

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

            response.Should().BeNull();
            mock.RepositoryMock.Verify(x => x.Get(It.IsAny <int>()));
        }
        public async void ByShoppingCartIDProductID_Not_Exists()
        {
            var mock = new ServiceMockFacade <IShoppingCartItemRepository>();

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

            List <ApiShoppingCartItemResponseModel> response = await service.ByShoppingCartIDProductID(default(string), default(int));

            response.Should().BeEmpty();
            mock.RepositoryMock.Verify(x => x.ByShoppingCartIDProductID(It.IsAny <string>(), It.IsAny <int>()));
        }
        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 All()
        {
            var mock    = new ServiceMockFacade <IShoppingCartItemRepository>();
            var records = new List <ShoppingCartItem>();

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

            List <ApiShoppingCartItemResponseModel> response = await service.All();

            response.Should().HaveCount(1);
            mock.RepositoryMock.Verify(x => x.All(It.IsAny <int>(), It.IsAny <int>()));
        }
        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>()));
        }
        public async Task Product_Not_Valid_BadRequest()
        {
            // Given
            var returnModel      = new ReturnModel <ValidProductDto>();
            var validReturnModel = new ReturnModel <int>()
            {
                Result = new ReturnResult {
                    Status = ReturnStatus.Success
                }
            };
            var model = new ShoppingCartSave
            {
                ProductId    = 1,
                CustomerInfo = new CustomerInfo
                {
                    CustomerId = 1
                }
            };

            var shoppingCartItemRepositoryMock = new Mock <IRepository <ShoppingCartItem> >();

            var customerServiceMock = new Mock <ICustomerService>();

            customerServiceMock.Setup(x => x.CheckCustomer(model.CustomerInfo.CustomerId.Value)).Returns(Task.FromResult(validReturnModel));

            var productServiceMock = new Mock <IProductService>();

            productServiceMock.Setup(x => x.ValidForSale(model.ProductId)).Returns(Task.FromResult(returnModel));

            var service    = new ShoppingCartItemService(productServiceMock.Object, customerServiceMock.Object, shoppingCartItemRepositoryMock.Object);
            var controller = new ShoppingCartController(service);

            // When
            var result = await controller.Post(model);

            // Assertions
            Assert.IsInstanceOfType(result, typeof(BadRequestObjectResult));
        }