public void TestLoadCoachFromFile() { //Load Coach/manager from baseballreference.com Coach ret = null; InMemoryConfigurationFile coachInfoFile = null; string coachInfoFilePath = TextUtilities.FormFilePathName(ConfigurationManager.GetConfigurationValue("TEST_ROAD_TEAM_DIRECTORY_2"), "Coach", ".dat"); if (File.Exists(coachInfoFilePath)) { try { coachInfoFile = ConfigurationManager.GetInMemoryConfigFile(coachInfoFilePath); //Player-relevant fields string lName = coachInfoFile["lastName"].ToString(); string fName = coachInfoFile["firstName"].ToString(); string position = coachInfoFile["position"].ToString(); Height height = new Height(coachInfoFile["height"].ToString()); Weight weight = new Weight(Convert.ToInt32(coachInfoFile["weight"])); Birthday bDay = new Birthday(coachInfoFile["birthday"].ToString()); ret = new Coach(Guid.NewGuid().ToString(), lName, fName, "", position, Race.Unknown, Handedness.Unknown, Handedness.Unknown, height, weight, bDay); //Managerial Tendencies form Coaching Stats CoachingStats cStats = new CoachingStats(coachInfoFile); if (cStats != null) { ret.CoachingStats = cStats; } Assert.IsTrue(ret.FullName.Equals("Lou Piniella")); Assert.IsTrue(ret.CoachingStats.Rating == 91);//52 * 1.75 } catch (Exception ex) { Console.WriteLine(ex.Message); } } }
/// <summary> /// Loads the coach from file. /// </summary> /// <returns>Coach</returns> /// <param name="directory">string</param> private static Coach LoadCoachFromFile(string directory) { Coach ret = null; InMemoryConfigurationFile coachInfoFile = null; string coachInfoFilePath = TextUtilities.FormFilePathName(directory, "Coach", ".dat"); if (File.Exists(coachInfoFilePath)) { try { coachInfoFile = ConfigurationManager.GetInMemoryConfigFile(coachInfoFilePath); //Player-relevant fields string lName = coachInfoFile["lastName"].ToString(); string fName = coachInfoFile["firstName"].ToString(); string position = coachInfoFile["position"].ToString(); Height height = new Height(coachInfoFile["height"].ToString()); Weight weight = new Weight(Convert.ToInt32(coachInfoFile["weight"])); Birthday bDay = new Birthday(coachInfoFile["birthday"].ToString()); ret = new Coach(Guid.NewGuid().ToString(), lName, fName, "", position, Race.Unknown, Handedness.Unknown, Handedness.Unknown, height, weight, bDay); //Managerial Tendencies form Coaching Stats CoachingStats cStats = new CoachingStats(coachInfoFile); if (cStats != null) { ret.CoachingStats = cStats; } } catch (Exception ex) { Console.WriteLine(ex.Message); } } return(ret); }