public void AddProductAuctionAlreadyFinished()
        {
            AuctionService auctionService = new AuctionService();
            ProductService productService = new ProductService();
            CurrencyService currencyService = new CurrencyService();
            UserService userService = new UserService();
            ProductAuctionService productAuctionService = new ProductAuctionService();
            RoleService roleService = new RoleService();

            User user = userService.GetUserById(3);
            Product product = productService.GetProductById(1);
            Double price = 101;
            Currency currency = currencyService.getCurrencyById(1);
            Boolean result = false;

            try
            {
                result = productAuctionService.AddProductAuction(user, product, price, currency);
            }
            catch (AuctionException exc)
            {
                Assert.AreEqual("Cannot add a new auction for the selected product because it is expired", exc.Message);
            }
            Assert.IsFalse(result);
        }
        public void AddProductNull()
        {
            Product product = null;
            ProductService productService = new ProductService();

            try
            {
                productService.AddProduct(product);
            }
            catch (ValidationException e)
            {
                Assert.AreEqual("Product is null", e.Message);
            }
        }
 public void deleteExistentProductDependency()
 {
     int id = 1;
     ProductService productService = new ProductService();
     Boolean result = false;
     try
     {
         result = productService.DeleteProduct(id);
     }
     catch (DependencyException e)
     {
         Assert.AreEqual("The product has auctions. It cannot be deleted!", e.Message);
     }
     Assert.AreEqual(result, false);
 }
 public void AddProductNullName()
 {
     Product product = new Product();
     product.Name = null;
     ProductService productService = new ProductService();
     Boolean result = false;
     try
     {
         result = productService.AddProduct(product);
     }
     catch (ValidationException exc)
     {
         Assert.AreEqual("Invalid product's name - null.", exc.Message);
     }
     Assert.AreEqual(result, false);
 }
 public void AddProductExistent()
 {
     Product product = new Product();
     product.Name = "thr";
     product.Description = "";
     CategoryService categoryService = new CategoryService();
     Category category = categoryService.GetCategoryById(2);
     product.Categories.Add(category);
     ProductService productService = new ProductService();
     Boolean result = false;
     try
     {
         result = productService.AddProduct(product);
     }
     catch (DuplicateException exc)
     {
         Assert.AreEqual("The same product already exists - same name, description and category", exc.Message);
     }
     Assert.AreEqual(result, false);
 }
        public void TestAddProductAuctionDifferentCurrency()
        {
            AuctionService auctionService = new AuctionService();
            ProductService productService = new ProductService();
            CurrencyService currencyService = new CurrencyService();
            UserService userService = new UserService();
            ProductAuctionService productAuctionService = new ProductAuctionService();
            RoleService roleService = new RoleService();

            User user = userService.GetUserById(2);
            Product product = productService.GetProductById(1);
            Double price = 100;
            Currency currency = currencyService.getCurrencyById(2);

            try
            {
                productAuctionService.AddProductAuction(user, product, price, currency);
            }
            catch (ValidationException exc)
            {
                Assert.AreEqual("The auction must have the same currency as the product: " + product.Auction.Currency.Name, exc.Message);
            }
        }
        public void TestAddProductAuctionPriceTheSameAsTheLastAuction()
        {
            AuctionService auctionService = new AuctionService();
            ProductService productService = new ProductService();
            CurrencyService currencyService = new CurrencyService();
            UserService userService = new UserService();
            ProductAuctionService productAuctionService = new ProductAuctionService();
            RoleService roleService = new RoleService();

            User user = userService.GetUserById(2);
            Product product = productService.GetProductById(1);
            Double price = 101;
            Currency currency = currencyService.getCurrencyById(1);

            try
            {
                productAuctionService.AddProductAuction(user, product, price, currency);
            }
            catch (ValidationException exc)
            {
                Assert.AreEqual("The price is too low", exc.Message);
            }
        }
        public void TestAddProductAuctionPriceHigherThanStartPice()
        {
            AuctionService auctionService = new AuctionService();
            ProductService productService = new ProductService();
            CurrencyService currencyService = new CurrencyService();
            UserService userService = new UserService();
            ProductAuctionService productAuctionService = new ProductAuctionService();
            RoleService roleService = new RoleService();

            User user = userService.GetUserById(2);
            Product product = productService.GetProductById(1);
            Double price = 1000;
            Currency currency = currencyService.getCurrencyById(1);

            Assert.IsNotNull(currency.IdCurrency);
            Assert.IsNotNull(product.Auction.Currency.IdCurrency);

            Assert.AreEqual(currency.IdCurrency, 1);
            Assert.AreEqual(product.Auction.Currency.IdCurrency, 1);

            Boolean result = false;
            try
            {
                result = productAuctionService.AddProductAuction(user, product, price, currency);
            }
            catch (ValidationException exc)
            {
                Assert.AreEqual("", exc.Message);
            }
            Assert.AreEqual(result, true);
        }
 public void UpdateProductDescriptionNull()
 {
     String description = null;
     int id = 1;
     ProductService ProductService = new ProductService();
     Boolean result = false;
     try
     {
         result = ProductService.UpdateProductDescription(id, description);
     }
     catch (ValidationException exc)
     {
         Assert.AreEqual("Invalid product's description.", exc.Message);
     }
     Assert.AreEqual(false, result);
 }
 public void UpdateProductDescriptionZeroCharacters()
 {
     String description = "";
     int id = 9;
     ProductService ProductService = new ProductService();
     Boolean result = false;
     try
     {
         result = ProductService.UpdateProductDescription(id, description);
     }
     catch (ValidationException exc)
     {
         Assert.AreEqual("", exc.Message);
     }
     Assert.AreEqual(true, result);
 }
        public void TestFinishAuctionNullUser()
        {
            ProductService productService = new ProductService();
            ProductAuctionService productAuctionService = new ProductAuctionService();

            Product product = productService.GetProductById(1);
            Boolean result = false;

            try
            {
                productAuctionService.closeAuction(null, product);
            }
            catch(EntityDoesNotExistException exc)
            {
                Assert.AreEqual("User is null", exc.Message);
            }

            Assert.IsFalse(result);
        }
        public void TestFinishAuctionNotTheSameUser()
        {
            UserService userService = new UserService();
            ProductAuctionService productAuctionService = new ProductAuctionService();
            ProductService productService = new ProductService();

            User user = userService.GetUserById(2);
            Product product = productService.GetProductById(1);
            Boolean result = false;

            try
            {
                productAuctionService.closeAuction(user, product);
            }
            catch (AuctionException exc)
            {
                Assert.AreEqual("You are not allowed to close the auction - you are not the owner!", exc.Message);
            }

            Assert.IsFalse(result);
        }
        public void TestAddProductNullCurrency()
        {
            AuctionService auctionService = new AuctionService();
            ProductService productService = new ProductService();
            CurrencyService currencyService = new CurrencyService();
            UserService userService = new UserService();
            ProductAuctionService productAuctionService = new ProductAuctionService();
            RoleService roleService = new RoleService();

            Product product = productService.GetProductById(1);
            Double price = 200;
            Currency currency = currencyService.getCurrencyById(1);

            Role role = roleService.GetRoleByName("owner");
            userService.AddRoleToUser("*****@*****.**", role);

            User user = userService.GetUserById(2);
            try
            {
                productAuctionService.AddProductAuction(user, product, price, null);
            }
            catch (EntityDoesNotExistException exc)
            {
                Assert.AreEqual("Currency is null", exc.Message);
            }
        }
 public void UpdateProductThirtyOneCharactersName()
 {
     String name = "1234567890123456789012345678901";
     int id = 2;
     ProductService ProductService = new ProductService();
     Boolean result = false;
     try
     {
         result = ProductService.UpdateProduct(id, name);
     }
     catch (ValidationException exc)
     {
         Assert.AreEqual("Invalid product's name.", exc.Message);
     }
     Assert.AreEqual(false, result);
 }
        public void UpdateProductSameName()
        {
            String name = "product";
            int id = 7;
            ProductService productService = new ProductService();

            Boolean result = false;
            try
            {
                result = productService.UpdateProduct(id, name);
            }
            catch (EntityDoesNotExistException exc)
            {
                Assert.AreEqual("", exc.Message);
            }
            Assert.AreEqual(true, result);
            Product product = productService.GetProductById(id);
            Assert.AreEqual(product.Name, name);
        }
        public void UpdateProductSameDescription()
        {
            String description = "abcdefghijabcdefghijabcdefghij";
            int id = 7;
            ProductService productService = new ProductService();

            Boolean result = false;
            try
            {
                result = productService.UpdateProductDescription(id, description);
            }
            catch (EntityDoesNotExistException exc)
            {
                Assert.AreEqual("", exc.Message);
            }
            Assert.AreEqual(true, result);
            Product product = productService.GetProductById(id);
            Assert.AreEqual(product.Description, description);
        }
        public void UpdateProductNullDescription()
        {
            String description = "Product";
            int id = 100;
            ProductService productService = new ProductService();

            Boolean result = false;
            try
            {
                result = productService.UpdateProductDescription(id, description);
            }
            catch (EntityDoesNotExistException exc)
            {
                Assert.AreEqual("Product is null", exc.Message);
            }
            Assert.AreEqual(false, result);
        }
 public void UpdateProductNameNull()
 {
     String name = null;
     int id = 2;
     ProductService ProductService = new ProductService();
     Boolean result = false;
     try
     {
         result = ProductService.UpdateProduct(id, name);
     }
     catch (ValidationException exc)
     {
         Assert.AreEqual("Invalid product's name.", exc.Message);
     }
     Assert.AreEqual(false, result);
 }
        public void UpdateProductDuplicateName()
        {
            Product product = new Product();
            product.Name = "Product1";
            product.Description = "Description";
            CategoryService categoryService = new CategoryService();
            Category category = categoryService.GetCategoryById(8);
            product.Categories.Add(category);
            ProductService productService = new ProductService();
            productService.AddProduct(product);

            String name = "Product";
            int id = 19;
            Product p = productService.GetProductById(id);
            Boolean result = false;
            try
            {
                result = productService.UpdateProduct(id, name);
            }
            catch (DuplicateException exc)
            {
                Assert.AreEqual("The same product already exists - same name, description and category", exc.Message);
            }
            Assert.AreEqual(false, result);
        }
        public void TestAddProductAuctionSameUser()
        {
            AuctionService auctionService = new AuctionService();
            ProductService productService = new ProductService();
            CurrencyService currencyService = new CurrencyService();
            UserService userService = new UserService();
            ProductAuctionService productAuctionService = new ProductAuctionService();
            RoleService roleService = new RoleService();

            Auction auction = auctionService.GetAuctionById(1);
            Role role = roleService.GetRoleByName("actioneer");
            userService.AddRoleToUser("[email protected]", role);
            User user = userService.GetUserById(1);
            Product product = productService.GetProductById(1);
            Double price = 100;
            Currency currency = currencyService.getCurrencyById(1);

            try
            {
                productAuctionService.AddProductAuction(user, product, price, currency);
            }
            catch (ValidationException exc)
            {
                Assert.AreEqual("The ownwer and the actioneer cannot be the same user", exc.Message);
            }
        }
        public void TestAddProductAuctionUserWithNoRole()
        {
            AuctionService auctionService = new AuctionService();
            ProductService productService = new ProductService();
            CurrencyService currencyService = new CurrencyService();
            UserService userService = new UserService();
            ProductAuctionService productAuctionService = new ProductAuctionService();
            RoleService roleService = new RoleService();

            Product product = productService.GetProductById(1);
            Double price = 20000;
            Currency currency = currencyService.getCurrencyById(1);

            User user = userService.GetUserById(3);
            try
            {
                productAuctionService.AddProductAuction(user, product, price, currency);
            }
            catch (ValidationException exc)
            {
                Assert.AreEqual("The user is not actioneer", exc.Message);
            }
        }
 public void UpdateProductThreeCharactersName()
 {
     String name = "pro";
     int id = 2;
     ProductService ProductService = new ProductService();
     Boolean result = false;
     try
     {
         result = ProductService.UpdateProduct(id, name);
     }
     catch (ValidationException exc)
     {
         Assert.AreEqual("", exc.Message);
     }
     Assert.AreEqual(true, result);
 }
        public void TestFinishAuctionAlreadyFinished()
        {
            UserService userService = new UserService();
            ProductAuctionService productAuctionService = new ProductAuctionService();
            ProductService productService = new ProductService();

            User user = userService.GetUserById(1);
            Product product = productService.GetProductById(1);
            Boolean result = false;

            try
            {
                result = productAuctionService.closeAuction(user, product);
            }
            catch (AuctionException exc)
            {
                Assert.AreEqual("Auction already closed", exc.Message);
            }
            Assert.IsFalse(result);
        }
        public void TestAddProductAuctionInvalidDate()
        {
            AuctionService auctionService = new AuctionService();
            ProductService productService = new ProductService();
            CurrencyService currencyService = new CurrencyService();
            UserService userService = new UserService();
            ProductAuctionService productAuctionService = new ProductAuctionService();
            RoleService roleService = new RoleService();

            User user = userService.GetUserById(3);
            Product product = productService.GetProductById(1);
            Double price = 101;
            Currency currency = currencyService.getCurrencyById(1);

            product.Auction.EndDate = DateTime.Today;

            Boolean result = false;
            try
            {
                result = productAuctionService.AddProductAuction(user, product, price, currency);
            }
            catch (ValidationException exc)
            {
                Assert.AreEqual("Cannot add a new auction for the selected product because it is expired", exc.Message);
            }
            Assert.AreEqual(result, false);
        }
 public void GetProductsOfACategory()
 {
     CategoryService categoryService = new CategoryService();
     ProductService productService = new ProductService();
     Category category = categoryService.GetCategoryById(8);
     ICollection<Product> products = productService.GetAllProductsOfACategory(category);
     Assert.AreEqual(products.Count(), 2);
 }
 public void GetProductInexistentById()
 {
     ProductService productService = new ProductService();
     Product product = productService.GetProductById(100);
     Assert.IsNull(product);
 }
        public void TestAddProductAuctionOwner()
        {
            AuctionService auctionService = new AuctionService();
            ProductService productService = new ProductService();
            CurrencyService currencyService = new CurrencyService();
            UserService userService = new UserService();
            ProductAuctionService productAuctionService = new ProductAuctionService();
            RoleService roleService = new RoleService();

            Product product = productService.GetProductById(1);
            Double price = 2000;
            Currency currency = currencyService.getCurrencyById(1);

            Role role = roleService.GetRoleByName("owner");
            userService.AddRoleToUser("*****@*****.**", role);

            User user = userService.GetUserById(3);
            try
            {
                productAuctionService.AddProductAuction(user, product, price, currency);
            }
            catch (ValidationException exc)
            {
                Assert.AreEqual("The user is not actioneer", exc.Message);
            }
        }
 public void UpdateProductDescriptionTwoHundredAndOneCharacters()
 {
     String description = "123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901";
     int id = 8;
     ProductService ProductService = new ProductService();
     Boolean result = false;
     try
     {
         result = ProductService.UpdateProductDescription(id, description);
     }
     catch (ValidationException exc)
     {
         Assert.AreEqual("Invalid product's description.", exc.Message);
     }
     Assert.AreEqual(false, result);
 }
        private void CheckProduct(Product product,User user)
        {
            ICategoryService categoryService = new CategoryService();
            IProductService productService = new ProductService();
            IConfiguration configuration = ConfigurationService.GetInstance();
            ICollection<Category> categorys = categoryService.GetCategorysForAProduct(product);

            int nrOfAuctions = 0;
            foreach(Category category in categorys)
            {
                ICollection<Category> parentCAtegorys = categoryService.getParents(category.IdCategory);
                ICollection<Product> products;
                foreach(Category parentCategory in parentCAtegorys)
                {
                    products = productService.GetAllProductsOfACategory(category);
                    foreach(Product productCat in products)
                    {
                        Auction auction = productService.GetAuctionOfAProduct(productCat);
                        if (auction != null && auction.User.Equals(user))
                            nrOfAuctions++;
                    }
                }
            }

            if(nrOfAuctions >= configuration.GetValue(Constants.MAX_NR_OF_AUCTION_ASSOCIATE_WITH_CATEGORY))
                throw new AuctionException("The auction can not be added because the number of auctions per category was exceeded");
        }
 public void AddProductOneCharacterName()
 {
     Product product = new Product();
     product.Name = "o";
     ProductService productService = new ProductService();
     Boolean result = false;
     try
     {
         result = productService.AddProduct(product);
     }
     catch (ValidationException exc)
     {
         Assert.AreEqual("Invalid product's name/description.", exc.Message);
     }
     Assert.AreEqual(result, false);
 }