public void RemovePriceRangeTest()
        {
            IStorage    storage     = new MockStorage();
            Preferences preferences = new Preferences(storage);

            List <string> categories = new List <string>();

            categories.Add("test_cat");
            categories.Add("test_cat2");
            categories.Add("test_cat3");

            Tuple <double, double> priceRange = new Tuple <double, double>(10.0, 100.0);

            foreach (string category in categories)
            {
                preferences.AddCategory(category);
                preferences.AddPriceRange(category, priceRange);
            }

            Assert.True(preferences.RemovePriceRange("test_cat2"));

            UserPreference userPreference = storage.GetUserPreference("test_cat2");

            Assert.Equal(0.0, userPreference._minPrice);
            Assert.Equal(0.0, userPreference._maxPrice);

            Assert.True(preferences.FindUserPreferenceFromCache("test_cat2", out userPreference));
            Assert.NotNull(userPreference);
            Assert.True(userPreference._minPrice == 0.0);
            Assert.True(userPreference._maxPrice == 0.0);
        }
        public void AddingPriceRangeTest()
        {
            IStorage    storage     = new MockStorage();
            Preferences preferences = new Preferences(storage);

            List <string> categories = new List <string>();

            categories.Add("test_cat");
            categories.Add("test_cat2");
            categories.Add("test_cat3");

            foreach (string category in categories)
            {
                preferences.AddCategory(category);
            }

            Tuple <double, double> priceRange = new Tuple <double, double>(10.0, 100.0);

            preferences.AddPriceRange("test_cat2", priceRange);

            // Check that the category was updated in the mock storage
            UserPreference userPreference = storage.GetUserPreference("test_cat2");

            Assert.Equal("test_cat2", userPreference._category);
            Assert.True(userPreference._minPrice == 10.0);
            Assert.True(userPreference._maxPrice == 100.0);

            Assert.True(preferences.FindUserPreferenceFromCache("test_cat2", out userPreference));
            Assert.NotNull(userPreference);
            Assert.True(userPreference._minPrice == 10.0);
            Assert.True(userPreference._maxPrice == 100.0);
        }
        public void RetrieveFakePreferenceFromCacheTest()
        {
            IStorage    storage     = new MockStorage();
            Preferences preferences = new Preferences(storage);

            UserPreference pref;

            Assert.False(preferences.FindUserPreferenceFromCache("cars", out pref));
        }
        public void RemovingNullCategoryTest()
        {
            IStorage    storage     = new MockStorage();
            Preferences preferences = new Preferences(storage);

            Assert.Throws <ArgumentNullException>(() =>
            {
                preferences.RemoveCategory(null);
            });
        }
        public void RemoveNullPriceRangeTest()
        {
            IStorage    storage     = new MockStorage();
            Preferences preferences = new Preferences(storage);

            Assert.Throws <ArgumentNullException>(() =>
            {
                preferences.RemovePriceRange(null);
            });
        }
        public void AddPriceWithFakeCategoryTest()
        {
            IStorage    storage     = new MockStorage();
            Preferences preferences = new Preferences(storage);

            Tuple <double, double> priceRange = new Tuple <double, double>(10.0, 100.0);

            Assert.Throws <Preferences.UserPreferenceNotFoundException>(() =>
            {
                preferences.AddPriceRange("fake_category", priceRange);
            });
        }
        public void AddPriceWithNullCategoryTest()
        {
            IStorage    storage     = new MockStorage();
            Preferences preferences = new Preferences(storage);

            Tuple <double, double> priceRange = new Tuple <double, double>(10.0, 100.0);

            Assert.Throws <ArgumentNullException>(() =>
            {
                preferences.AddPriceRange(null, priceRange);
            });
        }
Exemple #8
0
        public void FilterUndesirableItemTest()
        {
            IStorage      storage     = new MockStorage();
            Preferences   preferences = new Preferences(storage);
            FilterMessage filter      = new FilterMessage(preferences);

            BargainMessage message = new BargainMessage(
                "test", "900.50", "external_url", "image_url",
                "undesirable_category");

            preferences.AddCategory("test_category2");

            Assert.False(filter.IsDesirable(message));
        }
Exemple #9
0
        public void FilterUndesirablePriceTest()
        {
            IStorage      storage     = new MockStorage();
            Preferences   preferences = new Preferences(storage);
            FilterMessage filter      = new FilterMessage(preferences);

            BargainMessage message = new BargainMessage(
                "test", "1900.50", "external_url", "image_url",
                "test_category test_category2");

            preferences.AddCategory("test_category");
            preferences.AddPriceRange("test_category", new Tuple <double, double>(100.0, 1000.0));

            Assert.False(filter.IsDesirable(message));
        }
        public void RetrievePreferenceFromCacheTest()
        {
            IStorage    storage     = new MockStorage();
            Preferences preferences = new Preferences(storage);

            preferences.AddCategory("cars");
            preferences.AddCategory("towns");
            preferences.AddCategory("garages");

            UserPreference pref;

            Assert.True(preferences.FindUserPreferenceFromCache("cars", out pref));
            Assert.True(preferences.FindUserPreferenceFromCache("towns", out pref));
            Assert.True(preferences.FindUserPreferenceFromCache("garages", out pref));
        }
        public void RetrievePriceRangeTest()
        {
            IStorage    storage     = new MockStorage();
            Preferences preferences = new Preferences(storage);

            preferences.AddCategory("cars");

            Tuple <double, double> priceRange = new Tuple <double, double>(100.0, 856.0);

            preferences.AddPriceRange("cars", priceRange);

            Tuple <double, double> existingPriceRange = preferences.GetPriceRange("cars");

            Assert.Equal(priceRange, existingPriceRange);
        }
        public void AddingCategoriesTest()
        {
            IStorage    storage     = new MockStorage();
            Preferences preferences = new Preferences(storage);

            List <string> categories = new List <string>();

            categories.Add("gardening");
            categories.Add("electronics");
            categories.Add("test category");

            foreach (string category in categories)
            {
                Assert.True(preferences.AddCategory(category));
            }

            // Ensure these categories have been added to the mock storage
            List <UserPreference> mockPreferences = storage.GetUserPreferences();

            foreach (string category in categories)
            {
                bool found = false;
                foreach (UserPreference pref in mockPreferences)
                {
                    if (pref._category == category)
                    {
                        found = true;
                    }
                }

                Assert.True(found);
            }

            // Ensure these categories have been added to the cache storage
            foreach (string category in categories)
            {
                bool           found = false;
                UserPreference userPref;
                found = preferences.FindUserPreferenceFromCache(category, out userPref);
                Assert.True(found);
                Assert.NotNull(userPref);
            }
        }
        public void RemovingCategoriesTest()
        {
            IStorage    storage     = new MockStorage();
            Preferences preferences = new Preferences(storage);

            // Add some categories to the mock storage
            List <string> categories = new List <string>();

            categories.Add("gardening");
            categories.Add("electronics");
            categories.Add("test category");
            categories.Add("policeman");
            categories.Add("policewoman");

            foreach (string category in categories)
            {
                preferences.AddCategory(category);
            }

            // Remove some categories
            Assert.True(preferences.RemoveCategory("policeman"));
            Assert.True(preferences.RemoveCategory("policewoman"));

            // Ensure these filters are removed from the persistence storage
            List <UserPreference> mockPreferences = storage.GetUserPreferences();

            foreach (UserPreference pref in mockPreferences)
            {
                Assert.False(pref._category == "policeman");
                Assert.False(pref._category == "policewoman");
            }

            UserPreference userPrefOne, userPrefTwo;

            Assert.False(preferences.FindUserPreferenceFromCache("policeman", out userPrefOne));
            Assert.False(preferences.FindUserPreferenceFromCache("policewoman", out userPrefTwo));
        }