예제 #1
0
        private void buttonSort_Click(object sender, EventArgs e)
        {
            FavouritesList list = GetFavouritesList();

            PopulateFavourites(list.OrderBy(x => x.DisplayName).ToList());
            _isDirty = true;
        }
예제 #2
0
		[Test] public void Test_01_Add_Count_Delete()
		{
			{
				FavouritesList list = new FavouritesList();
				while (list.Count > 0)
					list.RemoveAt(0);
				list.Commit();
			}
			{
				FavouritesList list = new FavouritesList();
				Assert.IsTrue(list.Count == 0, "We just deleted all the items.  Wazzup?");
				ListViewItem item1 = Helper_CreateLVI("Anthony", "http://anthony/is/brilliant", "WebSite");
				list.Add(item1);
				Assert.IsTrue(list.Count == 1, "Just added one.");
				Assert.IsTrue(item1 == list[0],  "Just added one.");
				ListViewItem item2 = Helper_CreateLVI("Matthew", "http://matthew/is/more/brilliant", "WebSite");
				list.Add(item2);
				Assert.IsTrue(list.Count == 2, "Just added one.");
				Assert.IsTrue(item2 == list[1],  "Just added one.");
				list.Remove(item2);
				Assert.IsTrue(list.Count == 1, "Just added one.");
				Assert.IsTrue(item1 == list[0],  "Just added one.");
				list.RemoveAt(0);
				Assert.IsTrue(list.Count == 0, "Just added one.");
			}
		}
예제 #3
0
 private void Initialize()
 {
     try
     {
         _correctCardNames.Initialize();
     }
     catch (IOException)
     {
         FatalError($"IO Error reading {CorrectCardNames.FileName}");
     }
     catch (InvalidOperationException)
     {
         FatalError($"{CorrectCardNames.FileName} contains invalid entries.");
     }
     InitializeTemplate();
     try
     {
         _recentDecks = MostRecentList.Read(AppPaths.RecentDecksFilePath);
     }
     catch (IOException ex)
     {
         _recentDecks = new MostRecentList();
         ShowError("There was an error while loading recent decks.\r\n" + ex.Message);
     }
     try
     {
         _favourites = FavouritesList.Read(AppPaths.FavouritessFilePath);
     }
     catch (IOException ex)
     {
         _favourites = new FavouritesList();
         ShowError("There was an error while loading favourite decks.\r\n" + ex.Message);
     }
 }
예제 #4
0
		public void SetupSuite()
		{
			FavouritesList list = new FavouritesList();
			foreach(ListViewItem item in list)
			{
				m_listItems.Add(item);
			}
		}
예제 #5
0
        private FavouritesList GetFavouritesList()
        {
            FavouritesList list = new FavouritesList();

            foreach (object item in listBoxFavourites.Items)
            {
                list.Add((MostRecentItem)item);
            }
            return(list);
        }
예제 #6
0
		public void TearDownSuite()
		{
			FavouritesList list = new FavouritesList();
			list.Clear();
			foreach(ListViewItem item in m_listItems)
			{
				list.Add(item);
			}
			list.Commit();
		}
예제 #7
0
        private void favouritesMenuItem_ManageClick(object sender, EventArgs e)
        {
            ManageFavouritesForm dlg = new ManageFavouritesForm(_favourites);

            if (dlg.ShowDialog(this) == DialogResult.OK)
            {
                _favourites = dlg.Favourites;
                favouritesMenuItem.Favorites = _favourites;
                UpdateUiState();
            }
        }
예제 #8
0
        private void buttonOk_Click(object sender, EventArgs e)
        {
            if (!_isDirty)
            {
                DialogResult = DialogResult.Ignore;
                Close();
                return;
            }

            Favourites   = GetFavouritesList();
            DialogResult = DialogResult.OK;
            Close();
        }
예제 #9
0
		[Test] public void Test_02_Clear()
		{
			{
				FavouritesList list = new FavouritesList();
				if (list.Count == 0)
					list.Add(Helper_CreateLVI("Title", "http://someUrl", "WebSite"));
				list.Commit();
			}
			{
				FavouritesList list = new FavouritesList();
				Assert.IsTrue(list.Count > 0, "We just added an item.  Wazzup?");
				list.Clear();
				list.Commit();
				Assert.IsTrue(list.Count == 0, "Just cleared it.");
			}
			{
				FavouritesList list = new FavouritesList();
				Assert.IsTrue(list.Count == 0, "We just deleted all the items.  Wazzup?  Note that this failure is probably a persistance issue.");
			}
		}
예제 #10
0
        public ActionResult changeFavourite(int loggedInUser, int postID)
        {
            FavouritesList newEntry = new FavouritesList();

            if (db.FavouritesLists.Where(x => (x.UserId == loggedInUser) && (x.PostId == postID)).Select(x => x.ID).Count() > 0)
            { //They are unfavourating
                int id = db.FavouritesLists.Where(x => (x.UserId == loggedInUser) && (x.PostId == postID)).Select(x => x.ID).FirstOrDefault();
                newEntry = db.FavouritesLists.Find(id);
                db.FavouritesLists.Remove(newEntry);
                db.SaveChanges();
                ViewBag.favourite = 1;
            }
            else
            {//They are favourating
                newEntry.PostId = postID;
                newEntry.UserId = loggedInUser;
                db.FavouritesLists.Add(newEntry);
                db.SaveChanges();
                ViewBag.favourite = 0;
            }
            return(Json(new { newEntry, Status = "Ok", Error = "" }));
        }
예제 #11
0
 public ManageFavouritesForm(FavouritesList favourites)
 {
     InitializeComponent();
     PopulateFavourites(favourites);
 }
예제 #12
0
 private void FormMain_FormClosing(object sender, FormClosingEventArgs e)
 {
     MostRecentList.Save(AppPaths.RecentDecksFilePath, _recentDecks);
     FavouritesList.Save(AppPaths.FavouritessFilePath, _favourites);
 }
예제 #13
0
		[Test] public void Test_03_AddSavesValuesCorrectly()
		{
			{
				FavouritesList list = new FavouritesList();
				list.Clear();

				ListViewItem item = Helper_CreateLVI("Title", "http://someUrl", "WebSite");
				item.ImageIndex = 666;
				Assert.IsTrue(item.ImageIndex == 666);
				list.Add(item);
				list.Commit();
			}
			{
				FavouritesList list = new FavouritesList();
				Assert.IsTrue(list.Count == 1, "We just added it.");
				Assert.IsTrue(list[0].SubItems[0].Text == "Title");
				Assert.IsTrue(list[0].SubItems[1].Text == "http://someUrl");
				Assert.IsTrue(list[0].SubItems[2].Text == "WebSite");
				Assert.IsTrue(list[0].ImageIndex == 666);
				list.Commit();
			}
		}