public void TestNew() { Core.Models.Sheet doc = new Core.Models.Sheet(); Assert.IsNotNull(doc, "doc should not be null"); Assert.AreEqual("sansserif", doc.RulesFont.Family); doc.RulesFont.Family = "Cascadia Code"; Assert.AreEqual("Cascadia Code", doc.RulesFont.Family); TestHeaderFooter(doc); }
public void TestSerializeToFile() { Core.Models.Sheet doc = new Core.Models.Sheet(); // Use the name of the test file as the Document.File property string file = "WinPrint.Test.New.json"; Assert.AreEqual("WinPrint.Test.New.json", file); string jsonString = JsonSerializer.Serialize(doc, jsonOptions);; var writerOptions = new JsonWriterOptions { Indented = true }; var documentOptions = new JsonDocumentOptions { CommentHandling = JsonCommentHandling.Skip }; // Use the name of the test file as the Document.File property using (FileStream fs = File.Create(file)) using (var writer = new Utf8JsonWriter(fs, options: writerOptions)) using (JsonDocument document = JsonDocument.Parse(jsonString, documentOptions)) { JsonElement root = document.RootElement; if (root.ValueKind == JsonValueKind.Object) { writer.WriteStartObject(); } else { return; } foreach (JsonProperty property in root.EnumerateObject()) { property.WriteTo(writer); } writer.WriteEndObject(); writer.Flush(); } var docCopy = DeserializeFromFile(file); string jsonCopy = JsonSerializer.Serialize(docCopy, jsonOptions); Assert.IsNotNull(jsonCopy); Assert.AreEqual(jsonCopy, jsonString); }
public void TestPersist() { Core.Models.Sheet doc = new Core.Models.Sheet(); string json = JsonSerializer.Serialize(doc, jsonOptions); Assert.IsNotNull(json); Assert.IsTrue(json.Length > 0); var doc2 = JsonSerializer.Deserialize <Core.Models.Sheet>(json); Assert.IsNotNull(doc2); TestHeaderFooter(doc2); }
public void TestHeaderFooter(Core.Models.Sheet doc) { Assert.IsNotNull(doc.Header, "Header should not be null"); Assert.AreEqual("|{FullyQualifiedPath}", doc.Header.Text); // Default font Assert.IsNotNull(doc.Header.Font); Assert.IsNotNull(doc.Header, "Footer should not be null"); Assert.AreEqual("|{Page}/{NumPages}", doc.Footer.Text); // Default font Assert.IsNotNull(doc.Footer.Font); //public bool LeftBorder { get; set; } //public bool TopBorder { get; set; } //public bool RightBorder { get; set; } //public bool BottomBorder { get; set; } //public bool Enabled { get; set; } }