コード例 #1
0
        public void Setup()
        {
            // Mock the user settings database because we don't want the
            // unit tests using the real thing, which will screw up what
            // the user might be doing on their own.
            mockSettings = new Mock <IUserSettings>();
            // First launch means there is no value for LastUsedChallenge.
            mockSettings.Setup(us => us.GetUserSetting("LastUsedChallenge"))
            .Returns("");

            // Mock the model so that we are not dependent on a database.
            mockModel = new Mock <IHomunculusModel>();
            // With no database, the challenge list will be empty.
            mockModel.Setup(m => m.GetChallenges())
            .Returns(new List <string>());

            TestViewModel = new SplitsViewModel(mockSettings.Object, mockModel.Object);
        }
コード例 #2
0
        public CreateChallengeWindow(SplitsViewModel svm, EditMode mode)
        {
            InitializeComponent();

            Svm   = svm;
            myHVM = (HackViewModel)DataContext;
            myHVM.HackSplitList = new ObservableCollection <SplitVM>();
            foreach (var s in svm.SplitList)
            {
                myHVM.HackSplitList.Add(s);
            }

            // Set window behavior based on mode.
            Mode = mode;
            if (Mode == EditMode.Rearrange)
            {
                this.Title         = "Rearrange Challenge";
                challengeName.Text = svm.CurrentChallenge;

                // Only allow Up, Down, and Rename.
                addButton.IsEnabled      = false;
                deleteButton.IsEnabled   = false;
                moveUpButton.IsEnabled   = true;
                moveDownButton.IsEnabled = true;
                // TODO: Implement Rename feature.
            }
            else if (Mode == EditMode.Clone)
            {
                this.Title         = "Create Challenge";
                challengeName.Text = "New Challenge";

                // All features are available.
                addButton.IsEnabled      = true;
                deleteButton.IsEnabled   = true;
                moveUpButton.IsEnabled   = true;
                moveDownButton.IsEnabled = true;
                // TODO: Implement Rename feature.
            }
            else
            {
                this.Title = "ERROR: Unknown edit mode";
            }
        }
コード例 #3
0
        public void CorruptedUserSettingsFile()
        {
            //ARRANGE
            // Need to use our own test object for this one.
            Mock <IUserSettings> myMockSettings = new Mock <IUserSettings>();

            mockSettings.Setup(us => us.GetUserSetting(It.IsAny <string>()))
            .Returns("always return an invalid value in this test");

            // ACT
            SplitsViewModel mySvm = new SplitsViewModel(mockSettings.Object, mockModel.Object);

            // ASSERT
            // The split list will exist and it will be empty.
            Assert.IsNotNull(TestViewModel.SplitList);
            Assert.AreEqual(0, TestViewModel.SplitList.Count);

            // There is no current challenge.
            Assert.AreEqual("", TestViewModel.CurrentChallenge);
        }
コード例 #4
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());
        }