public async void TestApiPostForOrder()
        {
            ModelAddToCart model = new ModelAddToCart();

            model.InventoryId = 2;
            model.Numdays     = 5;
            model.Token       = token;

            //add to cart
            ApiInventoryController inventoryController = new ApiInventoryController(null);
            var jsonResult = await inventoryController.Post(model);

            Assert.NotNull(jsonResult);
            Assert.True(jsonResult.Success);

            //submit the order
            var submitted = controller.SubmitOrder();

            Assert.NotNull(submitted);

            //check order
            var             mockOrderRepository    = new Mock <IApiOrderRepository>();
            var             mockLogger             = new Mock <ILogger <OrderController> >();
            var             mockCustomerRepository = new Mock <IApiCustomerRepository>();
            OrderController orderController        = new OrderController(null, mockLogger.Object, mockOrderRepository.Object, mockCustomerRepository.Object, memoryCache);

            var result = await orderController.Order(token) as ViewResult;

            var viewResult  = Assert.IsType <ViewResult>(result);
            var modelResult = Assert.IsAssignableFrom <ViewResult>(viewResult);

            Assert.NotNull(modelResult);
        }
Пример #2
0
        public UnitTestApiInventory()
        {
            controller = new ApiInventoryController(null);
            Token t = new Token();

            token = t.CreateToken();
        }
Пример #3
0
        //[HttpGet]
        public async Task <IActionResult> Index()
        {
            int    customerId            = 0;
            string username              = "******"; //just for this demo application
            List <ModelInventory> result = null;
            int countOrdered             = 0;

            string culture     = "en";
            var    cultureInfo = new CultureInfo(culture);

            cultureInfo.NumberFormat.CurrencySymbol   = "€";
            CultureInfo.DefaultThreadCurrentCulture   = cultureInfo;
            CultureInfo.DefaultThreadCurrentUICulture = cultureInfo;
            Thread.CurrentThread.CurrentCulture       = CultureInfo.CreateSpecificCulture(culture);
            Thread.CurrentThread.CurrentUICulture     = CultureInfo.CreateSpecificCulture(culture);


            string token = "";

            if (HttpContext != null)
            {
                // actually it is a demo variant of registration
                ApiCustomerController apiCustomerController = new ApiCustomerController(apiCustomerRepository);
                var resultRegister = await apiCustomerController.RegisterOrModify(username);

                if (resultRegister == null)
                {
                    ViewBag.StatusMessage = localizer["BadRegistration"].Value;
                }
                else
                {
                    customerId = resultRegister.CustomerId;
                }

                token = HttpContext.Session.GetString("token");
                if (string.IsNullOrEmpty(token))
                {
                    Token t = new Token();
                    token = t.CreateToken();
                    HttpContext.Session.SetString("token", token);

                    cacheData(token, customerId);
                }
                ViewBag.Token = token;
                HttpContext.Session.SetInt32("customerId", customerId);
            }
            if (localizer != null)
            {
                ViewData["Title"]    = localizer["Title"].Value;
                ViewBag.NotFound     = localizer["NotFound"].Value;
                ViewBag.Name         = localizer["Name"].Value;
                ViewBag.Type         = localizer["Type"].Value;
                ViewBag.Duration     = localizer["Duration"].Value;
                ViewBag.Days         = localizer["Days"].Value;
                ViewBag.AddCart      = localizer["AddCart"].Value;
                ViewBag.ErrorApiCall = localizer["ErrorApiCall"].Value;
                ViewBag.Cart         = localizer["ShoppingCart"].Value;
                ViewBag.OpenCart     = localizer["OpenCart"].Value;
                ViewBag.WrongInput   = localizer["WrongInput"].Value;
            }

            try
            {
                ApiInventoryController             apiInventoryController = new ApiInventoryController(localizer);
                Tuple <List <ModelInventory>, int> tuple = await apiInventoryController.Get(token);

                result               = tuple.Item1;
                countOrdered         = tuple.Item2;
                ViewBag.CountOrdered = countOrdered;

                return(View(result));
            }
            catch (Exception ex)
            {
                logger.LogError(ex.Message + "; " + ex.InnerException);
                ViewBag.StatusMessage = ex.Message + "<br />" + ex.InnerException;
                return(View());
            }
        }