public JsonResult AddItemSubType([FromBody] AdminModel addItemSubType)
        {
            /*if (ModelState.IsValid)
             * {*/
            try
            {
                var addModel = new ItemTypeSub
                {
                    ItemType    = addItemSubType.ItemSubType.ItemType,
                    SubTypeName = addItemSubType.ItemSubType.SubTypeName
                };

                var add = _products.AddItemSubType(addModel);

                return(Json(addItemSubType.Message = "Item Sub Type added!"));
            }

            catch { return(Json(addItemSubType.Message = "Adding Item Sub Type Failed!")); }

            /* }
             *
             * else { return Json(addItemSubType.Message = "Something went wrong!"); }*/

            /* return Json(addItemSubType);*/
        }
        public Task <ItemTypeSub> AddItemSubType(ItemTypeSub itemSubType)
        {
            var itemSubTypeToAdd = new ItemTypeSub
            {
                SubTypeName = itemSubType.SubTypeName,
                ItemType    = itemSubType.ItemType
            };

            _context.ItemType.Attach(itemSubType.ItemType);
            _context.ItemTypeSub.Add(itemSubTypeToAdd);
            _context.SaveChanges();

            return(null);
        }
        public AdminControllerIntegrationTests()
        {
            #region MockData
            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
            };

            Reviews review = new Reviews
            {
                /*    Id = 1,*/
                /*  DayOfReview = DateTime.UtcNow,*/
                Item   = item,
                Rating = 5.0,
                Text   = "reviewText"
            };

            ImageUrls imageUrl = new ImageUrls
            {
                /* Id = 1,*/
                Item = item,
                Url  = "imageUrl"
            };
            #endregion

            adminModel = new AdminModel
            {
                Availibility   = item.Availability,
                Price          = item.Price,
                Discount       = item.Discount,
                Manufacturer   = manufacturer,
                Model          = model,
                ImageUrls      = imageUrl.Url,
                Color          = item.Color,
                ItemSubType    = itemSubType,
                ItemDepartment = itemDept,
                ModelName      = model.Name,
                Specs          = spec,
                ItemType       = itemType,
                Review         = review
            };


            var provider = new ServiceCollection().AddEntityFrameworkSqlServer().BuildServiceProvider();

            var options = new DbContextOptionsBuilder <StoreContext>();

            options.UseSqlServer($"Server=(localdb)\\MSSQLLocalDB;Database=Store_DTB_{Guid.NewGuid()};Trusted_Connection=True;MultipleActiveResultSets=True; ")
            .UseInternalServiceProvider(provider).EnableSensitiveDataLogging();

            _context = new StoreContext(options.Options);
            _context.Database.Migrate();
        }
Ejemplo n.º 4
0
        public void OrderController_AddInvoice_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"
            };

            Order order = new Order
            {
                ItemId          = 1,
                UserId          = 1,
                NumberOfItems   = 1,
                StatusId        = 1,
                BillingInfoId   = 1,
                PaymentMethodId = 1,
                InvoiceId       = 1
            };
            #endregion

            OrderListModel addInvoiceModel = new OrderListModel {
                BillingInfoId = 1
            };

            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 OrderProcessingController(productService, manager, userService, orderService)
            {
                ControllerContext = new ControllerContext()
                {
                    HttpContext = new DefaultHttpContext()
                    {
                        User = User
                    }
                }
            };

            var addUser          = userService.AddUser(user);
            var addItem          = productService.AddItem(item, spec, model);
            var addFirstInvoice  = orderService.AddInvoice(invoice);
            var addStatus        = orderService.AddStatus(status);
            var addStatus2       = orderService.AddStatus(status);
            var addStatus3       = orderService.AddStatus(status);
            var addStatus4       = orderService.AddStatus(status);
            var addPaymentMethod = orderService.AddPaymentMethod(paymentMethod);
            var addBillInfo      = orderService.AddBillingInfo(billingInfo);
            var addOrder         = orderService.AddOrder(order);
            var addInvoice       = Controller.AddInvoice(addInvoiceModel);

            var lastInvoice = orderService.GetLastInvoice();

            Assert.Equal(2, lastInvoice.Id);
            var    jsonResult = Assert.IsType <JsonResult>(addInvoice);
            string json       = JsonConvert.SerializeObject(jsonResult.Value);
            Assert.NotEqual("Invoice Addition Failed !", json);
            Assert.NotEqual("Something went wrong!", json);
        }
Ejemplo n.º 5
0
        public void OrderController_ConfirmOrder_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 addStatus2       = orderService.AddStatus(status);
            var addStatus3       = orderService.AddStatus(status);
            var addBillInfo      = orderService.AddBillingInfo(billingInfo);

            var addOrder      = Controller.AddOrder(productModel);
            var confirmOrders = Controller.ConfirmOrder();
            var getOrders     = orderService.GetAllOrders();
            Assert.Single(getOrders);
            Assert.Equal(3, getOrders.First().StatusId);
        }
Ejemplo n.º 6
0
        public OrderControllerIntegrationTests()
        {
            #region MockData
            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
            };

            Reviews review = new Reviews
            {
                /*    Id = 1,*/
                /*  DayOfReview = DateTime.UtcNow,*/
                Item   = item,
                Rating = 5.0,
                Text   = "reviewText"
            };

            ImageUrls imageUrl = new ImageUrls
            {
                /* Id = 1,*/
                Item = item,
                Url  = "imageUrl"
            };

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

            productModel = new ProductModel
            {
                Review        = review,
                ItemId        = 1,
                UserId        = 1,
                NumberOfItems = 1,
                BillingInfoId = 1,
                InvoiceId     = 1
            };


            var provider = new ServiceCollection().AddEntityFrameworkSqlServer().BuildServiceProvider();

            var options = new DbContextOptionsBuilder <StoreContext>();

            options.UseSqlServer($"Server=(localdb)\\MSSQLLocalDB;Database=Store_DTB_{Guid.NewGuid()};Trusted_Connection=True;MultipleActiveResultSets=True; ")
            .UseInternalServiceProvider(provider).EnableSensitiveDataLogging();

            _context = new StoreContext(options.Options);
            _context.Database.Migrate();
        }