Skip to content

Commit

Permalink
Merge pull request #139 from signnow/feature/thumbnails
Browse files Browse the repository at this point in the history
Feature | Thumbnails
  • Loading branch information
AlexNDRmac authored Mar 24, 2022
2 parents 1c38937 + f457fa4 commit 08fd325
Show file tree
Hide file tree
Showing 14 changed files with 226 additions and 80 deletions.
18 changes: 15 additions & 3 deletions .github/release-notes.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,24 @@
set -eu
set -o pipefail

# Get Release notes for the latest release from CHANGELOG.md
# Gets Release notes for the latest release from CHANGELOG.md
#
# This script takes description in `markdown` format from CHANGELOG.md file
# You must to use the `markdown` H2 tag for the release version
# and `markdown` H3 tag for the description
#
# Script will return the content between the first and second string occurrences
# that start with H2 markdown tag with release version: example: `## [1.0.0]`
#
# How to use:
# release-notes.sh CHANGELOG.md

startLine=$(cat < "$1" | grep -nE "^### " | head -n 1 | cut -d ":" -f 1)
finishLine=$(($(cat < "$1" | grep -nE "^## \[[0-9]" | head -n 2 | tail -n 1 | cut -d ":" -f 1) - 1))

# Searching for line which starts from markdown H2 tag: ## [1.0.0]
VERSION_PATTERN="^## \[[0-9]+\\.[0-9]+\\.[0-9]+]"

startLine=$(($(cat < "$1" | grep -nE "$VERSION_PATTERN" | head -n 1 | tail -n 1 | cut -d ":" -f 1) + 1))
finishLine=$(($(cat < "$1" | grep -nE "$VERSION_PATTERN" | head -n 2 | tail -n 1 | cut -d ":" -f 1) - 1))
changelog=$(sed -n "${startLine},${finishLine}p" "$1");

echo "${changelog}"
8 changes: 5 additions & 3 deletions .github/workflows/build_and_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ jobs:
DOTNET_NOLOGO: true # removes logo and telemetry message from first run of dotnet cli
NUGET_XMLDOC_MODE: skip # prevent the download of the XML documentation for the packages
COVERAGE_PATH: SignNow.Net.Test/bin/Debug
# Do not generate summary otherwise it leads to duplicate errors in build log
DOTNET_BUILD_ARGS: SignNow.Net --configuration Debug /consoleloggerparameters:NoSummary /property:GenerateFullPaths=true

defaults:
run:
Expand Down Expand Up @@ -94,15 +96,15 @@ jobs:

- name: Build for .NET Standard 1.2
if: matrix.framework == 'netcoreapp3.1'
run: dotnet build SignNow.Net --configuration Debug --framework netstandard1.2
run: dotnet build ${{ env.DOTNET_BUILD_ARGS }} --framework netstandard1.2

- name: Build for .NET Standard 2.0
if: matrix.framework == 'net5'
run: dotnet build SignNow.Net --configuration Debug --framework netstandard2.0
run: dotnet build ${{ env.DOTNET_BUILD_ARGS }} --framework netstandard2.0

- name: Build for .NET 4.5
if: (runner.os == 'Windows' && matrix.framework == 'net45')
run: dotnet build SignNow.Net --configuration Debug --framework net45
run: dotnet build ${{ env.DOTNET_BUILD_ARGS }} --framework net45

- name: Run Tests on ${{ matrix.framework }} with Coverage
run: |
Expand Down
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@ The format is based on [Keep a Changelog](http://keepachangelog.com)
and this project adheres to [Semantic Versioning](http://semver.org).

## [Unreleased] - TBD
### Added
- The `Thumbnail` property on `Model.SignNowDocument`, which allows you to get document thumbnails in small, medium and large image sizes

### Fixed
- Fixed fails when parsing error response from auth service [#134](https://github.com/signnow/SignNow.NET/issues/134)


## [1.0.0] - 2022-02-26
### Added
Expand Down
6 changes: 6 additions & 0 deletions SignNow.Net.Test/TestData/FakeModels/SignNowDocumentFaker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@ public class SignNowDocumentFaker : Faker<SignNowDocument>
/// "updated": "1580849001",
/// "owner": "Richie.Dickens60@gmail.com",
/// "template": true,
/// "thumbnail": {
/// "small": "https://via.placeholder.com/85x110/cccccc/9c9c9c.png?text=signNow%20test",
/// "medium": "https://via.placeholder.com/340x440/cccccc/9c9c9c.png?text=signNow%20test",
/// "large": "https://via.placeholder.com/890x1151/cccccc/9c9c9c.png?text=signNow%20test"
/// },
/// "roles": [],
/// "signatures": [],
/// "fields": [],
Expand Down Expand Up @@ -55,6 +60,7 @@ public SignNowDocumentFaker()
o.Updated = f.Date.Recent().ToUniversalTime();
o.Owner = f.Internet.Email();
o.IsTemplate = f.Random.Bool();
o.Thumbnail = new ThumbnailFaker();
});
}
}
Expand Down
24 changes: 24 additions & 0 deletions SignNow.Net.Test/TestData/FakeModels/ThumbnailFaker.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
using System;
using Bogus;
using SignNow.Net.Model;

namespace SignNow.Net.Test.FakeModels
{
/// <summary>
/// Fake model for <see cref="Thumbnail"/>
/// </summary>
public class ThumbnailFaker : Faker<Thumbnail>
{
private const string DefaultThumbnailText = "signNow test";

public ThumbnailFaker()
{
Rules((f, o) =>
{
o.Small = new Uri(f.Image.PlaceholderUrl(85, 110, DefaultThumbnailText));
o.Medium = new Uri(f.Image.PlaceholderUrl(340, 440, DefaultThumbnailText));
o.Large = new Uri(f.Image.PlaceholderUrl(890, 1151, DefaultThumbnailText));
});
}
}
}
8 changes: 4 additions & 4 deletions SignNow.Net.Test/UnitTests/Helpers/UserAgentSdkHeadersTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ public class UserAgentSdkHeadersTest
[TestMethod]
public void UserAgentStringIsCorrect()
{
// signNow .NET API Сlient/v1.0.0.0 (Windows_NT 10.0.14393; win32; ia32) .NET Core 3.1/v4.0.30319.42000
// signNow .NET API Сlient/v1.0.0.0 (Linux 3.10.0; Unix; X64) .NET Core 3.0/v4.0.30319.42000
// signNow .NET API Сlient/v1.0.0.0 (macOs 10.15.0; Unix; X64) .NET Core 3.1/v4.0.30319.42000
// SignNow .NET API Сlient/v1.0.0.0 (Windows_NT 10.0.14393; win32; ia32) .NET Core 3.1/v4.0.30319.42000
// SignNow .NET API Сlient/v1.0.0.0 (Linux 3.10.0; Unix; X64) .NET Core 3.0/v4.0.30319.42000
// SignNow .NET API Сlient/v1.0.0.0 (macOs 10.15.0; Unix; X64) .NET Core 3.1/v4.0.30319.42000

var patternClient = @"(?<client>.*)";
var patternSdk = @"(?<version>v\d+.\d+.\d+.?\d+)";
Expand All @@ -34,7 +34,7 @@ public void UserAgentStringIsCorrect()
Console.WriteLine(userAgentString);
#endif

StringAssert.Contains(SdkRuntime.ClientName, "signNow .NET API Client");
StringAssert.Contains(SdkRuntime.ClientName, "SignNow .NET API Client");
StringAssert.Matches(SdkRuntime.ClientName, new Regex(patternClient));
StringAssert.Matches($"v{SdkRuntime.Version}", new Regex(patternSdk));
StringAssert.Matches(osdetails, new Regex(patternOsDetails));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ public class SdkRuntimeTest
[TestMethod]
public void ShouldReturnProperClientName()
{
Assert.AreEqual(SdkRuntime.ClientName, "signNow .NET API Client");
Assert.AreEqual(SdkRuntime.ClientName, "SignNow .NET API Client");
}

[TestMethod]
Expand Down
73 changes: 32 additions & 41 deletions SignNow.Net.Test/UnitTests/Models/Internal/ErrorResponseTest.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
using System;
using System.Collections.Generic;
using System.Reflection;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Newtonsoft.Json;
using SignNow.Net.Internal.Model;
Expand All @@ -9,50 +11,39 @@ namespace UnitTests
public class ErrorResponseTest
{
[TestMethod]
public void ShouldProcessErrorMessage()
[DynamicData(nameof(ErrorContentProvider), DynamicDataSourceType.Method, DynamicDataDisplayName = nameof(TestDisplayName))]
public void ShouldProcessErrorMessage(string testName, string errorContext, string expectedMsg, string expectedCode)
{
var json = @"{
'error': 'context of error'
}";
var errorResponse = JsonConvert.DeserializeObject<ErrorResponse>(errorContext);

var json404 = @"{
'404': 'context of error404'
}";

var jsonError = @"{
'errors': [
{
'message': 'context of single errors item',
'code': 127
}
]
}";

var jsonErrors = @"{
'errors': [
{
'code': 41,
'message': 'context of first errors item'
},
{
'code': 42,
'message': 'context of second errors item'
}
]
}";

var errorResponse = JsonConvert.DeserializeObject<ErrorResponse>(json);
var errorResponse404 = JsonConvert.DeserializeObject<ErrorResponse>(json404);
var errorResponseError = JsonConvert.DeserializeObject<ErrorResponse>(jsonError);
var errorResponseErrors = JsonConvert.DeserializeObject<ErrorResponse>(jsonErrors);
Assert.AreEqual(expectedMsg, errorResponse.GetErrorMessage());
Assert.AreEqual(expectedCode, errorResponse.GetErrorCode());
}

Assert.AreEqual("context of error", errorResponse.GetErrorMessage());
Assert.AreEqual("context of error404", errorResponse404.GetErrorMessage());
Assert.AreEqual("context of single errors item", errorResponseError.GetErrorMessage());
Assert.AreEqual(
$"context of first errors item{Environment.NewLine}context of second errors item{Environment.NewLine}",
errorResponseErrors.GetErrorMessage()
);
public static IEnumerable<object[]> ErrorContentProvider()
{
// Test DisplayName | test object
yield return new object[] { "Invalid token", @"{""error"":""invalid_token"",""code"": 1537}", "invalid_token", "1537" };
yield return new object[] { "404", @"{""404"": ""context of error404""}", "context of error404", "" };
yield return new object[]
{
"One error as Array", @"{""errors"":[{""code"":""127"",""message"":""context of single errors item""}]}",
"context of single errors item", "127"
};
yield return new object[]
{
"Many errors as Array",
@"{""errors"":[{""code"":""127"",""message"":""first error""}, {""code"":""128"",""message"":""second error""}]}",
$"first error{Environment.NewLine}second error{Environment.NewLine}", $"127{Environment.NewLine}128{Environment.NewLine}"
};
yield return new object[]
{
"Internal Api Error", @"{""error"":[{""code"":""HY000"",""message"":""Internal Api Error""}]}",
"Internal Api Error", "HY000"
};
}

public static string TestDisplayName(MethodInfo methodInfo, object[] data) =>
TestUtils.DynamicDataDisplayName(methodInfo, data);
}
}
43 changes: 43 additions & 0 deletions SignNow.Net.Test/UnitTests/Models/ThumbnailTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Newtonsoft.Json;
using SignNow.Net.Model;
using SignNow.Net.Test.FakeModels;

namespace UnitTests
{
[TestClass]
public class ThumbnailTest
{
[TestMethod]
public void ShouldDeserializeFromJson()
{
const string Json = @"{
""small"": ""https://api.signnow.com/document/a09b26feeba7ce70228afe6290f4445700b6f349/thumbnail?size=small"",
""medium"":""https://api.signnow.com/document/a09b26feeba7ce70228afe6290f4445700b6f349/thumbnail?size=medium"",
""large"": ""https://api.signnow.com/document/a09b26feeba7ce70228afe6290f4445700b6f349/thumbnail?size=large""
}";

var actual = JsonConvert.DeserializeObject<Thumbnail>(Json);

Assert.AreEqual(
"https://api.signnow.com/document/a09b26feeba7ce70228afe6290f4445700b6f349/thumbnail?size=small",
actual.Small.AbsoluteUri);
Assert.AreEqual("?size=small", actual.Small.Query);
Assert.AreEqual("?size=medium", actual.Medium.Query);
Assert.AreEqual("?size=large", actual.Large.Query);
}

[TestMethod]
public void ShouldBeSerializable()
{
var model = new ThumbnailFaker().Generate();

var actual = JsonConvert.SerializeObject(model);

StringAssert.Contains(actual, "small");
StringAssert.Contains(actual, "medium");
StringAssert.Contains(actual, "large");
StringAssert.Contains(actual, "https://via.placeholder.com");
}
}
}
2 changes: 2 additions & 0 deletions SignNow.Net/Model/Requests/GetFolderQuery/FolderFilters.cs
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ public class DocumentUpdatedFilter
/// <summary>
/// Document signing statuses.
/// </summary>
#pragma warning disable CA1720 // Identifier 'Signed' contains type name
public enum SigningStatus
{
[EnumMember(Value = "waiting-for-me")]
Expand All @@ -116,6 +117,7 @@ public enum SigningStatus
[EnumMember(Value = "does-not-created")]
DoesNotCreated
}
#pragma warning restore CA1720 // Identifier 'Signed' contains type name

public enum HasFieldsAndRoles
{
Expand Down
6 changes: 6 additions & 0 deletions SignNow.Net/Model/SignNowDocument.cs
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,12 @@ public partial class SignNowDocument
[JsonProperty("template")]
public bool IsTemplate { get; set; }

/// <summary>
/// Thumbnails with different document preview image sizes.
/// </summary>
[JsonProperty("thumbnail")]
public Thumbnail Thumbnail { get; internal set; }

/// <summary>
/// The document signer roles.
/// </summary>
Expand Down
36 changes: 36 additions & 0 deletions SignNow.Net/Model/Thumbnail.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
using System;
using Newtonsoft.Json;
using SignNow.Net.Internal.Helpers.Converters;

namespace SignNow.Net.Model
{
/// <summary>
/// Represents thumbnails of the document.
/// </summary>
public class Thumbnail
{
/// <summary>
/// Uri for small document preview image size.
/// A4 (210 x 297 mm) ~ 85 x 110 px @ 10 ppi
/// </summary>
[JsonProperty("small")]
[JsonConverter(typeof(StringToUriJsonConverter))]
public Uri Small { get; internal set; }

/// <summary>
/// Uri for medium document preview image size
/// A4 (210 x 297 mm) ~ 340 x 440 px @ 40 ppi
/// </summary>
[JsonProperty("medium")]
[JsonConverter(typeof(StringToUriJsonConverter))]
public Uri Medium { get; internal set; }

/// <summary>
/// Uri for large document preview image size.
/// A4 (210 x 297 mm) ~ 890 x 1151 px @ 104 ppi
/// </summary>
[JsonProperty("large")]
[JsonConverter(typeof(StringToUriJsonConverter))]
public Uri Large { get; internal set; }
}
}
2 changes: 1 addition & 1 deletion SignNow.Net/_Internal/Infrastructure/SdkRuntime.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ internal static class SdkRuntime
/// <summary>
/// Returns signNow SDK client name
/// </summary>
public const string ClientName = "signNow .NET API Client";
public const string ClientName = "SignNow .NET API Client";

/// <summary>
/// Returns signNow SDK version.
Expand Down
Loading

0 comments on commit 08fd325

Please sign in to comment.