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 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 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 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 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 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 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 GetProductExistentById()
 {
     ProductService productService = new ProductService();
     Product product = productService.GetProductById(3);
     Assert.AreEqual("AAAAAAAA8" ,product.Description);
 }
        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 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 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 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 GetProductInexistentById()
 {
     ProductService productService = new ProductService();
     Product product = productService.GetProductById(100);
     Assert.IsNull(product);
 }
        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 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 GetAuctionOfAProduct()
 {
     ProductService productService = new ProductService();
     Product product = productService.GetProductById(16);
     Auction auction = productService.GetAuctionOfAProduct(product);
     Assert.IsNull(auction);
 }