public void TestSaveAndDeleteCard()
        {
            DataModel model = new DataModel(path);

            model.DeleteAll(); //Completely clears the data!!!! DO NOT USE IN ACTUAL CODE - TESTING METHOD

            //Setup
            RevisionCardSQL[] testCards  = new RevisionCardSQL[5];
            string[]          topicNames = { "Pancakes", "Chemistry", "Nuclear Physics" };

            //Save to file
            for (int i = 0; i < topicNames.Length; i++)
            {
                model.SaveTopic(new TopicSQL()
                {
                    TopicName = topicNames[i]
                });
                for (int j = 0; j < testCards.Length; j++)
                {
                    testCards[j] = new RevisionCardSQL()
                    {
                        Topic = topicNames[i], Answer = "A" + j.ToString(), Question = "Q" + j.ToString()
                    };
                    model.SaveCard(testCards[j]);
                }
            }

            //Read from file
            model.LoadData();

            //Test
            for (int i = 0; i < topicNames.Length; i++)
            {
                for (int j = 0; j < testCards.Length; j++)
                {
                    var             topic       = model.GetTopicByName(topicNames[i]);
                    RevisionCardSQL fetchedCard = model.RevisionGroups[topic][j];

                    Assert.AreEqual("Q" + j.ToString(), fetchedCard.Question);
                    Assert.AreEqual("A" + j.ToString(), fetchedCard.Answer);
                }
            }
            //Setup for testing of deleting cards
            for (int i = 0; i < model.RevisionGroups.Count; i++)
            {
                var topic = model.GetTopicByName(topicNames[i]);
                int count = model.RevisionGroups[topic].Count;
                while (model.RevisionGroups[topic].Count > 0)
                {
                    model.SaveDeleteCard(model.RevisionGroups[topic][0]);
                }
                Assert.AreEqual(0, model.RevisionGroups[topic].Count);
            }
        }
Example #2
0
        public ManageModifyCardViewModel(IPageHelper p, RevisionCardSQL revisionCard) : base(p)
        {
            TopicIndex = 0;

            int originalTopicIndex = TopicNames.IndexOf(revisionCard.Topic);

            TopicIndex = originalTopicIndex;
            Question   = revisionCard.Question;
            Answer     = revisionCard.Answer;

            SaveChangesCommand = new Command(execute: async() =>
            {
                try
                {
                    string topic;
                    if (TopicIndex != 0)
                    {
                        topic = TopicNames[TopicIndex];                  //Change to existing topic
                    }
                    else
                    {
                        topic = TopicName;  //Change to new topic
                    }
                    model.ModifyCard(revisionCard, topic, question, answer);

                    //Ensures that last selected topic remains selected
                    TopicIndex = TopicNames.IndexOf(topic);

                    await p.MessagePopup("Saved changes", "Changes to revision card have been saved.");
                }
                catch (Exception ex)
                {
                    await p.MessagePopup("Error occurred", "Error: " + ex.Message);
                }
            });
        }
Example #3
0
        public ManageModifyCardPage(RevisionCardSQL revisionCard)
        {
            InitializeComponent();

            BindingContext = new ManageModifyCardViewModel(this, revisionCard);
        }