Skip to content

Commit

Permalink
Updated examples, added new jobs (#357)
Browse files Browse the repository at this point in the history
  • Loading branch information
falleretic authored Nov 1, 2023
1 parent 9d035c8 commit 18baa3f
Show file tree
Hide file tree
Showing 36 changed files with 447 additions and 951 deletions.
14 changes: 14 additions & 0 deletions .github/workflows/pull_request.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
name: Create pull request
on: workflow_dispatch

jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Create Pull Request
uses: peter-evans/create-pull-request@v4
with:
commit-message: Updated API version
base: main
branch: main
41 changes: 41 additions & 0 deletions .github/workflows/run_tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
name: Run API tests
on:
push:
workflow_dispatch:

jobs:
build:
runs-on: windows-latest
steps:
- uses: actions/checkout@v4
- name: Setup .NET
uses: actions/setup-dotnet@v3
- name: Install fonts
run: dism /online /enable-feature /featurename:ServerCoreFonts-NonCritical-Fonts-TrueType /Source:O:\ /LimitAccess
- name: Build ENV
run: mkdir ./Examples/Data/License/
- name: Add total license
uses: timheuer/[email protected]
with:
fileName: 'Aspose.Total.NET.lic'
fileDir: './Examples/Data/License/'
encodedString: ${{ secrets.API_LICENSE }}
- name: Add words license
uses: timheuer/[email protected]
with:
fileName: 'Aspose.Words.NET.lic'
fileDir: './Examples/Data/License/'
encodedString: ${{ secrets.API_WORDS_LICENSE }}
- name: Restore dependencies
run: dotnet restore ./Examples/ApiExamples/ApiExamples/ApiExamples.csproj
- name: Build
run: dotnet build --no-restore ./Examples/ApiExamples/ApiExamples/ApiExamples.csproj
- name: Test
run: dotnet test --no-build --verbosity normal --logger trx --results-directory "TestResults" ./Examples/ApiExamples/ApiExamples/ApiExamples.csproj
- name: Upload dotnet test results
uses: actions/upload-artifact@v3
with:
name: test-results
path: TestResults
# Use always() to always run this step to publish test results when there are test failures
if: ${{ always() }}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ jobs:
runs-on: windows-latest
steps:
# Sync branch
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- uses: actions/setup-dotnet@v3

# Restore packages
Expand Down Expand Up @@ -44,3 +44,12 @@ jobs:
run: dotnet build ./Examples/ApiExamples/Runner.MAUI/Runner.MAUI.csproj
- name: Build DocsExamples
run: dotnet build ./Examples/DocsExamples/DocsExamples/DocsExamples.csproj

# Commit changes
- name: Commit changes
run: |
git config user.name github-actions
git config user.email [email protected]
git add .
git commit -m "Updated API versions"
git push
37 changes: 33 additions & 4 deletions Examples/ApiExamples/ApiExamples/ApiExampleBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
//////////////////////////////////////////////////////////////////////////

using System;
using System.Collections;
using System.Globalization;
using System.IO;
using System.Linq;
Expand Down Expand Up @@ -44,7 +45,12 @@ public void SetUp()
Assert.Ignore("Test skipped on mono");
}

Console.WriteLine($"Clr: {RuntimeInformation.FrameworkDescription}\n");
if (CheckForSkipGitHub() && IsRunningOnGitHub())
{
Assert.Ignore("Test skipped on GitHub");
}

Console.WriteLine($"Clr: {RuntimeInformation.FrameworkDescription}\n");
}

[OneTimeTearDown]
Expand All @@ -65,14 +71,37 @@ private static bool CheckForSkipMono()
return skipMono;
}

/// <summary>
/// Checks when we need to ignore test on GitHub.
/// </summary>
private static bool CheckForSkipGitHub()
{
bool skipGitHub = TestContext.CurrentContext.Test.Properties["Category"].Contains("SkipGitHub");
return skipGitHub;
}

/// <summary>
/// Determine if runtime is GitHub.
/// </summary>
/// <returns>True if being executed in GitHub, false otherwise.</returns>
internal static bool IsRunningOnGitHub()
{
string runEnv = Environment.GetEnvironmentVariable("RUNNER_ENVIRONMENT");
if (runEnv != null && runEnv.Equals("github-hosted"))
return true;
else
return false;
}

/// <summary>
/// Determine if runtime is Mono.
/// Workaround for .netcore.
/// </summary>
/// <returns>True if being executed in Mono, false otherwise.</returns>
internal static bool IsRunningOnMono() {
internal static bool IsRunningOnMono()
{
return Type.GetType("Mono.Runtime") != null;
}
}

internal static void SetUnlimitedLicense()
{
Expand Down Expand Up @@ -140,7 +169,7 @@ internal static string GetAssemblyDir(Assembly assembly)
/// Gets the path to the documents used by the code examples. Ends with a back slash.
/// </summary>
internal static string ArtifactsDir { get; }

/// <summary>
/// Gets the path to the documents used by the code examples. Ends with a back slash.
/// </summary>
Expand Down
14 changes: 7 additions & 7 deletions Examples/ApiExamples/ApiExamples/ApiExamples.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>net48;net6.0</TargetFrameworks>
<TargetFrameworks>net48;net7.0</TargetFrameworks>
<Platforms>AnyCPU</Platforms>
</PropertyGroup>

Expand Down Expand Up @@ -124,11 +124,11 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Aspose.BarCode" Version="23.8.1" />
<PackageReference Include="Aspose.Page" Version="23.8.0" />
<PackageReference Include="Aspose.PDF" Version="23.8.0" />
<PackageReference Include="Aspose.Words" Version="23.9.0" />
<PackageReference Include="Aspose.Words.Shaping.HarfBuzz" Version="23.9.0" />
<PackageReference Include="Aspose.BarCode" Version="23.9.0" />
<PackageReference Include="Aspose.Page" Version="23.10.0" />
<PackageReference Include="Aspose.PDF" Version="23.9.0" />
<PackageReference Include="Aspose.Words" Version="23.10.0" />
<PackageReference Include="Aspose.Words.Shaping.HarfBuzz" Version="23.10.0" />
<PackageReference Include="BouncyCastle.Cryptography" Version="2.2.1" />
<PackageReference Include="Microsoft.Extensions.Http" Version="7.0.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.7.2" />
Expand All @@ -146,7 +146,7 @@
<Reference Include="Interop.ADODB">
<HintPath>..\..\Data\Dlls\Interop.ADODB.dll</HintPath>
</Reference>
<Reference Include="System.Web" Condition="'$(TargetFramework)' != 'net6.0'" />
<Reference Include="System.Web" Condition="'$(TargetFramework)' != 'net7.0'" />
<Reference Include="System.Windows.Forms" Condition="$(TargetFramework.StartsWith('net4'))" />
</ItemGroup>

Expand Down
7 changes: 3 additions & 4 deletions Examples/ApiExamples/ApiExamples/CustomBarcodeGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -177,9 +177,8 @@ public Image GetBarcodeImage(BarcodeParameters parameters)
}

#if NET48 || JAVA
return generator.GenerateBarCodeImage();

#elif NET5_0_OR_GREATER || __MOBILE__
return generator.GenerateBarCodeImage();
#elif NET5_0_OR_GREATER
generator.GenerateBarCodeImage().Save(ArtifactsDir + "GetBarcodeImage.png");
return Image.Decode(ArtifactsDir + "GetBarcodeImage.png");
#endif
Expand All @@ -203,7 +202,7 @@ public Image GetOldBarcodeImage(BarcodeParameters parameters)
// Hardcode type for old-fashioned Barcode
#if NET48 || JAVA
return generator.GenerateBarCodeImage();
#elif NET5_0_OR_GREATER || __MOBILE__
#elif NET5_0_OR_GREATER
generator.GenerateBarCodeImage().Save(ArtifactsDir + "OldBarcodeImage.png");
return Image.Decode(ArtifactsDir + "OldBarcodeImage.png");
#endif
Expand Down
5 changes: 1 addition & 4 deletions Examples/ApiExamples/ApiExamples/ExCertificateHolder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,13 @@
using System.Security;
using Aspose.Words.DigitalSignatures;
using NUnit.Framework;
#if NET48 || MAC || JAVA
using Org.BouncyCastle.Pkcs;
#endif

namespace ApiExamples
{
[TestFixture]
public class ExCertificateHolder : ApiExampleBase
{
#if NET48 || MAC || JAVA
[Test]
public void Create()
{
Expand Down Expand Up @@ -59,6 +57,5 @@ public void Create()
CertificateHolder.Create(MyDir + "morzal.pfx", "aw", null);
//ExEnd
}
#endif
}
}
8 changes: 5 additions & 3 deletions Examples/ApiExamples/ApiExamples/ExDocSaveOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -170,12 +170,14 @@ public void AlwaysCompressMetafiles(bool compressAllMetafiles)
saveOptions.AlwaysCompressMetafiles = compressAllMetafiles;

doc.Save(ArtifactsDir + "DocSaveOptions.AlwaysCompressMetafiles.docx", saveOptions);
//ExEnd

var testedFileLength = new FileInfo(ArtifactsDir + "DocSaveOptions.AlwaysCompressMetafiles.docx").Length;

if (compressAllMetafiles)
Assert.That(10000, Is.LessThan(new FileInfo(ArtifactsDir + "DocSaveOptions.AlwaysCompressMetafiles.docx").Length));
Assert.That(testedFileLength, Is.LessThan(14000));
else
Assert.That(30000, Is.AtLeast(new FileInfo(ArtifactsDir + "DocSaveOptions.AlwaysCompressMetafiles.docx").Length));
//ExEnd
Assert.That(testedFileLength, Is.LessThan(22000));
}
}
}
4 changes: 2 additions & 2 deletions Examples/ApiExamples/ApiExamples/ExDocument.cs
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ public void SaveToImageStream()
Assert.AreEqual(1056, image.Height);
}
}
#elif NET5_0_OR_GREATER || __MOBILE__
#elif NET5_0_OR_GREATER
using (MemoryStream stream = new MemoryStream())
{
doc.Save(stream, SaveFormat.Bmp);
Expand Down Expand Up @@ -2641,7 +2641,7 @@ public void ImageWatermark()

#if NET48 || JAVA
doc.Watermark.SetImage(Image.FromFile(ImageDir + "Logo.jpg"), imageWatermarkOptions);
#elif NET5_0_OR_GREATER || __MOBILE__
#elif NET5_0_OR_GREATER
using (SKBitmap image = SKBitmap.Decode(ImageDir + "Logo.jpg"))
{
doc.Watermark.SetImage(image, imageWatermarkOptions);
Expand Down
2 changes: 0 additions & 2 deletions Examples/ApiExamples/ApiExamples/ExDocumentBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,6 @@ public void BackgroundShape()
Assert.AreEqual(ColorType.Rgb, pdfDocImage.GetColorType());
}

#if NET48 || JAVA
//ExStart
//ExFor:DocumentBase.ResourceLoadingCallback
//ExFor:IResourceLoadingCallback
Expand Down Expand Up @@ -275,6 +274,5 @@ private async Task TestResourceLoadingCallback(Document doc)

await TestUtil.VerifyWebResponseStatusCode(HttpStatusCode.OK, "http://www.google.com/images/logos/ps_logo2.png");
}
#endif
}
}
55 changes: 3 additions & 52 deletions Examples/ApiExamples/ApiExamples/ExDocumentBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,6 @@ public async Task PushPopFont()
await TestUtil.VerifyWebResponseStatusCode(HttpStatusCode.OK, ((FieldHyperlink)doc.Range.Fields[0]).Address);
}

#if NET48 || JAVA
[Test]
public void InsertWatermark()
{
Expand All @@ -328,9 +327,8 @@ public void InsertWatermark()
DocumentBuilder builder = new DocumentBuilder(doc);

// Insert the image into the header so that it will be visible on every page.
Image image = Image.FromFile(ImageDir + "Transparent background logo.png");
builder.MoveToHeaderFooter(HeaderFooterType.HeaderPrimary);
Shape shape = builder.InsertImage(image);
Shape shape = builder.InsertImage(ImageDir + "Transparent background logo.png");
shape.WrapType = WrapType.None;
shape.BehindText = true;

Expand Down Expand Up @@ -410,53 +408,6 @@ public void InsertOleObject()
Assert.AreEqual("PowerPoint.Show.12", shape.OleFormat.ProgId);
Assert.AreEqual(".pptx", shape.OleFormat.SuggestedExtension);
}
#elif NET5_0_OR_GREATER || __MOBILE__
[Test]
public void InsertWatermarkNetStandard2()
{
//ExStart
//ExFor:DocumentBuilder.MoveToHeaderFooter
//ExFor:PageSetup.PageWidth
//ExFor:PageSetup.PageHeight
//ExFor:WrapType
//ExFor:RelativeHorizontalPosition
//ExFor:RelativeVerticalPosition
//ExSummary:Shows how to insert an image, and use it as a watermark (.NetStandard 2.0).
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);

// Insert the image into the header so that it will be visible on every page.
builder.MoveToHeaderFooter(HeaderFooterType.HeaderPrimary);

using (SKBitmap image = SKBitmap.Decode(ImageDir + "Transparent background logo.png"))
{
builder.MoveToHeaderFooter(HeaderFooterType.HeaderPrimary);
Shape shape = builder.InsertImage(image);
shape.WrapType = WrapType.None;
shape.BehindText = true;

// Place the image at the center of the page.
shape.RelativeHorizontalPosition = RelativeHorizontalPosition.Page;
shape.RelativeVerticalPosition = RelativeVerticalPosition.Page;
shape.Left = (builder.PageSetup.PageWidth - shape.Width) / 2;
shape.Top = (builder.PageSetup.PageHeight - shape.Height) / 2;
}

doc.Save(ArtifactsDir + "DocumentBuilder.InsertWatermarkNetStandard2.docx");
//ExEnd

doc = new Document(ArtifactsDir + "DocumentBuilder.InsertWatermarkNetStandard2.docx");
Shape outShape = (Shape)doc.FirstSection.HeadersFooters[HeaderFooterType.HeaderPrimary].GetChild(NodeType.Shape, 0, true);

TestUtil.VerifyImageInShape(400, 400, ImageType.Png, outShape);
Assert.AreEqual(WrapType.None, outShape.WrapType);
Assert.True(outShape.BehindText);
Assert.AreEqual(RelativeHorizontalPosition.Page, outShape.RelativeHorizontalPosition);
Assert.AreEqual(RelativeVerticalPosition.Page, outShape.RelativeVerticalPosition);
Assert.AreEqual((doc.FirstSection.PageSetup.PageWidth - outShape.Width) / 2, outShape.Left);
Assert.AreEqual((doc.FirstSection.PageSetup.PageHeight - outShape.Height) / 2, outShape.Top);
}
#endif

[Test]
public void InsertHtml()
Expand Down Expand Up @@ -2810,7 +2761,7 @@ public enum FormatInvocationType
}
//ExEnd

[Test, Ignore("Failed")]
[Test]
public async Task InsertVideoWithUrl()
{
//ExStart
Expand All @@ -2819,7 +2770,7 @@ public async Task InsertVideoWithUrl()
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);

builder.InsertOnlineVideo("https://youtu.be/t_1LYZ102RA", 360, 270);
builder.InsertOnlineVideo("https://youtu.be/g1N9ke8Prmk", 360, 270);

// We can watch the video from Microsoft Word by clicking on the shape.
doc.Save(ArtifactsDir + "DocumentBuilder.InsertVideoWithUrl.docx");
Expand Down
Loading

0 comments on commit 18baa3f

Please sign in to comment.