Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
congminh1254 committed Dec 28, 2023
2 parents 73fadda + 3015ce5 commit dd5010b
Show file tree
Hide file tree
Showing 49 changed files with 1,348 additions and 45 deletions.
4 changes: 2 additions & 2 deletions Box.V2.Core/Box.V2.Core.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@
<PropertyGroup>
<Description>Box.V2 for .Net Core</Description>
<AssemblyTitle>Box.V2.Core</AssemblyTitle>
<Version>5.2.0</Version>
<Version>5.6.1</Version>
<Authors>Box, Inc.</Authors>
<Owners>Box, Inc.</Owners>
<PackageProjectUrl>https://github.com/box/box-windows-sdk-v2</PackageProjectUrl>
<PackageLicenseExpression>Apache-2.0</PackageLicenseExpression>
<PackageRequireLicenseAcceptance>false</PackageRequireLicenseAcceptance>
<PackageDescription>Windows SDK for v2 of the Box API. The SDK is built for .NET Core and includes JWTAuth support.</PackageDescription>
<PackageReleaseNotes>See https://github.com/box/box-windows-sdk-v2/blob/main/CHANGELOG.md#520-2023-03-14</PackageReleaseNotes>
<PackageReleaseNotes>See https://github.com/box/box-windows-sdk-v2/blob/main/CHANGELOG.md#561-2023-11-29</PackageReleaseNotes>
<Copyright>Copyright 2021</Copyright>
<PackageTags>Box;V2;SDK;Platform;Enterprise;Collaboration;Storage;File Management</PackageTags>
<TargetFramework>netstandard2.0</TargetFramework>
Expand Down
57 changes: 57 additions & 0 deletions Box.V2.Test.Integration/BoxFilesManagerIntegrationTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,40 @@ public async Task DownloadAsync_ForUploadedFile_ShouldReturnSameFileAsTheUploade
Assert.AreEqual(base64DownloadedFile, base64UploadedFile);
}

[TestMethod]
public async Task DownloadAsync_ForFileWithSharedLink_ShouldReturnSameFileAsTheUploadedFile()
{
var folder = await CreateFolderAsAdmin();
var uploadedFile = await CreateSmallFileAsAdmin(folder.Id);

var password = "SuperSecret123";
var sharedLinkRequest = new BoxSharedLinkRequest
{
Access = BoxSharedLinkAccessType.open,
Password = password
};

var sharedLink = await AdminClient.FilesManager.CreateSharedLinkAsync(uploadedFile.Id, sharedLinkRequest);

var downloadedFile = await UserClient.FilesManager.DownloadAsync(uploadedFile.Id, sharedLink: sharedLink.SharedLink.Url, sharedLinkPassword: password);

Stream fileContents = new MemoryStream();
await downloadedFile.CopyToAsync(fileContents);
fileContents.Position = 0;

string base64DownloadedFile;
string base64UploadedFile;

base64DownloadedFile = Helper.GetSha1Hash(fileContents);

using (var fileStream = new FileStream(GetSmallFilePath(), FileMode.OpenOrCreate))
{
base64UploadedFile = Helper.GetSha1Hash(fileStream);
}

Assert.AreEqual(base64DownloadedFile, base64UploadedFile);
}

[TestMethod]
public async Task GetInformationAsync_ForCorrectFileId_ShouldReturnSameFileAsUploadedFile()
{
Expand All @@ -66,6 +100,29 @@ public async Task GetInformationAsync_ForCorrectFileId_ShouldReturnSameFileAsUpl
Assert.AreEqual(uploadedFile.Sha1, downloadedFile.Sha1);
}

[TestMethod]
public async Task GetInformationAsync_ForFileWithSharedLink_ShouldReturnSameFileAsUploadedFile()
{
var folder = await CreateFolderAsAdmin();
var uploadedFile = await CreateSmallFileAsAdmin(folder.Id);

var password = "SuperSecret123";
var sharedLinkRequest = new BoxSharedLinkRequest
{
Access = BoxSharedLinkAccessType.open,
Password = password
};

var sharedLink = await AdminClient.FilesManager.CreateSharedLinkAsync(uploadedFile.Id, sharedLinkRequest);

var sharedItems = await UserClient.SharedItemsManager.SharedItemsAsync(sharedLink.SharedLink.Url, password);

BoxFile file = await UserClient.FilesManager.GetInformationAsync(sharedItems.Id, sharedLink: sharedLink.SharedLink.Url, sharedLinkPassword: password);

Assert.AreEqual(file.Id, uploadedFile.Id);
Assert.AreEqual(file.Sha1, uploadedFile.Sha1);
}

[TestMethod]
public async Task GetDownloadUriAsync_ForCorrectFileId_ShouldReturnCorrectUrl()
{
Expand Down
20 changes: 20 additions & 0 deletions Box.V2.Test.Integration/BoxFolderManagerIntegrationTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,26 @@ public async Task GetInformationAsync_ForExistingFolder_ShouldReturnInformationR
Assert.AreEqual(folder.Id, createdFolder.Id);
}

[TestMethod]
public async Task GetInformationAsync_ForFolderWithSharedLink_ShouldReturnInformationRelatedToThisFolder()
{
var createdFolder = await CreateFolderAsAdmin();

var password = "SuperSecret123";
var sharedLinkRequest = new BoxSharedLinkRequest
{
Access = BoxSharedLinkAccessType.open,
Password = password
};
var sharedLink = await AdminClient.FoldersManager.CreateSharedLinkAsync(createdFolder.Id, sharedLinkRequest);

var sharedItems = await UserClient.SharedItemsManager.SharedItemsAsync(sharedLink.SharedLink.Url, password);

BoxFolder folder = await UserClient.FoldersManager.GetInformationAsync(sharedItems.Id, sharedLink: sharedLink.SharedLink.Url, sharedLinkPassword: password);

Assert.AreEqual(folder.Id, createdFolder.Id);
}

[TestMethod]
public async Task CreateSharedLinkAsync_ForExistingFolder_ShouldCreateSharedLinkToThatFolder()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public class BoxSharedItemsManagerIntegrationTest : TestInFolder
public async Task SharedItemsAsync_ForSharedFolder_ShouldReturnSharedFolder()
{
var folder = await CreateFolder();
var password = "secret";
var password = "Secret123";
var sharedLinkReq = new BoxSharedLinkRequest()
{
Access = BoxSharedLinkAccessType.open,
Expand Down
13 changes: 12 additions & 1 deletion Box.V2.Test.Integration/BoxSignRequestManagerIntegrationTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,18 @@ public class BoxSignRequestManagerIntegrationTest : TestInFolder
public async Task CreateSignRequestAsync_ForCorrectSignRequestCreateRequest_ShouldCreateNewSignRequest()
{
var fileToSign = await CreateSmallFile(FolderId);
var fileToSign2 = await CreateSmallFile(FolderId);
var signRequestCreateRequest = new BoxSignRequestCreateRequest()
{
SourceFiles = new List<BoxSignRequestCreateSourceFile>()
{
new BoxSignRequestCreateSourceFile()
{
Id = fileToSign.Id
},
new BoxSignRequestCreateSourceFile()
{
Id = fileToSign2.Id
}
},
Signers = new List<BoxSignRequestSignerCreate>()
Expand All @@ -30,7 +35,8 @@ public async Task CreateSignRequestAsync_ForCorrectSignRequestCreateRequest_Shou
{
Email = "[email protected]",
RedirectUrl = new Uri("https://www.box.com/redirect_url_signer_1"),
DeclinedRedirectUrl = new Uri("https://www.box.com/declined_redirect_url_singer_1")
DeclinedRedirectUrl = new Uri("https://www.box.com/declined_redirect_url_singer_1"),
EmbedUrlExternalUserId = UserId
}
},
ParentFolder = new BoxRequestEntity()
Expand All @@ -44,10 +50,15 @@ public async Task CreateSignRequestAsync_ForCorrectSignRequestCreateRequest_Shou
BoxSignRequest signRequest = await UserClient.SignRequestsManager.CreateSignRequestAsync(signRequestCreateRequest);
Assert.IsNotNull(signRequest.Id);
Assert.AreEqual(signRequestCreateRequest.SourceFiles[0].Id, signRequest.SourceFiles[0].Id);
Assert.AreEqual(signRequestCreateRequest.SourceFiles[1].Id, signRequest.SourceFiles[1].Id);
Assert.AreEqual(signRequestCreateRequest.RedirectUrl.ToString(), signRequest.RedirectUrl.ToString());
Assert.AreEqual(signRequestCreateRequest.DeclinedRedirectUrl.ToString(), signRequest.DeclinedRedirectUrl.ToString());
Assert.AreEqual(signRequestCreateRequest.ParentFolder.Id, signRequest.ParentFolder.Id);

// first signer is the sender with role final_copy_reader, second is the recipient with role signer
Assert.AreEqual(2, signRequest.Signers.Count);
Assert.IsNotNull(signRequest.Signers[1].IframeableEmbedUrl);

await UserClient.SignRequestsManager.CancelSignRequestAsync(signRequest.Id);

signRequest = await UserClient.SignRequestsManager.GetSignRequestByIdAsync(signRequest.Id);
Expand Down
18 changes: 18 additions & 0 deletions Box.V2.Test/Box.V2.Test.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -75,12 +75,30 @@
<None Update="Fixtures\BoxSignRequest\GetSignRequest200.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="Fixtures\BoxSignTemplate\GetAllSignTemplates200.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="Fixtures\BoxSignTemplate\GetSignTemplate200.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="Fixtures\BoxUsers\AddOrUpdateUserAvatar200.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="Fixtures\BoxWebLinks\CreateWebLinkSharedLink200.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="Fixtures\Converters\SingleOrCollectionConverter\Empty.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="Fixtures\Converters\SingleOrCollectionConverter\EmptyArray.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="Fixtures\Converters\SingleOrCollectionConverter\Array.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="Fixtures\Converters\SingleOrCollectionConverter\SingleObject.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="TestData\smalltest.pdf">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
Expand Down
2 changes: 2 additions & 0 deletions Box.V2.Test/BoxResourceManagerTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ protected BoxResourceManagerTest()
Config.SetupGet(x => x.FolderLocksEndpointUri).Returns(FolderLocksUri);
Config.SetupGet(x => x.SignRequestsEndpointUri).Returns(SignRequestUri);
Config.SetupGet(x => x.SignRequestsEndpointWithPathUri).Returns(SignRequestWithPathUri);
Config.SetupGet(x => x.SignTemplatesEndpointUri).Returns(new Uri(Constants.SignTemplatesEndpointString));
Config.SetupGet(x => x.SignTemplatesEndpointWithPathUri).Returns(new Uri(Constants.SignTemplatesWithPathEndpointString));
Config.SetupGet(x => x.FileRequestsEndpointWithPathUri).Returns(FileRequestsWithPathUri);
Config.SetupGet(x => x.RetryStrategy).Returns(new InstantRetryStrategy());

Expand Down
7 changes: 6 additions & 1 deletion Box.V2.Test/BoxSignRequestsManagerTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,8 @@ public async Task CreateSignRequest_OptionalParams_Success()
"1234",
"text"
)
}
},
TemplateId = "12345"
};

/*** Act ***/
Expand All @@ -163,6 +164,7 @@ public async Task CreateSignRequest_OptionalParams_Success()
Assert.AreEqual("[email protected]", response.Signers[0].Email);
Assert.AreEqual("https://box.com/redirect_url_signer_1", response.Signers[0].RedirectUrl.ToString());
Assert.AreEqual("https://box.com/declined_redirect_url_signer_1", response.Signers[0].DeclinedRedirectUrl.ToString());
Assert.AreEqual("https://app.box.com/embed/sign/document/bf7aaac6/", response.Signers[0].IframeableEmbedUrl);
Assert.AreEqual(1, response.Signers[0].Inputs.Count);
Assert.IsTrue(response.Signers[0].Inputs[0].CheckboxValue.Value);
Assert.AreEqual(BoxSignRequestSingerInputContentType.checkbox, response.Signers[0].Inputs[0].ContentType);
Expand All @@ -180,6 +182,7 @@ public async Task CreateSignRequest_OptionalParams_Success()
Assert.AreEqual(DateTimeOffset.Parse("2021-04-26T08:12:13.982Z"), response.PrefillTags[0].DateValue);
Assert.AreEqual("https://box.com/redirect_url", response.RedirectUrl.ToString());
Assert.AreEqual("https://box.com/declined_redirect_url", response.DeclinedRedirectUrl.ToString());
Assert.AreEqual("12345", response.TemplateId);
}

[TestMethod]
Expand Down Expand Up @@ -211,6 +214,7 @@ public async Task GetSignRequest_Success()
Assert.AreEqual("[email protected]", response.Entries[0].Signers[0].Email);
Assert.AreEqual("https://box.com/redirect_url_signer_1", response.Entries[0].Signers[0].RedirectUrl.ToString());
Assert.AreEqual("https://box.com/declined_redirect_url_signer_1", response.Entries[0].Signers[0].DeclinedRedirectUrl.ToString());
Assert.AreEqual("https://app.box.com/embed/sign/document/bf7aaac6/", response.Entries[0].Signers[0].IframeableEmbedUrl);
Assert.AreEqual("12345", response.Entries[0].ParentFolder.Id);
Assert.IsTrue(response.Entries[0].IsDocumentPreparationNeeded);
Assert.IsTrue(response.Entries[0].AreRemindersEnabled);
Expand Down Expand Up @@ -257,6 +261,7 @@ public async Task GetSignRequestById_Success()
Assert.AreEqual("[email protected]", response.Signers[0].Email);
Assert.AreEqual("https://box.com/redirect_url_signer_1", response.Signers[0].RedirectUrl.ToString());
Assert.AreEqual("https://box.com/declined_redirect_url_signer_1", response.Signers[0].DeclinedRedirectUrl.ToString());
Assert.AreEqual("https://app.box.com/embed/sign/document/bf7aaac6/", response.Signers[0].IframeableEmbedUrl);
Assert.AreEqual(1, response.Signers[0].Inputs.Count);
Assert.IsTrue(response.Signers[0].Inputs[0].CheckboxValue.Value);
Assert.AreEqual(BoxSignRequestSingerInputContentType.checkbox, response.Signers[0].Inputs[0].ContentType);
Expand Down
85 changes: 85 additions & 0 deletions Box.V2.Test/BoxSignTemplateManagerTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using Box.V2.Managers;
using Box.V2.Models;
using Box.V2.Models.Request;
using Box.V2.Test.Extensions;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Moq;
using Newtonsoft.Json.Linq;

namespace Box.V2.Test
{
[TestClass]
public class BoxSignTemplatesManagerTest : BoxResourceManagerTest
{
private readonly BoxSignTemplatesManager _signTemplatesManager;

public BoxSignTemplatesManagerTest()
{
_signTemplatesManager = new BoxSignTemplatesManager(Config.Object, Service, Converter, AuthRepository);
}

[TestMethod]
public async Task GetSignTemplateById_Success()
{
/** Arrange **/
const string signTemplateId = "93153068-5420-467b-b8ef-8e54bfb7be42";
IBoxRequest boxRequest = null;
Handler.Setup(h => h.ExecuteAsync<BoxSignTemplate>(It.IsAny<IBoxRequest>()))
.Returns(Task.FromResult<IBoxResponse<BoxSignTemplate>>(new BoxResponse<BoxSignTemplate>()
{
Status = ResponseStatus.Success,
ContentString = LoadFixtureFromJson("Fixtures/BoxSignTemplate/GetSignTemplate200.json")
}))
.Callback<IBoxRequest>(r => boxRequest = r);

/*** Act ***/
BoxSignTemplate response = await _signTemplatesManager.GetSignTemplateByIdAsync(signTemplateId);

/*** Assert ***/
// Request check
Assert.IsNotNull(boxRequest);
Assert.AreEqual(RequestMethod.Get, boxRequest.Method);
Assert.AreEqual(new Uri("https://api.box.com/2.0/sign_templates/93153068-5420-467b-b8ef-8e54bfb7be42"), boxRequest.AbsoluteUri);

// Response check
Assert.AreEqual(signTemplateId, response.Id);
Assert.AreEqual("requirements-dev.pdf", response.Name);
Assert.AreEqual("Please sign this document.\n\nKind regards", response.EmailMessage);
Assert.AreEqual("Someone ([email protected]) has requested your signature on a document", response.EmailSubject);
Assert.AreEqual("1234567890", response.ParentFolder.Id);
Assert.AreEqual(1, response.SourceFiles.Count);
Assert.AreEqual("1234567890", response.SourceFiles[0].Id);
Assert.AreEqual("https://app.box.com/sign/ready-sign-link/59917816-c12b-4ef6-8f1d-aaaaaaa", response.ReadySignLink.Url);
}

[TestMethod]
public async Task GetSignTemplates_Success()
{
/** Arrange **/
IBoxRequest boxRequest = null;
Handler.Setup(h => h.ExecuteAsync<BoxCollectionMarkerBased<BoxSignTemplate>>(It.IsAny<IBoxRequest>()))
.Returns(Task.FromResult<IBoxResponse<BoxCollectionMarkerBased<BoxSignTemplate>>>(new BoxResponse<BoxCollectionMarkerBased<BoxSignTemplate>>()
{
Status = ResponseStatus.Success,
ContentString = LoadFixtureFromJson("Fixtures/BoxSignTemplate/GetAllSignTemplates200.json")
}))
.Callback<IBoxRequest>(r => boxRequest = r);

/*** Act ***/
BoxCollectionMarkerBased<BoxSignTemplate> response = await _signTemplatesManager.GetSignTemplatesAsync(1000, "JV9IRGZmieiBasejOG9yDCRNgd2ymoZIbjsxbJMjIs3kioVii");

/*** Assert ***/
// Request check
Assert.IsNotNull(boxRequest);
Assert.AreEqual(RequestMethod.Get, boxRequest.Method);
Assert.AreEqual(new Uri("https://api.box.com/2.0/sign_templates?limit=1000&marker=JV9IRGZmieiBasejOG9yDCRNgd2ymoZIbjsxbJMjIs3kioVii"), boxRequest.AbsoluteUri);

// Response check
Assert.AreEqual(1, response.Entries.Count);
Assert.AreEqual("93153068-5420-467b-b8ef-8e54bfb7be42", response.Entries[0].Id);
}
}
}
50 changes: 50 additions & 0 deletions Box.V2.Test/Converters/SingleOrCollectionConverterTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
using Box.V2.Converter;
using Box.V2.Models;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace Box.V2.Test
{
[TestClass]
public class SingleOrCollectionConverterTest : BoxResourceManagerTest
{
private readonly IBoxConverter _converter;

public SingleOrCollectionConverterTest()
{
_converter = new BoxJsonConverter();
}

[TestMethod]
public void SingleObject()
{
var json = LoadFixtureFromJson("Fixtures/Converters/SingleOrCollectionConverter/SingleObject.json");
var error = _converter.Parse<BoxConflictErrorContextInfo<BoxFolder>>(json);
Assert.AreEqual(error.Conflicts[0].Name, "Test Folder");
}

[TestMethod]
public void Array()
{
var json = LoadFixtureFromJson("Fixtures/Converters/SingleOrCollectionConverter/Array.json");
var error = _converter.Parse<BoxConflictErrorContextInfo<BoxFolder>>(json);
Assert.AreEqual(error.Conflicts[0].Name, "Test Folder");
Assert.AreEqual(error.Conflicts[1].Name, "Test Folder 2");
}

[TestMethod]
public void EmptyArray()
{
var json = LoadFixtureFromJson("Fixtures/Converters/SingleOrCollectionConverter/EmptyArray.json");
var error = _converter.Parse<BoxConflictErrorContextInfo<BoxFolder>>(json);
Assert.AreEqual(error.Conflicts.Count, 0);
}

[TestMethod]
public void Empty()
{
var json = LoadFixtureFromJson("Fixtures/Converters/SingleOrCollectionConverter/Empty.json");
var error = _converter.Parse<BoxConflictErrorContextInfo<BoxFolder>>(json);
Assert.IsNull(error.Conflicts);
}
}
}
Loading

0 comments on commit dd5010b

Please sign in to comment.