public void TestMethod1() { string fileName = "UnitTestLogger"; var logger = LogUtil.GetLogger(fileName); var target = new ObjectIniConfig("UnitTest.ini", logger); string dept = "Departure Test Location String"; string dest = "Destination Test Location String"; bool isMin = true; DateTime deptDate = DateTime.Now; DateTime retDate = DateTime.Now.AddDays(7); var obj = new ExecutionInfo { Departure = AirportDataProvider.FromIATA("HEL"), Destination = AirportDataProvider.FromIATA("SGN"), IsMinimized = isMin, DepartureDate = deptDate, ReturnDate = retDate }; target.SaveData(obj); bool actual = File.Exists(fileName); Assert.AreEqual(true, actual, "INI configuration file should be created"); var fi = new FileInfo(fileName); var length = fi.Length; Assert.AreNotEqual(0, length, "INI Configuration file should not be empty"); target.RemoveAllSections(); target.Load(fileName); var newObj = new ExecutionInfo(); // Initialize empty object target.Load(fileName); target.ApplyData(newObj); Assert.AreEqual(newObj.Departure, dept); Assert.AreEqual(newObj.Destination, dest); Assert.AreEqual(newObj.IsMinimized, isMin); Assert.AreEqual(newObj.DepartureDate, deptDate); Assert.AreEqual(newObj.ReturnDate, retDate); }
/// <summary> /// The parse. /// </summary> /// <param name="paramArgs"> /// The param args. /// </param> /// <param name="iniFilePath"> /// The ini file path. /// </param> /// <param name="logger"> /// The logger. /// </param> /// <param name="param"> /// The param. /// </param> /// <returns> /// The <see cref="bool"/>. /// </returns> /// <exception cref="ApplicationException"> /// </exception> public static bool Parse(string[] paramArgs, string iniFilePath, ILogger logger, out ExecutionParam param) { paramArgs = paramArgs ?? new string[0]; var result = new ExecutionParam(); int tempI; var parser = new Parser(switches.Length); parser.ParseStrings(switches, paramArgs); if (!string.IsNullOrEmpty(iniFilePath)) { var iniParser = new ObjectIniConfig(iniFilePath, logger); iniParser.LoadINI(); iniParser.ApplyData(result); result.ConfigHandler = iniParser; } result.IsMinimized = parser[0].ThereIs; result.AutoSync = parser[1].ThereIs; DateTime tempD; if (parser[2].ThereIs) { if (!DateTime.TryParseExact(parser[2].PostStrings[0].ToString(), DATE_FORMAT_PARAM, null, DateTimeStyles.AssumeLocal, out tempD)) { throw new ApplicationException("Invalid departure date"); } result.DepartureDate = tempD; } if (parser[4].ThereIs) { if (!DateTime.TryParseExact(parser[4].PostStrings[0].ToString(), DATE_FORMAT_PARAM, null, DateTimeStyles.AssumeLocal, out tempD)) { throw new ApplicationException("Invalid return date"); } result.ReturnDate = tempD; } if (parser[6].ThereIs) { if (!int.TryParse(parser[6].PostStrings[0].ToString(), out tempI)) { throw new ApplicationException("Invalid minimum stay duration"); } result.MinStayDuration = tempI; } else { result.MinStayDuration = Settings.Default.DefaultDurationMin; } if (parser[7].ThereIs) { if (!int.TryParse(parser[7].PostStrings[0].ToString(), out tempI)) { throw new ApplicationException("Invalid maximum stay duration"); } result.MaxStayDuration = tempI; } else { result.MaxStayDuration = Settings.Default.DefaultDurationMax; } if (parser[8].ThereIs) { if (!int.TryParse(parser[8].PostStrings[0].ToString(), out tempI)) { throw new ApplicationException("Invalid price limit"); } result.PriceLimit = tempI; } else { result.PriceLimit = Settings.Default.DefaultPriceLimit; } if (parser[9].ThereIs) { result.OperationMode = (OperationMode)Enum.Parse(typeof(OperationMode), parser[9].PostStrings[0].ToString(), true); if (result.OperationMode != OperationMode.Unspecified) { result.DepartureDateRange = DateRangeDiff.Parse(parser[3].PostStrings[0].ToString()); result.ReturnDateRange = DateRangeDiff.Parse(parser[5].PostStrings[0].ToString()); } } if (parser[10].ThereIs) { result.Departure = AirportDataProvider.FromIATA(parser[10].PostStrings[0].ToString()); } if (parser[11].ThereIs) { result.Destination = AirportDataProvider.FromIATA(parser[11].PostStrings[0].ToString()); } if (parser[13].ThereIs) { result.ExitAfterDone = true; } result.Validate(); param = result; if (parser[12].ThereIs) { return false; } return true; }