private void moveDownButton_Click(object sender, RoutedEventArgs e)
        {
            if (splitsListBox.SelectedIndex < (splitsListBox.Items.Count - 1))
            {
                // Need to save the index because changing the list resets it to -1.
                int index = splitsListBox.SelectedIndex;
                //((SplitsViewModel)DataContext).MoveDownSplitProc(splitsListBox.SelectedIndex);
                SplitVM item = myHVM.HackSplitList[index];
                myHVM.HackSplitList.RemoveAt(index);
                myHVM.HackSplitList.Insert(index + 1, item);

                splitsListBox.SelectedIndex = index + 1;
            }
        }
        private void moveUpButton_Click(object sender, RoutedEventArgs e)
        {
            if (splitsListBox.SelectedIndex > 0)
            {
                // Need to save the index because changing the list resets it to -1.
                int index = splitsListBox.SelectedIndex;
#if false
                ((SplitsViewModel)DataContext).MoveUpSplitProc(splitsListBox.SelectedIndex);
#else
                SplitVM item = myHVM.HackSplitList[index];
                myHVM.HackSplitList.RemoveAt(index);
                myHVM.HackSplitList.Insert(index - 1, item);
                //NotifyPropertyChanged("SplitList");
#endif

                splitsListBox.SelectedIndex = index - 1;
            }
        }
Example #3
0
        public void CurrentChallenge_Set()
        {
            // ARRANGE
            // Mock the existence of a database with several challenges in it.
            string        newCurrentName = "new current challenge";
            List <string> challengeNames = new List <string>
            {
                "challenge 1",
                "challenge 2",
                "challenge 3",
                newCurrentName,
                "challenge 4"
            };

            mockModel.Setup(m => m.GetChallenges())
            .Returns(challengeNames);

            // Needs some splits for the mentioned challenges.
            // The inital current challenge is not interesting.
            mockModel.Setup(m => m.GetSplits("challenge 2"))
            .Returns(new List <Split>());
            // The new current challenge needs some splits so that we have
            // something to validate.
            List <Split> newSplits = new List <Split>
            {
                new Split {
                    Handle = 0, Name = "split 1"
                },
                new Split {
                    Handle = 1, Name = "split 2"
                }
            };

            mockModel.Setup(m => m.GetSplits(newCurrentName))
            .Returns(newSplits);

            // Return an empty run list for any challenge.
            mockModel.Setup(m => m.GetRuns(It.IsAny <string>()))
            .Returns(new List <Run>());

            // Specify the last used challenge.
            mockSettings.Setup(us => us.GetUserSetting("LastUsedChallenge"))
            .Returns("challenge 2");

            // For this we need our own object.
            SplitsViewModel mySvm = new SplitsViewModel(mockSettings.Object, mockModel.Object);

            // ACT

            // The first time does real work.
            mySvm.CurrentChallenge = newCurrentName;

            // The second time should be a nop.
            mySvm.CurrentChallenge = newCurrentName;

            // ASSERT
            Assert.AreEqual(newCurrentName, mySvm.CurrentChallenge);
            Assert.AreEqual(-1, mySvm.CurrentSplit);
            Assert.AreEqual(2, mySvm.SplitList.Count);
            SplitVM testSplit = new SplitVM
            {
                SplitName      = "split 1",
                CurrentValue   = 0,
                CurrentPbValue = 9999
            };

            Assert.AreEqual <SplitVM>(testSplit, mySvm.SplitList[0]);
            testSplit.SplitName = "split 2";
            Assert.AreEqual <SplitVM>(testSplit, mySvm.SplitList[1]);
            mockSettings.Verify(us => us.SetUserSetting("LastUsedChallenge", newCurrentName));

            // Verify efficient operation.
            mockModel.Verify(mm => mm.GetSplits(newCurrentName), Times.AtMostOnce());
            mockModel.Verify(mm => mm.GetRuns(newCurrentName), Times.AtMostOnce());
        }