Skip to content

Commit

Permalink
updated ApiExamples for correct porting to Python.
Browse files Browse the repository at this point in the history
  • Loading branch information
KotovDA committed Oct 30, 2024
1 parent 5a441e7 commit f30fa09
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 17 deletions.
19 changes: 15 additions & 4 deletions Examples/ApiExamples/ApiExamples/ExDocSaveOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,9 @@ public void UpdateLastPrintedProperty(bool isUpdateLastPrintedProperty)
//ExFor:SaveOptions.UpdateLastPrintedProperty
//ExSummary:Shows how to update a document's "Last printed" property when saving.
Document doc = new Document();
doc.BuiltInDocumentProperties.LastPrinted = new DateTime(2019, 12, 20);

DateTime lastPrinted = new DateTime(2019, 12, 20);
doc.BuiltInDocumentProperties.LastPrinted = lastPrinted;

// This flag determines whether the last printed date, which is a built-in property, is updated.
// If so, then the date of the document's most recent save operation
Expand All @@ -125,7 +127,10 @@ public void UpdateLastPrintedProperty(bool isUpdateLastPrintedProperty)
// Open the saved document, then verify the value of the property.
doc = new Document(ArtifactsDir + "DocSaveOptions.UpdateLastPrintedProperty.doc");

Assert.AreNotEqual(isUpdateLastPrintedProperty, new DateTime(2019, 12, 20) == doc.BuiltInDocumentProperties.LastPrinted);
if (isUpdateLastPrintedProperty)
Assert.AreNotEqual(lastPrinted, doc.BuiltInDocumentProperties.LastPrinted);
else
Assert.AreEqual(lastPrinted, doc.BuiltInDocumentProperties.LastPrinted);
//ExEnd
}

Expand All @@ -137,7 +142,9 @@ public void UpdateCreatedTimeProperty(bool isUpdateCreatedTimeProperty)
//ExFor:SaveOptions.UpdateCreatedTimeProperty
//ExSummary:Shows how to update a document's "CreatedTime" property when saving.
Document doc = new Document();
doc.BuiltInDocumentProperties.CreatedTime = new DateTime(2019, 12, 20);

DateTime createdTime = new DateTime(2019, 12, 20);
doc.BuiltInDocumentProperties.CreatedTime = createdTime;

// This flag determines whether the created time, which is a built-in property, is updated.
// If so, then the date of the document's most recent save operation
Expand All @@ -150,7 +157,11 @@ public void UpdateCreatedTimeProperty(bool isUpdateCreatedTimeProperty)
// Open the saved document, then verify the value of the property.
doc = new Document(ArtifactsDir + "DocSaveOptions.UpdateCreatedTimeProperty.docx");

Assert.AreNotEqual(isUpdateCreatedTimeProperty, new DateTime(2019, 12, 20) == doc.BuiltInDocumentProperties.CreatedTime);
if (isUpdateCreatedTimeProperty)
Assert.AreNotEqual(createdTime, doc.BuiltInDocumentProperties.CreatedTime);
else
Assert.AreEqual(createdTime, doc.BuiltInDocumentProperties.CreatedTime);

//ExEnd
}

Expand Down
4 changes: 2 additions & 2 deletions Examples/ApiExamples/ApiExamples/ExDocumentProperties.cs
Original file line number Diff line number Diff line change
Expand Up @@ -529,8 +529,8 @@ public void CustomNamedAccess()
Document doc = new Document();

doc.CustomDocumentProperties.Add("AuthorizationDate", DateTime.Now);

Console.WriteLine($"Document authorized on {doc.CustomDocumentProperties["AuthorizationDate"].ToDateTime()}");
DateTime authorizationDate = doc.CustomDocumentProperties["AuthorizationDate"].ToDateTime();
Console.WriteLine($"Document authorized on {authorizationDate}");
//ExEnd

TestUtil.VerifyDate(DateTime.Now,
Expand Down
2 changes: 1 addition & 1 deletion Examples/ApiExamples/ApiExamples/ExInlineStory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -562,7 +562,7 @@ public void InsertInlineStoryNodes()
Assert.AreEqual(StoryType.Footnotes, footnote.StoryType);

// A comment is another type of inline story.
Comment comment = builder.CurrentParagraph.AppendChild(new Comment(doc, "John Doe", "J. D.", DateTime.Now));
Comment comment = (Comment)builder.CurrentParagraph.AppendChild(new Comment(doc, "John Doe", "J. D.", DateTime.Now));

// The parent paragraph of an inline story node will be the one from the main document body.
Assert.AreEqual(doc.FirstSection.Body.FirstParagraph, comment.ParentParagraph);
Expand Down
8 changes: 5 additions & 3 deletions Examples/ApiExamples/ApiExamples/ExMarkdownSaveOptions.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// Copyright (c) 2001-2024 Aspose Pty Ltd. All Rights Reserved.
using System;
using System.Drawing;
using System.IO;
using System.Linq;
Expand Down Expand Up @@ -271,10 +272,11 @@ public void ExportTableAsHtml()
saveOptions.ExportAsHtml = MarkdownExportAsHtml.Tables;

doc.Save(ArtifactsDir + "MarkdownSaveOptions.ExportTableAsHtml.md", saveOptions);
//ExEnd:ExportTableAsHtml

//ExEnd:ExportTableAsHtml

string newLine = Environment.NewLine;
string outDocContents = File.ReadAllText(ArtifactsDir + "MarkdownSaveOptions.ExportTableAsHtml.md");
Assert.AreEqual("Sample table:\r\n<table cellspacing=\"0\" cellpadding=\"0\" style=\"width:100%; border:0.75pt solid #000000; border-collapse:collapse\">" +
Assert.AreEqual($"Sample table:{newLine}<table cellspacing=\"0\" cellpadding=\"0\" style=\"width:100%; border:0.75pt solid #000000; border-collapse:collapse\">" +
"<tr><td style=\"border-right-style:solid; border-right-width:0.75pt; padding-right:5.03pt; padding-left:5.03pt; vertical-align:top\">" +
"<p style=\"margin-top:0pt; margin-bottom:0pt; text-align:right; font-size:12pt\"><span style=\"font-family:'Times New Roman'\">Cell1</span></p>" +
"</td><td style=\"border-left-style:solid; border-left-width:0.75pt; padding-right:5.03pt; padding-left:5.03pt; vertical-align:top\">" +
Expand Down
8 changes: 4 additions & 4 deletions Examples/ApiExamples/ApiExamples/ExStyles.cs
Original file line number Diff line number Diff line change
Expand Up @@ -341,16 +341,16 @@ public void LatentStyles()
doc.Save(ArtifactsDir + "Styles.LatentStyles.docx");

TestUtil.DocPackageFileContainsString(
@"<w:lsdException w:name=""Mention"" w:semiHidden=""1"" w:unhideWhenUsed=""1"" />",
"<w:lsdException w:name=\"Mention\" w:semiHidden=\"1\" w:unhideWhenUsed=\"1\" />",
ArtifactsDir + "Styles.LatentStyles.docx", "styles.xml");
TestUtil.DocPackageFileContainsString(
@"<w:lsdException w:name=""Smart Hyperlink"" w:semiHidden=""1"" w:unhideWhenUsed=""1"" />",
"<w:lsdException w:name=\"Smart Hyperlink\" w:semiHidden=\"1\" w:unhideWhenUsed=\"1\" />",
ArtifactsDir + "Styles.LatentStyles.docx", "styles.xml");
TestUtil.DocPackageFileContainsString(
@"<w:lsdException w:name=""Hashtag"" w:semiHidden=""1"" w:unhideWhenUsed=""1"" />",
"<w:lsdException w:name=\"Hashtag\" w:semiHidden=\"1\" w:unhideWhenUsed=\"1\" />",
ArtifactsDir + "Styles.LatentStyles.docx", "styles.xml");
TestUtil.DocPackageFileContainsString(
@"<w:lsdException w:name=""Unresolved Mention"" w:semiHidden=""1"" w:unhideWhenUsed=""1"" />",
"<w:lsdException w:name=\"Unresolved Mention\" w:semiHidden=\"1\" w:unhideWhenUsed=\"1\" />",
ArtifactsDir + "Styles.LatentStyles.docx", "styles.xml");
}

Expand Down
8 changes: 5 additions & 3 deletions Examples/ApiExamples/ApiExamples/ExTxtSaveOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
// "as is", without warranty of any kind, either expressed or implied.
//////////////////////////////////////////////////////////////////////////

using System;
using System.IO;
using Aspose.Words;
using Aspose.Words.Saving;
Expand Down Expand Up @@ -205,10 +206,11 @@ public void TxtListIndentation()
doc.Save(ArtifactsDir + "TxtSaveOptions.TxtListIndentation.txt", txtSaveOptions);

string docText = File.ReadAllText(ArtifactsDir + "TxtSaveOptions.TxtListIndentation.txt");
string newLine= Environment.NewLine;

Assert.AreEqual("1. Item 1\r\n" +
" a. Item 2\r\n" +
" i. Item 3\r\n", docText);
Assert.AreEqual($"1. Item 1{newLine}" +
$" a. Item 2{newLine}" +
$" i. Item 3{newLine}", docText);
//ExEnd
}

Expand Down

0 comments on commit f30fa09

Please sign in to comment.