Пример #1
0
        public void AddOrderFromIndex_Returns_JsonResult_AdditionFailed()
        {
            Users user = new Users {
                Id = 1, UserName = "******"
            };
            ProductModel model = new ProductModel {
                ItemId = 1, UserId = 1, StatusId = 1, NumberOfItems = 1
            };
            Order order = new Order {
                Id = 1, ItemId = 1
            };
            var cancel = new CancellationToken();

            var mockProductService = new Mock <IProductService>();
            var mockUserService    = new Mock <IUserService>();
            var mockOrderService   = new Mock <IOrderService>();

            mockOrderService.Setup(m => m.AddOrder(order)).Returns(Task.FromResult(order));
            var mockUserStore = new Mock <IUserStore <Users> >();

            mockUserStore.Setup(u => u.CreateAsync(user, cancel));

            var mockManager = new Mock <UserManager <Users> >(mockUserStore.Object, null, null, null, null, null, null, null, null);

            var Controller = new OrderController(mockProductService.Object, mockManager.Object, mockUserService.Object, mockOrderService.Object);

            var result = Controller.AddOrderFromIndex(model);

            var    jsonResult = Assert.IsType <JsonResult>(result);
            string json       = JsonConvert.SerializeObject(jsonResult.Value);

            Assert.Equal("\"Order addition failed!\"", json);
        }
Пример #2
0
        public void OrderController_AddOrderFromIndex_Success()
        {
            #region MockData
            Users user = new Users {
                UserName = "******", Email = "fakeEmail"
            };
            var cancel = new CancellationToken();

            var User = new ClaimsPrincipal(new ClaimsIdentity(new Claim[]
            {
                new Claim(ClaimTypes.NameIdentifier, "1"),
            }));

            BillingInfo billingInfo = new BillingInfo
            {
                Adress         = "fakeAdress",
                City           = "fakeCity",
                CountryOrState = "fakeCountry",
                Email          = "fakeEmail",
                PhoneNumber    = "fakeNumber",
            };

            Invoice invoice = new Invoice
            {
                InvoiceDate = DateTimeOffset.UtcNow,
                UserId      = 1
            };

            Manufacturer manufacturer = new Manufacturer
            {
                /* Id = 1,*/
                Name = "manufacturerName"
            };

            ItemDepartment itemDept = new ItemDepartment
            {
                /*   Id = 1,*/
                DeptName = "DeptName"
            };

            ItemType itemType = new ItemType
            {
                /* Id = 1,*/
                Name = "itemTypeName",
                ItemTypeHeaderImageUrl = "itemTypeHeaderImageUrl",
                ItemGroupName          = "itemGroupName"
            };

            ItemTypeSub itemSubType = new ItemTypeSub
            {
                /*   Id = 1,*/
                SubTypeName = "itemSubTypeName",
                ItemType    = itemType
            };

            Specs spec = new Specs
            {
                /*  Id = 1, */
                Description   = "Description",
                Specification = "Specification",
            };

            Model model = new Model
            {
                /*  Id = 1,*/
                ItemDepartment = itemDept,
                SpecsId        = spec,
                TypeId         = itemType,
                Name           = "modelName"
            };

            Items item = new Items
            {
                /* Id = 1, */
                Availability = 1,
                Color        = "itemColor",
                Price        = 12,
                Discount     = 0,
                ManuModel    = manufacturer,
                Model        = model,
                ItemTypeSub  = itemSubType
            };

            PaymentMethod paymentMethod = new PaymentMethod {
                Method = "fakeMethod"
            };
            Status status = new Status {
                StatusText = "fakeStatus"
            };
            #endregion

            var productService = new StoreProductService(_context);
            var userService    = new UserService(_context);
            var orderService   = new OrderService(_context);

            var mockUserStore = new Mock <IUserStore <Users> >();
            mockUserStore.Setup(u => u.CreateAsync(user, cancel));

            var manager    = new UserManager <Users>(mockUserStore.Object, null, null, null, null, null, null, null, null);
            var Controller = new OrderController(productService, manager, userService, orderService)
            {
                ControllerContext = new ControllerContext()
                {
                    HttpContext = new DefaultHttpContext()
                    {
                        User = User
                    }
                }
            };

            var addItem          = productService.AddItem(item, spec, model);
            var addUser          = userService.AddUser(user);
            var addInvoice       = orderService.AddInvoice(invoice);
            var addPaymentMethod = orderService.AddPaymentMethod(paymentMethod);
            var addStatus        = orderService.AddStatus(status);
            var addBillInfo      = orderService.AddBillingInfo(billingInfo);

            var addOrder  = Controller.AddOrderFromIndex(productModel);
            var getOrders = orderService.GetAllOrders();
            Assert.Single(getOrders);
            Assert.Equal(1, getOrders.First().NumberOfItems);
            Assert.Equal("Order Added Sucesffuly!", addOrder.Value);
        }