Skip to content

Commit

Permalink
replaced Assert.That by Assert.AreEquals, Assert.IsTrue, Assert.Throws
Browse files Browse the repository at this point in the history
  • Loading branch information
stdstring committed Mar 5, 2024
1 parent 36c1898 commit fcefd39
Show file tree
Hide file tree
Showing 25 changed files with 131 additions and 139 deletions.
2 changes: 1 addition & 1 deletion Examples/ApiExamples/ApiExamples/ExBookmarks.cs
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ public void Remove()
bookmarks.Clear();

// The text that was inside the bookmarks is still present in the document.
Assert.That(bookmarks, Is.Empty);
Assert.AreEqual(0, bookmarks.Count);
Assert.AreEqual("Text inside MyBookmark_1.\r" +
"Text inside MyBookmark_2.\r" +
"Text inside MyBookmark_3.\r" +
Expand Down
18 changes: 9 additions & 9 deletions Examples/ApiExamples/ApiExamples/ExDigitalSignatureUtil.cs
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,8 @@ public void Remove()
}

// Verify that both our output documents have no digital signatures.
Assert.That(DigitalSignatureUtil.LoadSignatures(ArtifactsDir + "DigitalSignatureUtil.LoadAndRemove.FromString.docx"), Is.Empty);
Assert.That(DigitalSignatureUtil.LoadSignatures(ArtifactsDir + "DigitalSignatureUtil.LoadAndRemove.FromStream.docx"), Is.Empty);
Assert.AreEqual(0, DigitalSignatureUtil.LoadSignatures(ArtifactsDir + "DigitalSignatureUtil.LoadAndRemove.FromString.docx").Count);
Assert.AreEqual(0, DigitalSignatureUtil.LoadSignatures(ArtifactsDir + "DigitalSignatureUtil.LoadAndRemove.FromStream.docx").Count);
//ExEnd
}

Expand All @@ -78,7 +78,7 @@ public void RemoveSignatures()
DigitalSignatureUtil.RemoveAllSignatures(MyDir + "Digitally signed.odt",
ArtifactsDir + "DigitalSignatureUtil.RemoveSignatures.odt");

Assert.That(DigitalSignatureUtil.LoadSignatures(ArtifactsDir + "DigitalSignatureUtil.RemoveSignatures.odt"), Is.Empty);
Assert.AreEqual(0, DigitalSignatureUtil.LoadSignatures(ArtifactsDir + "DigitalSignatureUtil.RemoveSignatures.odt").Count);
}

[Test]
Expand Down Expand Up @@ -196,9 +196,9 @@ public void IncorrectDecryptionPassword()
DecryptionPassword = "docPassword1"
};

Assert.That(
Assert.Throws<IncorrectPasswordException>(
() => DigitalSignatureUtil.Sign(doc.OriginalFileName, outputFileName, certificateHolder, signOptions),
Throws.TypeOf<IncorrectPasswordException>(), "The document password is incorrect.");
"The document password is incorrect.");
}

[Test]
Expand All @@ -211,8 +211,8 @@ public void NoArgumentsForSing()
DecryptionPassword = string.Empty
};

Assert.That(() => DigitalSignatureUtil.Sign(string.Empty, string.Empty, null, signOptions),
Throws.TypeOf<ArgumentException>());
Assert.Throws<ArgumentException>(
() => DigitalSignatureUtil.Sign(string.Empty, string.Empty, null, signOptions));
}

[Test]
Expand All @@ -228,8 +228,8 @@ public void NoCertificateForSign()
DecryptionPassword = "docPassword"
};

Assert.That(() => DigitalSignatureUtil.Sign(doc.OriginalFileName, outputFileName, null, signOptions),
Throws.TypeOf<ArgumentNullException>());
Assert.Throws<ArgumentNullException>(
() => DigitalSignatureUtil.Sign(doc.OriginalFileName, outputFileName, null, signOptions));
}
}
}
6 changes: 3 additions & 3 deletions Examples/ApiExamples/ApiExamples/ExDocSaveOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public void TempFolder()
doc.Save(ArtifactsDir + "DocSaveOptions.TempFolder.doc", options);

// The folder will persist with no residual contents from the load operation.
Assert.That(Directory.GetFiles(options.TempFolder), Is.Empty);
Assert.AreEqual(0, Directory.GetFiles(options.TempFolder).Length);
//ExEnd
}

Expand Down Expand Up @@ -175,9 +175,9 @@ public void AlwaysCompressMetafiles(bool compressAllMetafiles)
var testedFileLength = new FileInfo(ArtifactsDir + "DocSaveOptions.AlwaysCompressMetafiles.docx").Length;

if (compressAllMetafiles)
Assert.That(testedFileLength, Is.LessThan(14000));
Assert.IsTrue(testedFileLength < 14000);
else
Assert.That(testedFileLength, Is.LessThan(22000));
Assert.IsTrue(testedFileLength < 22000);
}
}
}
16 changes: 6 additions & 10 deletions Examples/ApiExamples/ApiExamples/ExDocument.cs
Original file line number Diff line number Diff line change
Expand Up @@ -783,8 +783,7 @@ public void AppendDocumentFromAutomation()
{
Document srcDoc = new Document();

Assert.That(() => srcDoc == new Document("C:\\DetailsList.doc"),
Throws.TypeOf<FileNotFoundException>());
Assert.Throws<FileNotFoundException>(() => new Document("C:\\DetailsList.doc"));

// Append the source document at the end of the destination document.
doc.AppendDocument(srcDoc, ImportFormatMode.UseDestinationStyles);
Expand All @@ -795,8 +794,7 @@ public void AppendDocumentFromAutomation()
// Unlink all headers/footers in this section from the previous section headers/footers
// if this is the second document or above being appended.
if (i > 1)
Assert.That(() => doc.Sections[i].HeadersFooters.LinkToPrevious(false),
Throws.TypeOf<NullReferenceException>());
Assert.Throws<NullReferenceException>(() => doc.Sections[i].HeadersFooters.LinkToPrevious(false));
}
}

Expand Down Expand Up @@ -1442,8 +1440,7 @@ public void CompareDocumentWithRevisions()
docWithRevision.StartTrackRevisions("John Doe");
builder.Writeln("This is a revision.");

Assert.That(() => docWithRevision.Compare(doc1, "John Doe", DateTime.Now),
Throws.TypeOf<InvalidOperationException>());
Assert.Throws<InvalidOperationException>(() => docWithRevision.Compare(doc1, "John Doe", DateTime.Now));
}

[Test]
Expand Down Expand Up @@ -1592,7 +1589,7 @@ public void TrackRevisions()
Assert.AreEqual(1, doc.Revisions.Count);
Assert.True(doc.FirstSection.Body.Paragraphs[0].Runs[1].IsInsertRevision);
Assert.AreEqual("John Doe", doc.Revisions[0].Author);
Assert.That(doc.Revisions[0].DateTime, Is.EqualTo(DateTime.Now).Within(10).Milliseconds);
Assert.IsTrue((DateTime.Now - doc.Revisions[0].DateTime).Milliseconds <= 10);

// Stop tracking revisions to not count any future edits as revisions.
doc.StopTrackRevisions();
Expand Down Expand Up @@ -1759,9 +1756,8 @@ public void HyphenationOptionsDefaultValues()
public void HyphenationZoneException()
{
Document doc = new Document();

Assert.That(() => doc.HyphenationOptions.HyphenationZone = 0,
Throws.TypeOf<ArgumentOutOfRangeException>());

Assert.Throws<ArgumentOutOfRangeException>(() => doc.HyphenationOptions.HyphenationZone = 0);
}

[Test]
Expand Down
13 changes: 6 additions & 7 deletions Examples/ApiExamples/ApiExamples/ExDocumentBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -204,13 +204,13 @@ public void HorizontalRuleFormatExceptions()
HorizontalRuleFormat horizontalRuleFormat = shape.HorizontalRuleFormat;
horizontalRuleFormat.WidthPercent = 1;
horizontalRuleFormat.WidthPercent = 100;
Assert.That(() => horizontalRuleFormat.WidthPercent = 0, Throws.TypeOf<ArgumentOutOfRangeException>());
Assert.That(() => horizontalRuleFormat.WidthPercent = 101, Throws.TypeOf<ArgumentOutOfRangeException>());
Assert.Throws<ArgumentOutOfRangeException>(() => horizontalRuleFormat.WidthPercent = 0);
Assert.Throws<ArgumentOutOfRangeException>(() => horizontalRuleFormat.WidthPercent = 101);

horizontalRuleFormat.Height = 0;
horizontalRuleFormat.Height = 1584;
Assert.That(() => horizontalRuleFormat.Height = -1, Throws.TypeOf<ArgumentOutOfRangeException>());
Assert.That(() => horizontalRuleFormat.Height = 1585, Throws.TypeOf<ArgumentOutOfRangeException>());
Assert.Throws<ArgumentOutOfRangeException>(() => horizontalRuleFormat.Height = -1);
Assert.Throws<ArgumentOutOfRangeException>(() => horizontalRuleFormat.Height = 1585);
}

[Test]
Expand Down Expand Up @@ -2480,8 +2480,7 @@ public void InsertOleObjectException()
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);

Assert.That(() => builder.InsertOleObject("", "checkbox", false, true, null),
Throws.TypeOf<ArgumentException>());
Assert.Throws<ArgumentException>(() => builder.InsertOleObject("", "checkbox", false, true, null));
}

[Test]
Expand Down Expand Up @@ -2559,7 +2558,7 @@ public void InsertField()
Assert.AreEqual("DATE \\@ \"dddd, MMMM dd, yyyy\"", field.GetFieldCode());

// This overload of the InsertField method automatically updates inserted fields.
Assert.That(DateTime.Parse(field.Result), Is.EqualTo(DateTime.Today).Within(1).Days);
Assert.True((DateTime.Today - DateTime.Parse(field.Result)).Days <= 1);
//ExEnd
}

Expand Down
2 changes: 1 addition & 1 deletion Examples/ApiExamples/ApiExamples/ExEditableRange.cs
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ public void IncorrectStructureException()
DocumentBuilder builder = new DocumentBuilder(doc);

// Assert that isn't valid structure for the current document.
Assert.That(() => builder.EndEditableRange(), Throws.TypeOf<InvalidOperationException>());
Assert.Throws<InvalidOperationException>(() => builder.EndEditableRange());

builder.StartEditableRange();
}
Expand Down
12 changes: 6 additions & 6 deletions Examples/ApiExamples/ApiExamples/ExField.cs
Original file line number Diff line number Diff line change
Expand Up @@ -406,9 +406,9 @@ public void InsertFieldWithFieldBuilderException()

FieldBuilder fieldBuilder = new FieldBuilder(FieldType.FieldIncludeText);

Assert.That(
Assert.Throws<ArgumentException>(
() => fieldBuilder.AddArgument(argumentBuilder).AddArgument("=").AddArgument("BestField")
.AddArgument(10).AddArgument(20.0).BuildAndInsert(run), Throws.TypeOf<ArgumentException>());
.AddArgument(10).AddArgument(20.0).BuildAndInsert(run));
}

[Test]
Expand Down Expand Up @@ -1533,7 +1533,7 @@ public void FieldAutoText()

doc = new Document(ArtifactsDir + "Field.AUTOTEXT.GLOSSARY.dotx");

Assert.That(doc.FieldOptions.BuiltInTemplatesPaths, Is.Empty);
Assert.AreEqual(0, doc.FieldOptions.BuiltInTemplatesPaths.Length);

fieldAutoText = (FieldAutoText)doc.Range.Fields[0];

Expand Down Expand Up @@ -1678,7 +1678,7 @@ public void FieldGreetingLine()

doc.MailMerge.Execute(table);

Assert.That(doc.Range.Fields, Is.Empty);
Assert.AreEqual(0, doc.Range.Fields.Count);
Assert.AreEqual("Dear Mr. Doe,\r\r\tThis is your custom greeting, created programmatically using Aspose Words!\r" +
"\fDear Mrs. Cardholder,\r\r\tThis is your custom greeting, created programmatically using Aspose Words!\r" +
"\fDear Sir or Madam,\r\r\tThis is your custom greeting, created programmatically using Aspose Words!",
Expand Down Expand Up @@ -1844,7 +1844,7 @@ public void MergeField()
Assert.AreEqual("Dear Mr. Doe:\u000cDear Mrs. Cardholder:", doc.GetText().Trim());
//ExEnd

Assert.That(doc.Range.Fields, Is.Empty);
Assert.AreEqual(0, doc.Range.Fields.Count);
}

//ExStart
Expand Down Expand Up @@ -5105,7 +5105,7 @@ public void FieldDocVariable()

// 2 - Display a custom document variable:
// Define a custom variable, then reference that variable with a DOCPROPERTY field.
Assert.That(doc.Variables, Is.Empty);
Assert.AreEqual(0, doc.Variables.Count);
doc.Variables.Add("My variable", "My variable's value");

FieldDocVariable fieldDocVariable = (FieldDocVariable)builder.InsertField(FieldType.FieldDocVariable, true);
Expand Down
4 changes: 2 additions & 2 deletions Examples/ApiExamples/ApiExamples/ExFont.cs
Original file line number Diff line number Diff line change
Expand Up @@ -161,9 +161,9 @@ public void FontInfoCollection(bool embedAllFonts)
var testedFileLength = new FileInfo(ArtifactsDir + "Font.FontInfoCollection.docx").Length;

if (embedAllFonts)
Assert.That(testedFileLength, Is.LessThan(28000));
Assert.IsTrue(testedFileLength < 28000);
else
Assert.That(testedFileLength, Is.LessThan(13000));
Assert.IsTrue(testedFileLength < 13000);
}

[TestCase(true, false, false, Description =
Expand Down
4 changes: 2 additions & 2 deletions Examples/ApiExamples/ApiExamples/ExFontSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ public void UpdatePageLayoutWarnings()
// Even though the document was rendered previously, any save warnings are notified to the user during document save
doc.Save(ArtifactsDir + "FontSettings.UpdatePageLayoutWarnings.pdf");

Assert.That(callback.FontWarnings.Count, Is.GreaterThan(0));
Assert.True(callback.FontWarnings.Count > 0);
Assert.True(callback.FontWarnings[0].WarningType == WarningType.FontSubstitution);
Assert.True(callback.FontWarnings[0].Description.Contains("has not been found"));

Expand Down Expand Up @@ -273,7 +273,7 @@ public void EnableFontSubstitution()

substitutionWarningHandler.FontWarnings.Clear();

Assert.That(substitutionWarningHandler.FontWarnings, Is.Empty);
Assert.AreEqual(0, substitutionWarningHandler.FontWarnings.Count);
}

public class HandleDocumentSubstitutionWarnings : IWarningCallback
Expand Down
2 changes: 1 addition & 1 deletion Examples/ApiExamples/ApiExamples/ExHtmlFixedSaveOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -353,7 +353,7 @@ public void PageMargins()
public void PageMarginsException()
{
HtmlFixedSaveOptions saveOptions = new HtmlFixedSaveOptions();
Assert.That(() => saveOptions.PageMargins = -1, Throws.TypeOf<ArgumentException>());
Assert.Throws<ArgumentException>(() => saveOptions.PageMargins = -1);
}

[TestCase(false)]
Expand Down
16 changes: 8 additions & 8 deletions Examples/ApiExamples/ApiExamples/ExHtmlSaveOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -94,35 +94,35 @@ public void ExportTextBoxAsSvgEpub(SaveFormat saveFormat, bool isTextBoxAsSvg)

dirFiles = Directory.GetFiles(ArtifactsDir, "HtmlSaveOptions.ExportTextBoxAsSvgEpub.001.png",
SearchOption.AllDirectories);
Assert.That(dirFiles, Is.Empty);
Assert.AreEqual(0, dirFiles.Length);
return;

case SaveFormat.Epub:

dirFiles = Directory.GetFiles(ArtifactsDir, "HtmlSaveOptions.ExportTextBoxAsSvgEpub.001.png",
SearchOption.AllDirectories);
Assert.That(dirFiles, Is.Empty);
Assert.AreEqual(0, dirFiles.Length);
return;

case SaveFormat.Mhtml:

dirFiles = Directory.GetFiles(ArtifactsDir, "HtmlSaveOptions.ExportTextBoxAsSvgEpub.001.png",
SearchOption.AllDirectories);
Assert.That(dirFiles, Is.Empty);
Assert.AreEqual(0, dirFiles.Length);
return;

case SaveFormat.Azw3:

dirFiles = Directory.GetFiles(ArtifactsDir, "HtmlSaveOptions.ExportTextBoxAsSvgEpub.001.png",
SearchOption.AllDirectories);
Assert.That(dirFiles, Is.Empty);
Assert.AreEqual(0, dirFiles.Length);
return;

case SaveFormat.Mobi:

dirFiles = Directory.GetFiles(ArtifactsDir, "HtmlSaveOptions.ExportTextBoxAsSvgEpub.001.png",
SearchOption.AllDirectories);
Assert.That(dirFiles, Is.Empty);
Assert.AreEqual(0, dirFiles.Length);
return;
}
}
Expand Down Expand Up @@ -1745,12 +1745,12 @@ public void ScaleImageToShapeSize(bool scaleImageToShapeSize)

if (scaleImageToShapeSize)
#if NET461_OR_GREATER || JAVA
Assert.That(testedImageLength, Is.LessThan(3000));
Assert.IsTrue(testedImageLength < 3000);
#elif NET5_0_OR_GREATER
Assert.That(testedImageLength, Is.LessThan(6000));
Assert.IsTrue(testedImageLength < 6000);
#endif
else
Assert.That(testedImageLength, Is.LessThan(16000));
Assert.IsTrue(testedImageLength < 16000);

}

Expand Down
Loading

0 comments on commit fcefd39

Please sign in to comment.