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 AddingNullPriceRangeTest()
        {
            IStorage    storage     = new MockStorage();
            Preferences preferences = new Preferences(storage);

            Assert.Throws <ArgumentNullException>(() =>
            {
                preferences.AddPriceRange(null, 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);
            });
        }
Example #6
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 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);
        }