public void Setup()
        {
            var mapperConfig = new MapperConfiguration(cfg =>
            {
                cfg.AddProfile(new MapperProfile());
            });

            _mapper = mapperConfig.CreateMapper();

            cartEFServiceMock     = new Mock <ICartEFService>();
            productEFServiceMock  = new Mock <IProductEFService>();
            categoryEFServiceMock = new Mock <ICategoryEFService>();

            //Mock Setups
            cartEFServiceMock.Setup(c => c.GetCartAsync(It.IsAny <int>())).Returns(Task.FromResult(MockModels.MockCartModel()));
            cartEFServiceMock.Setup(c => c.AddCartAsync(It.IsAny <CartModel>())).Returns(Task.FromResult(CartId));
            cartEFServiceMock.Setup(c => c.AddCartDetailAsync(It.IsAny <CartDetailModel>())).Returns(Task.FromResult(CartDetailId));
            cartEFServiceMock.Setup(c => c.SaveCartCampaignAsync(It.IsAny <CartCampaignModel>(), It.IsAny <int>()));
            cartEFServiceMock.Setup(c => c.SaveCartCouponAsync(It.IsAny <CartCouponModel>(), It.IsAny <int>()));
            cartEFServiceMock.Setup(c => c.GetCartCampaignAsync(It.IsAny <int>())).Returns(Task.FromResult(MockModels.MockListCartCampaignModel()));
            cartEFServiceMock.Setup(c => c.GetCartCouponAsync(It.IsAny <int>())).Returns(Task.FromResult(MockModels.MockCartCouponModel()));
            cartEFServiceMock.Setup(c => c.GetCartDeliveriesAsync(It.IsAny <int>())).Returns(Task.FromResult(MockModels.MockCartDeliveries()));
            cartEFServiceMock.Setup(c => c.GetCartDetailsAsync(It.IsAny <int>())).Returns(Task.FromResult(MockModels.MockListCartDetailModel()));

            productEFServiceMock.Setup(p => p.GetProductAsync(It.IsAny <int>())).Returns(Task.FromResult(MockModels.MockProductModel()));

            categoryEFServiceMock.Setup(c => c.GetCategoryAsync(It.IsAny <int>())).Returns(Task.FromResult(MockModels.MockCategoryModel()));

            _cartDTO = _mapper.Map <CartDTO>(MockModels.MockCartModel());

            cart = new Cart(cartEFServiceMock.Object, _mapper, productEFServiceMock.Object, categoryEFServiceMock.Object);
        }
Esempio n. 2
0
        public async Task CalculateForTest()
        {
            double deliveryCost = await delivery.GetDeliveryCostAsync(_mapper.Map <CartDTO>(MockModels.MockCartModel()));

            Assert.IsTrue(deliveryCost > 0);
        }
Esempio n. 3
0
        public void Setup()
        {
            deliveryEFServiceMock = new Mock <IDeliveryEFService>();
            deliveryEFServiceMock.Setup(d => d.AddDeliveryAsync(It.IsAny <DeliveryModel>())).Returns(Task.FromResult(DeliveryModelId));
            deliveryEFServiceMock.Setup(d => d.GetDeliveriesAsync(It.IsAny <int>())).Returns(Task.FromResult(MockModels.MockCartDeliveries()));

            cartEFServiceMock = new Mock <ICartEFService>();
            cartEFServiceMock.Setup(cef => cef.GetCartAsync(It.IsAny <int>())).Returns(Task.FromResult(MockModels.MockCartModel()));

            productEFServiceMock = new Mock <IProductEFService>();
            productEFServiceMock.Setup(p => p.GetProductAsync(It.IsAny <int>())).Returns(Task.FromResult(MockModels.MockProductModel()));

            categoryEFServiceMock = new Mock <ICategoryEFService>();
            categoryEFServiceMock.Setup(c => c.GetCategoryAsync(It.IsAny <int>())).Returns(Task.FromResult(MockModels.MockCategoryModel()));

            var mapperConfig = new MapperConfiguration(cfg =>
            {
                cfg.AddProfile(new MapperProfile());
            });

            _mapper = mapperConfig.CreateMapper();

            delivery = new Delivery(deliveryEFServiceMock.Object, cartEFServiceMock.Object, productEFServiceMock.Object, categoryEFServiceMock.Object, _mapper);
        }
        public async Task CreateCartTest()
        {
            int cartId = await cart.CreateCartAsync(_mapper.Map <CartDTO>(MockModels.MockCartModel()));

            Assert.AreEqual(cartId, CartId);
        }