Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions .github/workflows/build_and_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -146,11 +146,23 @@ jobs:
# --force-language csharp \
# -r ./SignNow.Net.Test/bin/Debug/${{ matrix.framework }}/coverage.opencover.xml

- name: Setup Codecov tags
shell: pwsh
run: |
If ("${{ matrix.framework }}" -eq "netcoreapp3.0") {
echo "::set-env name=TARGET_FRAMEWORK::netstandard1.2"
} ElseIf ("${{ matrix.framework }}" -eq "netcoreapp3.1") {
echo "::set-env name=TARGET_FRAMEWORK::netstandard2.0"
} Else {
echo "::set-env name=TARGET_FRAMEWORK::net45"
}

- name: Upload Code Coverage Report (Codecov.io)
continue-on-error: true
uses: codecov/codecov-action@v1
with:
name: ${{ runner.os }}-codecov-${{ matrix.framework }}
flags: ${{ runner.os }},${{ env.TARGET_FRAMEWORK }}
token: ${{ secrets.CODECOV_TOKEN }}
file: ./SignNow.Net.Test/bin/Debug/${{ matrix.framework }}/coverage.opencover.xml
yml: ./codecov.yml
Expand Down
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ and this project adheres to [Semantic Versioning](http://semver.org).
### Changed
- Upgraded netcore version from 2.x to 3.x for `SignNow.Net.Test`
- Added project `SignNow.Net.Examples` with code samples
- Added validation for all document identity

### Fixed
- Fixed `Field.Type` converting error [#96](https://github.com/signnow/SignNow.NET/issues/96)


## [0.5.0-beta] - 2020-03-06
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
using Microsoft.VisualStudio.TestTools.UnitTesting;
using SignNow.Net.Test.Constants;
using System;
using System.Globalization;
using System.IO;
using SignNow.Net.Exceptions;

namespace AcceptanceTests
{
Expand All @@ -28,7 +29,10 @@ public void SigningLinkExceptionIsCorrect()
.ThrowsException<AggregateException>(
() => SignNowTestContext.Documents.CreateSigningLinkAsync("Some Wrong Document Id").Result);

Assert.AreEqual(ErrorMessages.TheDocumentIdShouldHave40Characters, exception.InnerException?.Message);
var expected = string
.Format(CultureInfo.CurrentCulture, ExceptionMessages.InvalidFormatOfId, "Some Wrong Document Id");

Assert.AreEqual(expected, exception.InnerException?.Message);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
using System.Globalization;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System.Threading.Tasks;
using SignNow.Net.Exceptions;
using SignNow.Net.Internal.Extensions;
using SignNow.Net.Test.Constants;

namespace AcceptanceTests
{
Expand Down Expand Up @@ -36,7 +36,7 @@ public void CannotDeleteDocumentWithWrongId()
() => Task.WaitAll(deleteResponse));

Assert.AreEqual(
string.Format(CultureInfo.CurrentCulture, ErrorMessages.InvalidFormatOfId, documentId),
string.Format(CultureInfo.CurrentCulture, ExceptionMessages.InvalidFormatOfId, documentId),
exception.InnerException?.Message);
}
}
Expand Down
17 changes: 0 additions & 17 deletions SignNow.Net.Test/Constants/ErrorMessages.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
using System;

namespace SignNow.Net.Test.Constants
{
/// <summary>
Expand All @@ -8,21 +6,6 @@ namespace SignNow.Net.Test.Constants
public static class ErrorMessages
{
public static readonly string InvalidFileType = "Invalid file type.";
public static readonly string CannotCreateSigningLinksOnDocumentsWithNoFields = "Cannot create signing links on documents with no fields";
public static readonly string TheDocumentIdShouldHave40Characters = "The document id should have exactly 40 characters.";
public static readonly string BadRequest = "Bad Request";

/// <summary>
/// Invalid format of ID {param}...
/// </summary>
public static readonly string InvalidFormatOfId =
"Invalid format of ID <{0}>. The required format: 40 characters long, case-sensitive, letters and numbers, underscore allowed.";

/// <summary>
/// Invalid format of email {param}...
/// </summary>
public static readonly string InvalidFormatOfEmail =
"Invalid format of email <{0}>. The required format: valid email address (e.g john+1@gmail.com or john123@gmail.com).";

/// <summary>
/// Starts string message for Exceptions with nullable param: `Value cannot be null.`
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
using System;
using System.Globalization;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using SignNow.Net.Exceptions;
using SignNow.Net.Internal.Extensions;
using SignNow.Net.Test.Constants;

namespace UnitTests
{
Expand All @@ -22,7 +22,7 @@ public void ShouldValidateDocumentId(string id)
id.ValidateId);

Assert.AreEqual(
string.Format(CultureInfo.CurrentCulture, ErrorMessages.InvalidFormatOfId, id),
string.Format(CultureInfo.CurrentCulture, ExceptionMessages.InvalidFormatOfId, id),
exception.Message);
}

Expand All @@ -43,7 +43,7 @@ public void ShouldFailNonValidEmails(string email)
email.ValidateEmail);

Assert.AreEqual(
string.Format(CultureInfo.CurrentCulture, ErrorMessages.InvalidFormatOfEmail, email),
string.Format(CultureInfo.CurrentCulture, ExceptionMessages.InvalidFormatOfEmail, email),
exception.Message);
}

Expand Down
16 changes: 8 additions & 8 deletions SignNow.Net.Test/UnitTests/Models/SignNowDocumentTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,11 @@ public void ShouldDeserializeFromJson()
[DataTestMethod]
[DataRow(FieldType.Text, DisplayName = "Get values for Text Fields")]
[DataRow(FieldType.Signature, DisplayName = "Get values for SignatureContent Fields")]
[DataRow(FieldType.Initial, DisplayName = "Get values for Initial Fields")]
[DataRow(FieldType.Initials, DisplayName = "Get values for Initials Fields")]
[DataRow(FieldType.Hyperlink, DisplayName = "Get values for Hyperlink Fields")]
[DataRow(FieldType.Checkbox, DisplayName = "Get values for Checkbox Fields")]
[DataRow(FieldType.Attachment, DisplayName = "Get values for Attachment Fields")]
[DataRow(FieldType.Dropdown, DisplayName = "Get values for Dropdown Fields")]
[DataRow(FieldType.Enumeration, DisplayName = "Get values for Enumeration Fields")]
[DataRow(FieldType.RadioButton, DisplayName = "Get values for Radiobutton Fields")]
public void ShouldGetFieldValuesForDocument(object testType)
{
Expand Down Expand Up @@ -93,12 +93,12 @@ public void ShouldGetFieldValuesForDocument(object testType)
{
field.Current.RoleId = role.Current.Id;
field.Current.Owner = obj.Owner;
field.Current.JsonAttributes.Name = ((FieldType)testType).ToString() + "Name";
field.Current.JsonAttributes.Label = ((FieldType)testType).ToString() + "LabelName";
field.Current.JsonAttributes.Name = (FieldType)testType + "Name";
field.Current.JsonAttributes.Label = (FieldType)testType + "LabelName";

text.Current.Id = field.Current.ElementId;
text.Current.Email = field.Current.Signer;
text.Current.Data = (FieldType)testType == FieldType.Dropdown
text.Current.Data = (FieldType)testType == FieldType.Enumeration
? "this is test dropdown element value"
: "this is test text field value";

Expand All @@ -115,7 +115,7 @@ public void ShouldGetFieldValuesForDocument(object testType)
checkbox.Current.Id = field.Current.ElementId;
if (field.Current.Type == FieldType.Checkbox)
{
field.Current.JsonAttributes.PrefilledText = f.PickRandom(new[] { "1", "" });
field.Current.JsonAttributes.PrefilledText = f.PickRandom("1", "");
}

attach.Current.Id = field.Current.ElementId;
Expand All @@ -142,7 +142,7 @@ public void ShouldGetFieldValuesForDocument(object testType)
break;

case FieldType.Signature:
case FieldType.Initial:
case FieldType.Initials:
var signValue = fieldValue as SignatureContent;
Assert.AreEqual(field.ElementId, signValue.Id, "Wrong signature ID");
Assert.AreEqual("this is test signature field value", Encoding.UTF8.GetString((byte[])signValue.GetValue()));
Expand Down Expand Up @@ -171,7 +171,7 @@ public void ShouldGetFieldValuesForDocument(object testType)
Assert.AreEqual("TestFileName.pdf", attachmentValue.OriginalName);
break;

case FieldType.Dropdown:
case FieldType.Enumeration:
var dropdownValue = fieldValue as TextContent;
Assert.AreEqual(field.ElementId, dropdownValue?.Id, "Wrong dropdown ID");
Assert.AreEqual("this is test dropdown element value", dropdownValue.GetValue());
Expand Down
6 changes: 3 additions & 3 deletions SignNow.Net.Test/UnitTests/OAuth2ServiceTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,8 @@ public void CannotValidateEmptyToken()
[TestMethod]
public void EnsuresTokeLifetimeForCodeGrant()
{
// Add 30 days for token lifetime test
var futureTimestamp = UnixTimeStampConverter.ToUnixTimestamp(DateTime.Now.AddDays(30));
// Add 3 days for token lifetime test
var futureTimestamp = UnixTimeStampConverter.ToUnixTimestamp(DateTime.Now.AddDays(3));
var fakeToken = new TokenFaker()
.RuleFor(t => t.ExpiresIn, (int)futureTimestamp)
.Generate();
Expand All @@ -119,7 +119,7 @@ public void EnsuresTokeLifetimeForCodeGrant()

Assert.AreNotEqual(tokenJsonResponse, SerializeToJsonFormatted(token));
Assert.AreNotEqual(fakeToken.ExpiresIn, token.ExpiresIn);
Assert.IsTrue(2599200 - token.ExpiresIn >= 0, "token lifetime adjustment error");
Assert.IsTrue(2592000 - token.ExpiresIn >= 0, $"token lifetime adjustment error: {token.ExpiresIn}");
Assert.IsTrue(fakeToken.ExpiresIn > token.ExpiresIn, "ExpiresIn is Timestamp, expected lifetime");
}
}
Expand Down
18 changes: 18 additions & 0 deletions SignNow.Net/Exceptions/ExceptionMessages.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions SignNow.Net/Exceptions/ExceptionMessages.resx
Original file line number Diff line number Diff line change
Expand Up @@ -129,4 +129,12 @@
<value>Document must contains at least one fillable field assigned to one role.</value>
<comment>Looks up a localized string similar to Document must have fillable fields.</comment>
</data>
<data name="InvalidFormatOfId" xml:space="preserve">
<value>Invalid format of ID `{0}`. The required format: 40 characters long, case-sensitive, letters and numbers, underscore allowed.</value>
<comment>Looks up a localized string similar to Invalid format of ID.</comment>
</data>
<data name="InvalidFormatOfEmail" xml:space="preserve">
<value>Invalid format of email `{0}`. The required format: valid email address (e.g john+1@gmail.com or john123@gmail.com).</value>
<comment>Looks up a localized string similar to Invalid format of email.</comment>
</data>
</root>
4 changes: 4 additions & 0 deletions SignNow.Net/Interfaces/IDocumentService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ public interface IDocumentService
/// <param name="documentId">Identity of the document to be viewed.</param>
/// <param name="cancellationToken">Propagates notification that operations should be canceled.</param>
/// <returns></returns>
/// <exception cref="System.ArgumentException">If document identity is not valid.</exception>
Task<SignNowDocument> GetDocumentAsync(string documentId, CancellationToken cancellationToken = default);

/// <summary>
Expand Down Expand Up @@ -44,6 +45,7 @@ public interface IDocumentService
/// <param name="documentId">Identity of the document to be removed.</param>
/// <param name="cancellationToken">Propagates notification that operations should be canceled.</param>
/// <returns></returns>
/// <exception cref="System.ArgumentException">If document identity is not valid.</exception>
Task DeleteDocumentAsync(string documentId, CancellationToken cancellationToken = default);

/// <summary>
Expand All @@ -52,6 +54,7 @@ public interface IDocumentService
/// <param name="documentId">Identity of the document to create signing link for</param>
/// <param name="cancellationToken">Propagates notification that operations should be canceled</param>
/// <returns>Operation result object containing URL to sign the document using web browser.</returns>
/// <exception cref="System.ArgumentException">If document identity is not valid.</exception>
Task<SigningLinkResponse> CreateSigningLinkAsync(string documentId, CancellationToken cancellationToken = default);

/// <summary>
Expand All @@ -61,6 +64,7 @@ public interface IDocumentService
/// <param name="type">Download document <see cref="DownloadType">type</see></param>
/// <param name="cancellationToken">Propagates notification that operations should be canceled</param>
/// <returns>Operation result object containing File info with Stream file content.</returns>
/// <exception cref="System.ArgumentException">If document identity is not valid.</exception>
Task<DownloadDocumentResponse> DownloadDocumentAsync(string documentId, DownloadType type = DownloadType.PdfCollapsed, CancellationToken cancellationToken = default);
}
}
8 changes: 4 additions & 4 deletions SignNow.Net/Model/Field.cs
Original file line number Diff line number Diff line change
Expand Up @@ -80,24 +80,24 @@ public enum FieldType
Text,

/// <summary>
/// SignatureContent fields.
/// Signature fields.
/// </summary>
Signature,

/// <summary>
/// Initials fields.
/// </summary>
Initial,
Initials,

/// <summary>
/// Check box.
/// </summary>
Checkbox,

/// <summary>
/// Dropdown list.
/// Enumeration list.
/// </summary>
Dropdown,
Enumeration,

/// <summary>
/// Radio button group with Radio elements included.
Expand Down
4 changes: 2 additions & 2 deletions SignNow.Net/Model/SignNowDocument.Fields.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,11 @@ public ISignNowContent GetFieldContent(ISignNowField fieldMeta)
switch (fieldMeta?.Type)
{
case FieldType.Text:
case FieldType.Dropdown:
case FieldType.Enumeration:
return Texts.FirstOrDefault(txt => txt.Id == fieldMeta.ElementId);

case FieldType.Signature:
case FieldType.Initial:
case FieldType.Initials:
return Signatures.FirstOrDefault(sig => sig.Id == fieldMeta.ElementId);

case FieldType.Hyperlink:
Expand Down
23 changes: 16 additions & 7 deletions SignNow.Net/Service/DocumentService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,22 @@ namespace SignNow.Net.Service
{
public class DocumentService : AuthorizedWebClientBase, IDocumentService
{
/// <inheritdoc cref="DocumentService(Uri, Token, ISignNowClient)"/>
public DocumentService(Token token) : this(ApiUrl.ApiBaseUrl, token)
{
}

/// <inheritdoc cref="DocumentService(Uri, Token, ISignNowClient)"/>
public DocumentService(Uri baseApiUrl, Token token) : base(baseApiUrl, token)
{
}

/// <summary>
/// Creates new instance of <see cref="DocumentService"/>
/// </summary>
/// <param name="baseApiUrl"><see cref="ApiUrl.ApiBaseUrl"/></param>
/// <param name="token"><see cref="Token"/></param>
/// <param name="signNowClient"><see cref="ISignNowClient"/></param>
protected internal DocumentService(Uri baseApiUrl, Token token, ISignNowClient signNowClient) : base(baseApiUrl, token, signNowClient)
{
}
Expand All @@ -46,7 +54,7 @@ public async Task<SigningLinkResponse> CreateSigningLinkAsync(string documentId,
var requestOptions = new PostHttpRequestOptions
{
RequestUrl = requestFullUrl,
Content = new JsonHttpContent(new { document_id = documentId }),
Content = new JsonHttpContent(new { document_id = documentId.ValidateId() }),
Token = Token
};

Expand Down Expand Up @@ -124,12 +132,13 @@ public async Task<DownloadDocumentResponse> DownloadDocumentAsync(string documen
Token = Token
};

return await SignNowClient.RequestAsync(
requestOptions,
new HttpContentToDownloadDocumentResponseAdapter(),
HttpCompletionOption.ResponseHeadersRead,
cancellationToken
).ConfigureAwait(false);
return await SignNowClient
.RequestAsync(
requestOptions,
new HttpContentToDownloadDocumentResponseAdapter(),
HttpCompletionOption.ResponseHeadersRead,
cancellationToken)
.ConfigureAwait(false);
}
}
}
Loading