示例#1
0
        protected override ValidationResult IsValid(object value, ValidationContext validationContext)
        {
            if (value == null)
            {
                return new ValidationResult("Categories are missing.");
            }

            List<int> categories = value as List<int>;
            if (categories.Count < 1 && categories.Count > 3)
            {
                return new ValidationResult("Categories should be at least 1 and no more than 3.");
            }

            using (var context = new OnlineShopContext())
            {
                var DbCategories = context.Categories
                    .Select(c => c.Id);

                foreach (var categoryId in categories)
                {
                    if (!DbCategories.Contains(categoryId))
                    {
                        return new ValidationResult("Category with Id " + categoryId + " doesn't exist.");
                    }
                }
            }

            return ValidationResult.Success;
        }
示例#2
0
        private static void CleanDatabase()
        {
            var context = new OnlineShopContext();

            context.Ads.Delete();
            context.AdTypes.Delete();
            context.Categories.Delete();
            context.Users.Delete();
        }
        public async Task GetWorkItemsAsync_WhenCalled_ReturnsAllWorkItemsWithIteration()
        {
            // Act
            List <WorkItem> workItems = null;

            using (var context = new OnlineShopContext(options))
            {
                var sut = new WorkItemService(context);
                workItems = (await sut.GetWorkItemsAsync()).ToList();
            }

            // Assert
            Assert.NotNull(workItems);
            Assert.Equal(3, workItems.Count());
            Assert.NotNull(workItems[0].Iteration);
            Assert.NotNull(workItems[1].Iteration);
            Assert.NotNull(workItems[2].Iteration);
        }
示例#4
0
        public void Posting_Ad_With_Invalid_AdType_Should_Return_Bad_Request()
        {
            var context  = new OnlineShopContext();
            var category = context.Categories.First();

            var data = new FormUrlEncodedContent(new[]
            {
                new KeyValuePair <string, string>("name", "Opel Astra"),
                new KeyValuePair <string, string>("description", "some description"),
                new KeyValuePair <string, string>("price", "2000"),
                new KeyValuePair <string, string>("typeId", "-1"), // invalid Id
                new KeyValuePair <string, string>("categories[0]", category.Id.ToString())
            });

            var response = this.PostNewAd(data);

            Assert.AreEqual(HttpStatusCode.BadRequest, response.StatusCode);
        }
        protected override ValidationResult IsValid(object value, ValidationContext validationContext)
        {
            if (value == null)
            {
                return(new ValidationResult("Type cannot be null."));
            }

            using (var context = new OnlineShopContext())
            {
                var type = context.AdTypes.Find(value);

                if (type == null)
                {
                    return(new ValidationResult("Ad Type with Id " + value + " doesn't exist."));
                }
            }

            return(ValidationResult.Success);
        }
示例#6
0
 //[Route("GetAllProducts")]
 public List <Product> GetAllProducts(int index, int rows)
 {
     try
     {
         using (OnlineShopContext employeeDBEntities = new OnlineShopContext())
         {
             var STARTROWINDEX = new SqlParameter("STARTROWINDEX", index);
             var MAXIMUMROWS   = new SqlParameter("MAXIMUMROWS", rows);
             var result        = employeeDBEntities.Products.FromSqlRaw("EXECUTE dbo.GETDATA_WITHPAGING  @STARTROWINDEX,@MAXIMUMROWS", STARTROWINDEX, MAXIMUMROWS).ToList();
             //.FromSql("EXECUTE dbo.GETDATA_WITHPAGING  @STARTROWINDEX", productCategory)
             //.ToList();
             return(_orderRepo.GetAllProducts(result));
         }
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
        public CategoryServiceTests()
        {
            // Arrange
            var category1 = new Category {
                Id = 1, Name = "Category1", Description = "Category1_Description"
            };
            var category2 = new Category {
                Id = 2, Name = "Category2", Description = "Category2_Description"
            };
            var category3 = new Category {
                Id = 3, Name = "Category3", Description = "Category3_Description"
            };

            using (var context = new OnlineShopContext(options))
            {
                context.Category.AddRange(category1, category2, category3);
                context.SaveChanges();
            }
        }
示例#8
0
        protected override ValidationResult IsValid(object value, ValidationContext validationContext)
        {
            if (value == null)
            {
                return new ValidationResult("Type cannot be null.");
            }

            using (var context = new OnlineShopContext())
            {
                var type = context.AdTypes.Find(value);

                if (type == null)
                {
                    return new ValidationResult("Ad Type with Id " + value + " doesn't exist.");
                }
            }

            return ValidationResult.Success;
        }
        public IterationServiceTests()
        {
            // Arrange
            var iteration1 = new Iteration {
                Id = 1, Name = "Iteration1"
            };
            var iteration2 = new Iteration {
                Id = 2, Name = "Iteration2"
            };
            var iteration3 = new Iteration {
                Id = 3, Name = "Iteration3"
            };

            using (var context = new OnlineShopContext(options))
            {
                context.Iteration.AddRange(iteration1, iteration2, iteration3);
                context.SaveChanges();
            }
        }
示例#10
0
        protected override ValidationResult IsValid(object value, ValidationContext validationContext)
        {
            int id = (int)value;

            if (id == 0)
            {
                return(new ValidationResult("Missing ad type."));
            }

            using (OnlineShopContext data = new OnlineShopContext())
            {
                var adType = data.AdTypes.Find(id);
                if (adType == null)
                {
                    return(new ValidationResult("No such ad type in database."));
                }
            }

            return(ValidationResult.Success);
        }
        public async Task GetPiesAsync_WhenCalled_ReturnsAllPiesWithCategory()
        {
            // Act
            List <Pie> pies = null;

            using (var context = new OnlineShopContext(options))
            {
                var sut = new PieService(context);
                pies = (await sut.GetPiesAsync()).ToList();
            }

            // Assert
            Assert.NotNull(pies);
            Assert.Equal(6, pies.Count());
            Assert.NotNull(pies[0].Category);
            Assert.NotNull(pies[1].Category);
            Assert.NotNull(pies[2].Category);
            Assert.NotNull(pies[3].Category);
            Assert.NotNull(pies[4].Category);
            Assert.NotNull(pies[5].Category);
        }
示例#12
0
        public async Task GetShoppingCartItemsAsync_WhenCalled_ReturnsAllShoppingCartItemsWithPie()
        {
            // Act
            List <ShoppingCartItem> shoppingCartItems = null;

            using (var context = new OnlineShopContext(options))
            {
                var sut = new ShoppingCartService(context, shoppingCartId);
                shoppingCartItems = (await sut.GetShoppingCartItemsAsync()).ToList();
            }

            // Assert
            Assert.NotNull(shoppingCartItems);
            Assert.Equal(6, shoppingCartItems.Count());
            Assert.NotNull(shoppingCartItems[0].Pie);
            Assert.NotNull(shoppingCartItems[1].Pie);
            Assert.NotNull(shoppingCartItems[2].Pie);
            Assert.NotNull(shoppingCartItems[3].Pie);
            Assert.NotNull(shoppingCartItems[4].Pie);
            Assert.NotNull(shoppingCartItems[5].Pie);
        }
示例#13
0
        public static void Initialize(OnlineShopContext context)
        {
            context.Database.EnsureCreated();

            //var customer = new Customer()
            //{
            //    FirstName = "Jok",
            //    LastName = "Garcia",
            //    Email = "*****@*****.**",
            //    ContactNumber = "888777",
            //    IsActive = true
            //};

            //context.Customers.Add(customer);
            //context.SaveChanges();

            //var customer2 = new Customer()
            //{
            //    FirstName = "Lebron",
            //    LastName = "James",
            //    Email = "*****@*****.**",
            //    ContactNumber = "31231231",
            //};

            //context.Customers.Add(customer2);
            //context.SaveChanges();

            //var product = new Product()
            //{
            //    ProductName = "Laptop",
            //    ProductDescription = "A laptop computer is a portable personal computer powered by a battery, or an AC cord plugged into an electrical outlet, which is also used to charge the battery.",
            //    Amount = 50000,
            //    Category = "Computer",
            //    CreatedBy = "Alyanna Cantos",
            //    CreatedDate = DateTime.Now
            //};

            //context.Products.Add(product);
            //context.SaveChanges();
        }
        public PieServiceTests()
        {
            // Arrange
            var category1 = new Category {
                Id = 1, Name = "Category1", Description = "Category1_Description"
            };
            var category2 = new Category {
                Id = 2, Name = "Category2", Description = "Category2_Description"
            };
            var category3 = new Category {
                Id = 3, Name = "Category3", Description = "Category3_Description"
            };

            var pie1 = new Pie {
                Id = 1, Name = "Pie1", ShortDescription = "Pie1_ShortDescription", LongDescription = "Pie1_LongDescription", Price = 10.99m, IsPieOfTheWeek = true, InStock = true, ImageUrl = "Pie1_ImageUrl", ThumbnailImageUrl = "Pie1_ThumbnailImageUrl", Category = category1
            };
            var pie2 = new Pie {
                Id = 2, Name = "Pie2", ShortDescription = "Pie2_ShortDescription", LongDescription = "Pie2_LongDescription", Price = 11.50m, IsPieOfTheWeek = false, InStock = false, ImageUrl = "Pie2_ImageUrl", ThumbnailImageUrl = "Pie2_ThumbnailImageUrl", Category = category2
            };
            var pie3 = new Pie {
                Id = 3, Name = "Pie3", ShortDescription = "Pie3_ShortDescription", LongDescription = "Pie3_LongDescription", Price = 12.59m, IsPieOfTheWeek = false, InStock = true, ImageUrl = "Pie3_ImageUrl", ThumbnailImageUrl = "Pie3_ThumbnailImageUrl", Category = category3
            };
            var pie4 = new Pie {
                Id = 4, Name = "Pie4", ShortDescription = "Pie4_ShortDescription", LongDescription = "Pie4_LongDescription", Price = 15.95m, IsPieOfTheWeek = false, InStock = true, ImageUrl = "Pie4_ImageUrl", ThumbnailImageUrl = "Pie4_ThumbnailImageUrl", Category = category1
            };
            var pie5 = new Pie {
                Id = 5, Name = "Pie5", ShortDescription = "Pie5_ShortDescription", LongDescription = "Pie5_LongDescription", Price = 16.95m, IsPieOfTheWeek = true, InStock = true, ImageUrl = "Pie5_ImageUrl", ThumbnailImageUrl = "Pie5_ThumbnailImageUrl", Category = category2
            };
            var pie6 = new Pie {
                Id = 6, Name = "Pie6", ShortDescription = "Pie6_ShortDescription", LongDescription = "Pie6_LongDescription", Price = 21.40m, IsPieOfTheWeek = false, InStock = false, ImageUrl = "Pie6_ImageUrl", ThumbnailImageUrl = "Pie6_ThumbnailImageUrl", Category = category3
            };

            using (var context = new OnlineShopContext(options))
            {
                context.Category.AddRange(category1, category2, category3);
                context.Pie.AddRange(pie1, pie2, pie3, pie4, pie5, pie6);
                context.SaveChanges();
            }
        }
示例#15
0
        private static void SeedDatabase()
        {
            var context = new OnlineShopContext();
            var userStore = new UserStore<ApplicationUser>(context);
            var userManager = new ApplicationUserManager(userStore);

            var user = new ApplicationUser()
            {
                UserName = TestUserUsername,
                Email = "*****@*****.**"
            };

            var result = userManager.CreateAsync(user, TestUserPassword).Result;

            if (!result.Succeeded)
            {
                Assert.Fail(string.Join(Environment.NewLine, result.Errors));
            }

            SeedCategories(context);
            SeedAdTypes(context);
        }
示例#16
0
        private List <Category> SeedCategories(OnlineShopContext context)
        {
            var categories = new List <Category>()
            {
                new Category()
                {
                    Name = "Business"
                },
                new Category()
                {
                    Name = "Garden"
                },
                new Category()
                {
                    Name = "Toys"
                },
                new Category()
                {
                    Name = "Pleasure"
                },
                new Category()
                {
                    Name = "Electronics"
                },
                new Category()
                {
                    Name = "Clothes"
                }
            };

            foreach (var category in categories)
            {
                context.Categories.Add(category);
            }

            context.SaveChanges();

            return(categories);
        }
示例#17
0
        private static void SeedDatabase()
        {
            var context     = new OnlineShopContext();
            var userStore   = new UserStore <ApplicationUser>(context);
            var userManager = new ApplicationUserManager(userStore);

            var user = new ApplicationUser()
            {
                UserName = Username,
                Email    = "*****@*****.**"
            };

            var result = userManager.CreateAsync(user, Password).Result;

            if (!result.Succeeded)
            {
                Assert.Fail(string.Join(Environment.NewLine, result.Errors));
            }

            SeedCategories(context);
            SeedAdTypes(context);
        }
示例#18
0
        private static void SeedAds(OnlineShopContext context, ApplicationUser user, List <AdType> adTypes)
        {
            user.OwnAds.Add(new Ad()
            {
                Name        = "Motika",
                Description = "Brand new",
                Price       = 199.99m,
                PostedOn    = DateTime.Now.AddDays(-6),
                Type        = adTypes[0]
            });

            user.OwnAds.Add(new Ad()
            {
                Name        = "Tarnokop",
                Description = "Old antique",
                Price       = 15.20m,
                PostedOn    = DateTime.Now.AddDays(-12),
                Type        = adTypes[1]
            });

            context.SaveChanges();
        }
示例#19
0
        public IActionResult SaveRegistration(string name, string surname, DateTime birthdate, int cityID, string adresa, string email, string password, int genderID)
        {
            OnlineShopContext _database = new OnlineShopContext();

            User user = new User
            {
                Name      = name,
                Surname   = surname,
                BirthDate = birthdate,
                CityID    = cityID,
                Adress    = adresa,
                Email     = email,
                Password  = password,
                GenderID  = genderID,
            };


            _database.user.Add(user);
            _database.SaveChanges();
            _database.Dispose();
            return(Redirect("RegistrationSuccessful"));
        }
示例#20
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IWebHostEnvironment env, OnlineShopContext context)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }

            app.UseRouting();
            app.UseStaticFiles();

            app.UseMvc(ConfigureRoutes);

            //app.UseEndpoints(endpoints =>
            //{
            //    endpoints.MapGet("/", async context =>
            //    {
            //        await context.Response.WriteAsync("Hello World!");
            //    });
            //});

            Seeder.Initialize(context);
        }
示例#21
0
        public void Posting_Ad_With_More_Than_3_Categories_Should_Return_Bad_Request()
        {
            var context    = new OnlineShopContext();
            var categories = context.Categories.ToList();
            var adType     = context.AdTypes.First();

            var data = new FormUrlEncodedContent(new[]
            {
                new KeyValuePair <string, string>("name", "Opel Atra"),
                new KeyValuePair <string, string>("description", "some description"),
                new KeyValuePair <string, string>("price", "2000"),
                new KeyValuePair <string, string>("typeId", adType.Id.ToString()),
                new KeyValuePair <string, string>("categories[0]", categories[0].Id.ToString()),
                new KeyValuePair <string, string>("categories[1]", categories[1].Id.ToString()),
                new KeyValuePair <string, string>("categories[2]", categories[2].Id.ToString()),
                new KeyValuePair <string, string>("categories[3]", categories[3].Id.ToString()),
            });

            var response = this.PostNewAd(data);
            var ads      = context.Ads.ToList();

            Assert.AreEqual(HttpStatusCode.BadRequest, response.StatusCode);
        }
示例#22
0
        public async Task RemoveShoppingCartItemAsync_WhenCalledWithPieIdInShoppingCart_Returns1AndRemovesShoppingCartItem(int pieId, int expectedOutput)
        {
            // Act
            int numberOfRecordsUpdated = 0;

            using (var context = new OnlineShopContext(options))
            {
                var sut = new ShoppingCartService(context, shoppingCartId);
                numberOfRecordsUpdated = await sut.RemoveShoppingCartItemAsync(pieId);
            }

            // Assert
            ShoppingCartItem shoppingCartItem = null;

            using (var context = new OnlineShopContext(options))
            {
                var sut = new ShoppingCartService(context, shoppingCartId);
                shoppingCartItem = await sut.GetShoppingCartItemAsync(pieId);
            }

            Assert.Equal(expectedOutput, numberOfRecordsUpdated);
            Assert.Null(shoppingCartItem);
        }
示例#23
0
        public async Task ClearShoppingCartAsync_WhenCalledWithNonEmptyShoppingCart_Returns1AndEmptiesShoppingCart()
        {
            // Act
            int numberOfRecordsUpdated = 0;

            using (var context = new OnlineShopContext(options))
            {
                var sut = new ShoppingCartService(context, shoppingCartId);
                numberOfRecordsUpdated = await sut.ClearShoppingCartAsync();
            }

            // Assert
            IEnumerable <ShoppingCartItem> shoppingCartItems = null;

            using (var context = new OnlineShopContext(options))
            {
                var sut = new ShoppingCartService(context, shoppingCartId);
                shoppingCartItems = await sut.GetShoppingCartItemsAsync();
            }

            Assert.Equal(6, numberOfRecordsUpdated);
            Assert.Empty(shoppingCartItems);
        }
示例#24
0
        public async Task ClearShoppingCartAsync_WhenCalledWithEmptyShoppingCart_Returns0()
        {
            // Arrange - Empty Shopping Cart
            using (var context = new OnlineShopContext(options))
            {
                var shoppingCartItems = await context.ShoppingCartItem.ToListAsync();

                context.ShoppingCartItem.RemoveRange(shoppingCartItems);
                await context.SaveChangesAsync();
            }

            // Act
            int numberOfRecordsUpdated = 0;

            using (var context = new OnlineShopContext(options))
            {
                var sut = new ShoppingCartService(context, shoppingCartId);
                numberOfRecordsUpdated = await sut.ClearShoppingCartAsync();
            }

            // Assert
            Assert.Equal(0, numberOfRecordsUpdated);
        }
示例#25
0
        public void TestAddAdsWhenDataCorrectShouldAddAds()
        {
            var context  = new OnlineShopContext();
            var category = context.Categories.First();
            var typeAd   = context.AdTypes.First();

            var data = new FormUrlEncodedContent(new []
            {
                new KeyValuePair <string, string>("name", "first"),
                new KeyValuePair <string, string>("description", "1111"),
                new KeyValuePair <string, string>("price", "1"),
                new KeyValuePair <string, string>("typeId", typeAd.Id.ToString()),
                new KeyValuePair <string, string>("categories[0]", category.Id.ToString()),
            });

            var response = this.PostNewAd(data);

            if (response.StatusCode != HttpStatusCode.OK)
            {
                Assert.Fail(response.Content.ReadAsStringAsync().Result);
            }
            Assert.AreEqual(HttpStatusCode.OK, response.StatusCode);
        }
示例#26
0
        public async Task DecreaseShoppingCartItemQuantityAsync_WhenCalledWithPieIdInShoppingCartAndQuantityLessThanCurrentQuantity_Returns1AndDecreasesQuantity(int pieId, int quantity, int expectedOutput, int expectedQuantity)
        {
            // Act
            int numberOfRecordsUpdated = 0;

            using (var context = new OnlineShopContext(options))
            {
                var sut = new ShoppingCartService(context, shoppingCartId);
                numberOfRecordsUpdated = await sut.DecreaseShoppingCartItemQuantityAsync(pieId, quantity);
            }

            // Assert
            ShoppingCartItem shoppingCartItem = null;

            using (var context = new OnlineShopContext(options))
            {
                var sut = new ShoppingCartService(context, shoppingCartId);
                shoppingCartItem = await sut.GetShoppingCartItemAsync(pieId);
            }

            Assert.Equal(expectedOutput, numberOfRecordsUpdated);
            Assert.NotNull(shoppingCartItem);
            Assert.Equal(expectedQuantity, shoppingCartItem.Quantity);
        }
示例#27
0
        public void MakeAnOrder(int customerId, int productId, int quantity)
        {
            using (var ctx = new OnlineShopContext())
            {
                var customer = ctx.Customers.FirstOrDefault(c => c.Id == customerId) ?? throw new ArgumentNullException("Customer with provided id not found!");
                var product  = ctx.Products.FirstOrDefault(p => p.Id == productId) ?? throw new ArgumentNullException("Product with provided id not found!");

                var order = new Order()
                {
                    CustomerId = customer.Id,
                    Customer   = customer
                };

                var orderItems = new OrderItem()
                {
                    Quantity = quantity,
                    Order    = order,
                    Product  = product
                };

                ctx.OrderItems.Add(orderItems);
                ctx.SaveChanges();
            }
        }
示例#28
0
        private static ApplicationUser SeedUser(OnlineShopContext context)
        {
            var user = new ApplicationUser()
            {
                UserName = "******",
                Email    = "*****@*****.**"
            };

            var userStore   = new UserStore <ApplicationUser>(context);
            var userManager = new UserManager <ApplicationUser>(userStore);

            const string password = "******";

            var userCreateResult = userManager.Create(user, password);

            if (!userCreateResult.Succeeded)
            {
                throw new InvalidOperationException(string.Join(
                                                        Environment.NewLine,
                                                        userCreateResult.Errors));
            }

            return(user);
        }
示例#29
0
 protected BaseApiController(OnlineShopContext data)
 {
     this.Data = data;
 }
示例#30
0
 public BranchService(OnlineShopContext context)
 {
     _context = context;
 }
示例#31
0
 public SlideDao()
 {
     db = new OnlineShopContext();
 }
示例#32
0
 public OrderController(OnlineShopContext database, IOrder order, ICart cart)
 {
     _order = order; _database = database; _cart = cart;
 }
 public BaseController()
 {
     this.Context = OnlineShopContext.Create();
 }
 public BaseApiController(OnlineShopContext context)
 {
     this.Context = context;
 }
示例#35
0
 public CategoryRepository(OnlineShopContext context)
 {
     _context = context;
 }
示例#36
0
 public CartsController(OnlineShopContext context)
 {
     _context = context;
 }
 public BaseApiController(OnlineShopContext data)
 {
     this.Data = data;
 }
示例#38
0
        private static List<Category> SeedCategories(OnlineShopContext context)
        {
            var categories = new List<Category>()
            {
                new Category() {Name = "Business"},
                new Category() {Name = "Garden"},
                new Category() {Name = "Toys"},
                new Category() {Name = "Pleasure"},
                new Category() {Name = "Electronics"},
                new Category() {Name = "Clothes"}
            };

            foreach (var category in categories)
            {
                context.Categories.Add(category);
            }

            context.SaveChanges();

            return categories;
        }
示例#39
0
        private static List<AdType> SeedAdTypes(OnlineShopContext context)
        {
            var adTypes = new List<AdType>
            {
                new AdType()
                {
                    Name = "Normal",
                    PricePerDay = 3.99m,
                    Index = 100
                },
                new AdType()
                {
                    Name = "Premium",
                    PricePerDay = 5.99m,
                    Index = 200
                },
                new AdType()
                {
                    Name = "Diamond",
                    PricePerDay = 9.99m,
                    Index = 300
                }
            };

            foreach (var adType in adTypes)
            {
                context.AdTypes.Add(adType);
            }

            context.SaveChanges();

            return adTypes;
        }