public void TestAddingInitialWater() { string json = ReflectionUtilities.GetResourceAsString("UnitTests.Core.ApsimFile.Soil.json"); ConverterReturnType result = Converter.DoConvert(json, Converter.LatestVersion); IEnumerable <JObject> initialWaters = JsonUtilities.Children(result.Root).Where(c => string.Equals(c["Name"].ToString(), "Initial water", StringComparison.InvariantCultureIgnoreCase)); Assert.AreEqual(1, initialWaters.Count()); Assert.AreEqual("Models.Soils.Sample, Models", initialWaters.First()["$type"].ToString()); }
/// <summary> /// Upgrade a file to the latest APSIM version. /// </summary> /// <param name="file">The name of the file to upgrade.</param> private static void UpgradeFile(string file) { string contents = File.ReadAllText(file); ConverterReturnType converter = Converter.DoConvert(contents, fileName: file); if (converter.DidConvert) { File.WriteAllText(file, converter.Root.ToString()); } }
/// <summary> /// Upgrade a file to the latest APSIM version. /// </summary> /// <param name="fileName">The name of the file to upgrade.</param> /// <param name="recurse">Recurse though child folders?</param> private static void UpgradeFile(string fileName, bool recurse) { string dir = Path.GetDirectoryName(fileName); if (string.IsNullOrWhiteSpace(dir)) { dir = Directory.GetCurrentDirectory(); } string[] files = Directory.EnumerateFiles(dir, Path.GetFileName(fileName), recurse ? SearchOption.AllDirectories : SearchOption.TopDirectoryOnly).ToArray(); foreach (string file in files) { string contents = File.ReadAllText(file); ConverterReturnType converter = Converter.DoConvert(contents, fileName: file); if (converter.DidConvert) { File.WriteAllText(file, converter.Root.ToString()); } Console.WriteLine("Successfully upgraded " + file); } }