Пример #1
0
        public void CreateAndExecutePayment()
        {
            AppSettingsReader appSettingsReader = new AppSettingsReader();
            string            clientId          = (string)appSettingsReader.GetValue("clientId", typeof(string));
            string            clientSecret      = (string)appSettingsReader.GetValue("clientSecret", typeof(string));
            var apicontext = PayPalConfiguration.GetAPIContext(clientId, clientSecret);

            PaymentController controller = new PaymentController();
            var          guid            = Convert.ToString((new Random()).Next(100000));
            string       baseURI         = "http://localhost:37256/Paypal/PayWithPayPal?guid=" + guid;
            BouquetOrder bouquet         = new BouquetOrder(1, 1, new Bouquet(6, "gardenia", 2.00, 0));
            var          payment         = controller.CreatePayment(apicontext, baseURI, bouquet);

            var context = new Mock.MockHttpContext();

            context.m_request.m_queryString.Add("PayerID", guid);
            context.m_request.m_queryString.Add("guid", guid);
            context.Session.Add(guid, payment.id);

            controller.ControllerContext = new ControllerContext {
                HttpContext = context, RouteData = new RouteData()
            };
            var result = controller.ExecutePayment(apicontext, guid, payment.id);

            Assert.IsNotNull(apicontext, "PayPal API context is null");
            Assert.IsNotNull(payment.id, "Fail to create payment");
            //must be failed because the data are fake.
            Assert.IsTrue(result.state.ToLower() != "approved", result.state.ToLower());
        }
Пример #2
0
        public void CanGetSummaryViewModel()
        {
            IRepository <Basket>  baskets  = new Mock.MockContext <Basket>();
            IRepository <Product> products = new Mock.MockContext <Product>();

            products.Insert(new Product()
            {
                Id = "1", Price = 10
            });
            products.Insert(new Product()
            {
                Id = "2", Price = 30
            });

            Basket basket = new Basket();

            basket.BasketItems.Add(new BasketItem()
            {
                ProductId = "1", Quantity = 3
            });
            basket.BasketItems.Add(new BasketItem()
            {
                ProductId = "2", Quantity = 5
            });

            baskets.Insert(basket);

            IBasketService basketService = new BasketService(products, baskets);

            var controller  = new BasketController(basketService);
            var httpContext = new Mock.MockHttpContext();

            httpContext.Request.Cookies.Add(new System.Web.HttpCookie("eCommerceBasket")
            {
                Value = basket.Id
            });

            controller.ControllerContext = new System.Web.Mvc.ControllerContext(httpContext, new System.Web.Routing.RouteData(), controller);

            var result        = controller.BasketSummary() as PartialViewResult;
            var basketSummary = (BasketSummaryViewModel)result.ViewData.Model;

            Assert.AreEqual(8, basketSummary.BasketCount);
            Assert.AreEqual(180, basketSummary.BasketTotoal);
        }
Пример #3
0
        public void CanAddBasketItem()
        {
            IRepository <Basket>  baskets  = new Mock.MockContext <Basket>();
            IRepository <Product> products = new Mock.MockContext <Product>();

            var httpContext = new Mock.MockHttpContext();

            IBasketService basketService = new BasketService(products, baskets);

            var controller = new BasketController(basketService);

            //basketService.AddtoBasket(httpContext, "1");

            controller.ControllerContext = new System.Web.Mvc.ControllerContext(httpContext, new System.Web.Routing.RouteData(), controller);

            controller.AddToBasket("1");
            Basket basket = baskets.Collection().FirstOrDefault();

            Assert.IsNotNull(basket);
            Assert.AreEqual(1, basket.BasketItems.Count);
            Assert.AreEqual("1", basket.BasketItems.ToList().FirstOrDefault().ProductId);
        }