public void Did_People_Save_Correctly() { //We must clear out the persistence store first before we begin testing. ClearPeople(); //Local variables. string path = AppDomain.CurrentDomain.BaseDirectory; string fileLoad = path + @"\LocalData\FileStructure.txt"; string fileSave = path + @"\LocalData\Demo.xml"; //Setup Test PersonController controller = new PersonController(fileSave); var people = PersonHelpers.ParsePersonDataFromFile(fileLoad); //Conduct Test Experiment. var results = (OkNegotiatedContentResult <string>)controller.SavePeople(people); //Determine Test Results //Make sure we have results. if (results == null || string.IsNullOrEmpty(results.Content)) { Assert.IsTrue(true == false); //Test fails automatically with no data. } //Make sure we got a success result back. Assert.IsTrue(results.Content.ToUpper() == "SUCCESS"); }
/// <summary> /// The following helper method is used to create the data in the xml persistenc store. /// </summary> private string SavePeople() { //Local variables. string path = AppDomain.CurrentDomain.BaseDirectory; string fileLoad = path + @"\LocalData\FileStructure.txt"; string fileSave = path + @"\LocalData\Demo.xml"; //Setup Test PersonRepository_XML_Persistence dataStrategy = new PersonRepository_XML_Persistence(fileSave); var people = PersonHelpers.ParsePersonDataFromFile(fileLoad); //Conduct Test Experiment. dataStrategy.ClearPeople(); var results = dataStrategy.SavePeople(people); //Return results. return(results); }
/// <summary> /// React to the loading of the application. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void frmMain_Load(object sender, EventArgs e) { try { //See Actions Folder in project. //Pull out the data from each file and display it to the user. _people.AddRange(PersonHelpers.ParsePersonDataFromFile(Application.StartupPath + @"\LocalData\FileStructure1.txt")); _people.AddRange(PersonHelpers.ParsePersonDataFromFile(Application.StartupPath + @"\LocalData\FileStructure2.txt")); _people.AddRange(PersonHelpers.ParsePersonDataFromFile(Application.StartupPath + @"\LocalData\FileStructure3.txt")); //Refresh the datagrid of people. RefreshData(_people, false); } catch { //An exception can occur when dealing with files. //Since this is a demo. Just throw a dummy message. MessageBox.Show("It looks like you might have have a file in the correct place. Please double check the LocalData folder."); } }
/// <summary> /// The following helper method is used to clear out the xml persistence store. /// </summary> private void ClearPeople() { //Local variables. string path = AppDomain.CurrentDomain.BaseDirectory; string fileLoad = path + @"\LocalData\FileStructure.txt"; string fileSave = path + @"\LocalData\Demo.xml"; //Setup Test PersonRepository_XML_Persistence dataStrategy = new PersonRepository_XML_Persistence(fileSave); var people = PersonHelpers.ParsePersonDataFromFile(fileLoad); //Conduct Test Experiment. try { dataStrategy.ClearPeople(); } catch { //Do nothing... This is just clearing the data. } }