public void DatabaseFileOperations() { // Add some content to the existing default database. TestModel.CreateChallenge("challenge-ldb-1", SplitNamesBefore); TestModel.CreateChallenge("challenge-ldb-2", SplitNamesBefore); TestModel.CreateChallenge("challenge-ldb-3", SplitNamesBefore); // Create a new Model instance. ModelXml NewTestModel = new ModelXml(); // Load the existing database file into the new Model. NewTestModel.LoadDatabase(DefaultFilename); // Verify the contents of the database. List <string> challenges = NewTestModel.GetChallenges(); Assert.AreEqual(3, challenges.Count); // TODO: Can we assume the order in the list and/or in the XML file? Assert.AreEqual("challenge-ldb-1", challenges[0]); Assert.AreEqual("challenge-ldb-2", challenges[1]); Assert.AreEqual("challenge-ldb-3", challenges[2]); // TODO: Do I have to check everything here, or can I assume other tests // will provide coverage? }
public void ModifyChallenge_RenameChallenge() { string oldName = "challenge 1"; string newName = "challenge 2"; // ARRANGE List <Split> SplitsAfter = TestModel.CreateChallenge(oldName, SplitNamesBefore); // ACT TestModel.ModifyChallenge(oldName, null, newName); // ASSERT ModelXml VerifyModel = new ModelXml(); VerifyModel.LoadDatabase(DefaultFilename); List <string> challenges = VerifyModel.GetChallenges(); Assert.AreEqual(1, challenges.Count); Assert.AreEqual(newName, challenges[0]); List <Split> SplitsAfterAfter = VerifyModel.GetSplits(newName); // Verify split names. Assert.AreEqual(SplitsAfter.Count, SplitsAfterAfter.Count); Assert.AreEqual(SplitsAfter[0].Name, SplitsAfterAfter[0].Name); Assert.AreEqual(SplitsAfter[1].Name, SplitsAfterAfter[1].Name); Assert.AreEqual(SplitsAfter[2].Name, SplitsAfterAfter[2].Name); Assert.AreEqual(SplitsAfter[3].Name, SplitsAfterAfter[3].Name); // Verify that Handle didn't change. Assert.AreEqual(SplitsAfter[0].Handle, SplitsAfterAfter[0].Handle); Assert.AreEqual(SplitsAfter[1].Handle, SplitsAfterAfter[1].Handle); Assert.AreEqual(SplitsAfter[2].Handle, SplitsAfterAfter[2].Handle); Assert.AreEqual(SplitsAfter[3].Handle, SplitsAfterAfter[3].Handle); }
public void ModifyChallenge_SwapTwoSplits() { // ARRANGE // Create a new challenge. string challengeName = "new challenge"; TestModel.CreateChallenge(challengeName, SplitNamesBefore); // Get the splits. List <Split> SplitsAfter = TestModel.GetSplits(challengeName); // ACT List <Split> newSplitOrder = new List <Split>(); newSplitOrder.Add(new Split { Handle = SplitsAfter[0].Handle, Name = SplitsAfter[0].Name }); newSplitOrder.Add(new Split { Handle = SplitsAfter[1].Handle, Name = SplitsAfter[1].Name }); newSplitOrder.Add(new Split { Handle = SplitsAfter[3].Handle, Name = SplitsAfter[3].Name }); newSplitOrder.Add(new Split { Handle = SplitsAfter[2].Handle, Name = SplitsAfter[2].Name }); TestModel.ModifyChallenge(challengeName, newSplitOrder, null); // ASSERT ModelXml VerifyModel = new ModelXml(); VerifyModel.LoadDatabase(DefaultFilename); List <Split> SplitsAfterAfter = VerifyModel.GetSplits(challengeName); // Verify split names. Assert.AreEqual(newSplitOrder.Count, SplitsAfterAfter.Count); Assert.AreEqual(newSplitOrder[0].Name, SplitsAfterAfter[0].Name); Assert.AreEqual(newSplitOrder[1].Name, SplitsAfterAfter[1].Name); Assert.AreEqual(newSplitOrder[2].Name, SplitsAfterAfter[2].Name); Assert.AreEqual(newSplitOrder[3].Name, SplitsAfterAfter[3].Name); // Verify that Handle didn't change. Assert.AreEqual(newSplitOrder[0].Handle, SplitsAfterAfter[0].Handle); Assert.AreEqual(newSplitOrder[1].Handle, SplitsAfterAfter[1].Handle); Assert.AreEqual(newSplitOrder[2].Handle, SplitsAfterAfter[2].Handle); Assert.AreEqual(newSplitOrder[3].Handle, SplitsAfterAfter[3].Handle); }
public void LoadDatabase_LoadSameFileTwice() { // Load the same file twice (should be a no-op) TestModel.LoadDatabase(DefaultFilename); TestModel.LoadDatabase(DefaultFilename); // A new Model object should be able to do the same thing. ModelXml NewTestModel = new ModelXml(); NewTestModel.LoadDatabase(DefaultFilename); NewTestModel.LoadDatabase(DefaultFilename); // Now load a different file (although the contents are the same). string newFilename = "test1.xml"; if (System.IO.File.Exists(newFilename)) { System.IO.File.Delete(newFilename); } System.IO.File.Copy(DefaultFilename, newFilename); TestModel.LoadDatabase(newFilename); TestModel.LoadDatabase(newFilename); }
public void ModifyChallenge_RenameAllSplits() { // ARRANGE // Create a new challenge. string challengeName = "new challenge"; TestModel.CreateChallenge(challengeName, SplitNamesBefore); // Get the splits. List <Split> SplitsAfter = TestModel.GetSplits(challengeName); // ACT string newSplitName = "this is a new name"; foreach (var split in SplitsAfter) { split.Name = newSplitName; } TestModel.ModifyChallenge(challengeName, SplitsAfter, null); // ASSERT ModelXml VerifyModel = new ModelXml(); VerifyModel.LoadDatabase(DefaultFilename); List <Split> SplitsAfterAfter = VerifyModel.GetSplits(challengeName); // Verify split names. Assert.AreEqual(SplitsAfter.Count, SplitsAfterAfter.Count); Assert.AreEqual(newSplitName, SplitsAfterAfter[0].Name); Assert.AreEqual(newSplitName, SplitsAfterAfter[1].Name); Assert.AreEqual(newSplitName, SplitsAfterAfter[2].Name); Assert.AreEqual(newSplitName, SplitsAfterAfter[3].Name); // Verify that Handle didn't change. Assert.AreEqual(SplitsAfter[0].Handle, SplitsAfterAfter[0].Handle); Assert.AreEqual(SplitsAfter[1].Handle, SplitsAfterAfter[1].Handle); Assert.AreEqual(SplitsAfter[2].Handle, SplitsAfterAfter[2].Handle); Assert.AreEqual(SplitsAfter[3].Handle, SplitsAfterAfter[3].Handle); }
public SplitsViewModel(IUserSettings Settings, IHomunculusModel Model) { // If the caller is not supplying a user settings // interface object, just make our own. if (Settings == null) { UserSettings = new StandardUserSettings(); } else { UserSettings = Settings; } // If the caller is not supplying a model object, // just make our own. if (Model == null) { Challenges = new ModelXml(); if (System.IO.File.Exists("homunculus.xml")) { Challenges.LoadDatabase("homunculus.xml"); } else { Challenges.CreateDatabase("homunculus.xml"); } } else { Challenges = Model; } // Get the challenges and set one to current, if available. challengeList = Challenges.GetChallenges(); CurrentChallenge = (string)UserSettings.GetUserSetting("LastUsedChallenge"); SuccessButtonText = "Success"; }
public void LoadDatabase_NullFilename() { TestModel.LoadDatabase(null); }