public void LoadTest() { ValidateLogic VL = MainTest.JsonLogic(); VL.Save(Path.Combine(MainTest.SaveLoadPath, "JSONTest.json")); ValidateLogic VL2 = new ValidateLogic(); VL2.Load(Path.Combine(MainTest.SaveLoadPath, "JSONTest.json")); VL2.Save(Path.Combine(MainTest.SaveLoadPath, "SecondJSONTest.json")); }
public void JsonTest() { ValidateLogic VL = JsonLogic(); TinaValidator validator = new TinaValidator(VL); VL.Save(Path.Combine(SaveLoadPath, "JSONTest.json")); string[] files = Directory.GetFiles(RandomJsonPath); foreach (string file in files) { File.Delete(file); } for (int i = 0; i < 1000; i++) { List <ObjectConst> ol; ol = validator.CreateRandom(); string s = ol.ForEachToString(); byte[] buffer = System.Text.Encoding.Convert(System.Text.Encoding.Unicode, System.Text.Encoding.UTF8, System.Text.Encoding.Unicode.GetBytes(s)); s = System.Text.Encoding.UTF8.GetString(buffer); if (ol.Count > 10000) { using (FileStream fs = new FileStream(Path.Combine(RandomJsonPath, $"BigJson-{i.ToString("0000")}.json"), FileMode.Create)) { BinaryWriter bw = new BinaryWriter(fs); bw.Write(buffer); bw.Close(); } TestContext.WriteLine($"{i} ObjectCount: {ol.Count}"); } try { JsonSerializer.Deserialize(s, typeof(object)); } catch (Exception ex) { TestContext.WriteLine("Wrong Happen:" + i); TestContext.WriteLine("Message:" + ex.Message); TestContext.WriteLine(s); using (FileStream fs = new FileStream(Path.Combine(WrongRecordsPath, $"DeserializeRecord-{DateTime.Now.ToString("yyyy-MM-dd-HH-mm-ss")}-{i.ToString("0000")}.json"), FileMode.Create)) { StreamWriter sw = new StreamWriter(fs); sw.WriteLine($"Message: {ex.Message}"); sw.WriteLine("Content:"); sw.Write(s); sw.Close(); } } if (!validator.Validate(ol)) { TestContext.WriteLine("-----------------------------"); TestContext.WriteLine("Wrong happen: " + i); TestContext.WriteLine(ol.ForEachToString()); TestContext.WriteLine("TotalObjectCount:" + ol.Count); //TestContext.WriteLine("Error Node:" + validator.ErrorNode.ID); //TestContext.WriteLine("Node Type:" + validator.ErrorNode.GetType().Name); string ss = ""; for (int j = (int)validator.LongerErrorLocation - 5; j < validator.LongerErrorLocation + 5; j++) { if (j >= 0 && j < ol.Count) { ss += ol[j].ToString(); } if (j == validator.LongerErrorLocation) { ss += "!"; } } TestContext.WriteLine("NearbyString:" + ss); TestContext.WriteLine("Error Location:" + validator.LongerErrorLocation); JsonSerializerOptions jso = new JsonSerializerOptions { WriteIndented = true, MaxDepth = 128 }; jso.Converters.Add(new Aritiafel.Locations.StorageHouse.DefaultJsonConverterFactory()); using (FileStream fs = new FileStream(Path.Combine(WrongRecordsPath, $"TestRecord-{DateTime.Now.ToString("yyyy-MM-dd-HH-mm-ss")}-{i.ToString("0000")}.json"), FileMode.Create)) { StreamWriter sw = new StreamWriter(fs); sw.Write(JsonSerializer.Serialize(ol, jso)); sw.Close(); } } } TestContext.WriteLine("Test End"); }