Skip to content

Commit 955b108

Browse files
authored
Merge pull request #109 from docusign/feature/add-medium-priority-tests
Added unit tests for the middle priority services
2 parents a75f051 + 52aa56c commit 955b108

File tree

73 files changed

+998
-405
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

73 files changed

+998
-405
lines changed

Quick_ACG/Startup.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ public void ConfigureServices(IServiceCollection services)
5252
config.QuickACG = "true";
5353

5454
services.AddSingleton(config);
55-
services.AddSingleton(new LauncherTexts(config));
55+
services.AddSingleton(new LauncherTexts(config, Configuration));
5656
services.AddScoped<IRequestItemsService, RequestItemsService>();
5757
services.AddMvc();
5858

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
using System.Linq;
2+
using DocuSign.Click.Examples;
3+
using DocuSign.Click.Model;
4+
using DocuSign.CodeExamples.Common;
5+
using FluentAssertions;
6+
using Xunit;
7+
8+
namespace launcher_csharp.Tests.ClickUnitTests
9+
{
10+
public sealed class ActivateClickwrapUnitTests
11+
{
12+
private const string CLICK_PATH_PREFIX = "/clickapi";
13+
14+
private readonly TestConfig _testConfig;
15+
16+
private readonly CreateClickwrapUnitTests _createClickwrapUnitTests;
17+
18+
public ActivateClickwrapUnitTests()
19+
{
20+
this._testConfig = new TestConfig();
21+
22+
var jwtLoginMethod = new JwtLoginMethodUnitTest();
23+
jwtLoginMethod.RequestJWTUserToken_CorrectInputParameters_ReturnsOAuthToken(ExamplesAPIType.Click, _testConfig);
24+
this._createClickwrapUnitTests = new CreateClickwrapUnitTests(_testConfig);
25+
}
26+
27+
[Fact]
28+
public void BuildUpdateClickwrapVersionRequest_CorrectInputParameters_ReturnsClickwrapRequest()
29+
{
30+
// Arrange
31+
var statusActive = "active";
32+
var expectedClickwrapRequest = new ClickwrapRequest
33+
{
34+
Status = statusActive,
35+
};
36+
37+
// Act
38+
ClickwrapRequest clickwrapRequest = ActivateClickwrap.BuildUpdateClickwrapVersionRequest();
39+
40+
// Assert
41+
Assert.NotNull(clickwrapRequest);
42+
clickwrapRequest.Should().BeEquivalentTo(expectedClickwrapRequest);
43+
}
44+
45+
46+
[Fact]
47+
public void Update_CorrectInputParameters_ReturnsClickwrapVersionSummaryResponse()
48+
{
49+
// Arrange
50+
_createClickwrapUnitTests.Create_CorrectInputParameters_ReturnsClickwrapVersionSummaryResponse();
51+
52+
string basePath = _testConfig.BasePath + CLICK_PATH_PREFIX;
53+
var statusActive = "active";
54+
55+
// Act
56+
ClickwrapVersionSummaryResponse clickwrapVersionSummaryResponse = ActivateClickwrap.Update(
57+
_testConfig.InactiveClickwrap.ClickwrapId,
58+
_testConfig.InactiveClickwrap.VersionNumber,
59+
basePath,
60+
_testConfig.AccessToken,
61+
_testConfig.AccountId
62+
);
63+
64+
// Assert
65+
Assert.NotNull(clickwrapVersionSummaryResponse);
66+
clickwrapVersionSummaryResponse.Status.Should().BeEquivalentTo(statusActive);
67+
}
68+
}
69+
}
Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using DocuSign.Click.Examples;
4+
using DocuSign.Click.Model;
5+
using DocuSign.CodeExamples.Common;
6+
using FluentAssertions;
7+
using Xunit;
8+
9+
namespace launcher_csharp.Tests.ClickUnitTests
10+
{
11+
public sealed class CreateClickwrapUnitTests
12+
{
13+
private const string CLICK_PATH_PREFIX = "/clickapi";
14+
15+
private const string PDF_FILE = "Terms_of_service.pdf";
16+
17+
private readonly TestConfig _testConfig;
18+
19+
public CreateClickwrapUnitTests(TestConfig testConfig = null)
20+
{
21+
this._testConfig = testConfig ?? new TestConfig();
22+
23+
var jwtLoginMethod = new JwtLoginMethodUnitTest();
24+
jwtLoginMethod.RequestJWTUserToken_CorrectInputParameters_ReturnsOAuthToken(ExamplesAPIType.Click, _testConfig);
25+
}
26+
27+
[Fact]
28+
public void BuildClickwrapRequest_CorrectInputParameters_ReturnsClickwrapRequest()
29+
{
30+
// Arrange
31+
var clickwrapName = "Clickwrap name";
32+
string pdfFile = _testConfig.PathToSolution + PDF_FILE;
33+
var consentButtonText = "I Agree";
34+
var format = "modal";
35+
var documentDisplay = "document";
36+
var termsOfService = "Terms of Service";
37+
var fileExtension = "pdf";
38+
39+
var expectedClickwrapRequest = new ClickwrapRequest
40+
{
41+
DisplaySettings = new DisplaySettings()
42+
{
43+
ConsentButtonText = consentButtonText,
44+
DisplayName = clickwrapName,
45+
Downloadable = true,
46+
Format = format,
47+
MustRead = true,
48+
RequireAccept = true,
49+
DocumentDisplay = documentDisplay,
50+
},
51+
Documents = new List<Document>()
52+
{
53+
new Document()
54+
{
55+
DocumentBase64 = Convert.ToBase64String(System.IO.File.ReadAllBytes(pdfFile)),
56+
DocumentName = termsOfService,
57+
FileExtension = fileExtension,
58+
Order = 0,
59+
},
60+
},
61+
Name = clickwrapName,
62+
RequireReacceptance = true,
63+
};
64+
65+
// Act
66+
ClickwrapRequest clickwrapRequest = CreateClickwrap.BuildClickwrapRequest(clickwrapName, pdfFile);
67+
68+
// Assert
69+
Assert.NotNull(clickwrapRequest);
70+
clickwrapRequest.Should().BeEquivalentTo(expectedClickwrapRequest);
71+
}
72+
73+
[Fact]
74+
public void Create_CorrectInputParameters_ReturnsClickwrapVersionSummaryResponse()
75+
{
76+
// Arrange
77+
var clickwrapName = Guid.NewGuid().ToString("n").Substring(0, 8);
78+
string pdfFile = _testConfig.PathToSolution + PDF_FILE;
79+
string basePath = _testConfig.BasePath + CLICK_PATH_PREFIX;
80+
81+
// Act
82+
ClickwrapVersionSummaryResponse clickwrapVersionSummaryResponse = CreateClickwrap.Create(
83+
clickwrapName,
84+
basePath,
85+
_testConfig.AccessToken,
86+
_testConfig.AccountId,
87+
pdfFile
88+
);
89+
90+
// Assert
91+
Assert.NotNull(clickwrapVersionSummaryResponse);
92+
clickwrapVersionSummaryResponse.ClickwrapName.Should().Be(clickwrapName);
93+
94+
_testConfig.InactiveClickwrap = clickwrapVersionSummaryResponse;
95+
}
96+
}
97+
}

launcher-csharp.Tests/JwtLoginMethodUnitTest.cs

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -16,25 +16,18 @@ public sealed class JwtLoginMethodUnitTest
1616

1717
private const string CONSENT_REQUIRED = "consent_required";
1818

19-
private readonly ITestConfig _testConfig;
20-
21-
public JwtLoginMethodUnitTest() : this(TestConfig.Instance) { }
22-
23-
private JwtLoginMethodUnitTest(ITestConfig testConfig)
24-
{
25-
this._testConfig = testConfig;
26-
}
27-
2819
[Theory]
2920
[InlineData(ExamplesAPIType.ESignature)]
3021
[InlineData(ExamplesAPIType.Monitor)]
3122
[InlineData(ExamplesAPIType.Click)]
3223
[InlineData(ExamplesAPIType.Rooms)]
3324
[InlineData(ExamplesAPIType.Admin)]
34-
public void RequestJWTUserToken_CorrectInputParameters_ReturnsOAuthToken(ExamplesAPIType apiType)
25+
public void RequestJWTUserToken_CorrectInputParameters_ReturnsOAuthToken(ExamplesAPIType apiType, TestConfig _testConfig = null)
3526
{
27+
_testConfig = _testConfig ?? new TestConfig();
28+
3629
// Arrange
37-
_testConfig.ApiClient = new ApiClient(_testConfig.Host);
30+
_testConfig.ApiClient = new DocuSignClient(_testConfig.Host);
3831

3932
try
4033
{
@@ -75,14 +68,14 @@ public void RequestJWTUserToken_CorrectInputParameters_ReturnsOAuthToken(Example
7568
{
7669
if (e.Message.ToLowerInvariant().Contains(CONSENT_REQUIRED))
7770
{
78-
_testConfig?.OpenUrlUsingConsoleWindow(BuildConsentUrl(apiType));
71+
_testConfig?.OpenUrlUsingConsoleWindow(BuildConsentUrl(apiType, _testConfig));
7972

8073
throw new Xunit.Sdk.XunitException(RERUN_UNIT_TESTS);
8174
}
8275
}
8376
}
8477

85-
private string BuildConsentUrl(ExamplesAPIType apiType)
78+
private string BuildConsentUrl(ExamplesAPIType apiType, TestConfig _testConfig)
8679
{
8780
var scopes = "signature%20impersonation";
8881
if (apiType == ExamplesAPIType.Rooms)

launcher-csharp.Tests/TestConfig/ITestConfig.cs

Lines changed: 0 additions & 37 deletions
This file was deleted.

launcher-csharp.Tests/TestConfig/TestConfig.cs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
using System.Diagnostics;
33
using System.IO;
44
using System.Runtime.InteropServices;
5+
using DocuSign.Click.Model;
56
using System.Text;
67
using DocuSign.CodeExamples.Common;
78
using DocuSign.eSign.Client;
@@ -10,13 +11,13 @@
1011

1112
namespace launcher_csharp.Tests
1213
{
13-
public sealed class TestConfig : ITestConfig
14+
public sealed class TestConfig
1415
{
1516
public string ClientId { get; set; }
1617

1718
public string Host { get; set; }
1819

19-
public ApiClient ApiClient { get; set; }
20+
public DocuSignClient ApiClient { get; set; }
2021

2122
public string AccountId { get; set; }
2223

@@ -38,6 +39,10 @@ public sealed class TestConfig : ITestConfig
3839

3940
public string PathToSolution { get; set; }
4041

42+
public string BrandId { get; set; }
43+
44+
public ClickwrapVersionSummaryResponse InactiveClickwrap { get; set; }
45+
4146
public byte[] PrivateKeyBytes { get; set; }
4247

4348
private static readonly Lazy<TestConfig> TestConfigLazy =

0 commit comments

Comments
 (0)