Skip to content

Commit

Permalink
Merge branch 'sdk-1695-long-upload-fail' of https://github.com/box/bo…
Browse files Browse the repository at this point in the history
…x-windows-sdk-v2 into sdk-1695-long-upload-fail
  • Loading branch information
mwwoda committed Aug 6, 2021
2 parents 6e86164 + a7443e0 commit 8eb43eb
Show file tree
Hide file tree
Showing 27 changed files with 580 additions and 108 deletions.
4 changes: 2 additions & 2 deletions Box.V2.Samples.Core.AppUser.Create/Program.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using Box.V2.Config;
using Box.V2.Config;
using Box.V2.JWTAuth;
using Box.V2.Models;
using System;
Expand Down Expand Up @@ -86,7 +86,7 @@ private static IBoxConfig ConfigureBoxApi()
IBoxConfig config = null;
using (FileStream fs = new FileStream(@"YOUR_JSON_FILE_HERE", FileMode.Open))
{
config = BoxConfig.CreateFromJsonFile(fs);
config = BoxConfigBuilder.CreateFromJsonFile(fs).Build();
}

return config;
Expand Down
5 changes: 3 additions & 2 deletions Box.V2.Samples.Core.File.Upload/Program.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;
using System.IO;
using System.Threading.Tasks;
using Box.V2.Config;
Expand Down Expand Up @@ -41,7 +41,8 @@ private async Task ExecuteMainAsync()

var auth = new OAuthSession(accessToken, "YOUR_REFRESH_TOKEN", 3600, "bearer");

var config = new BoxConfig("YOUR_CLIENT_ID", "YOUR_CLIENT_SECRET", new Uri("http://boxsdk"));
var config = new BoxConfigBuilder("YOUR_CLIENT_ID", "YOUR_CLIENT_SECRET", new Uri("http://boxsdk"))
.Build();
var client = new BoxClient(config, auth);

var file = File.OpenRead(localFilePath);
Expand Down
8 changes: 4 additions & 4 deletions Box.V2.Samples.Core.HttpProxy/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ class Program
{
static void Main(string[] args)
{
var boxConfig = BoxConfig.CreateFromJsonString(GetConfigJson());

// Set web proxy
boxConfig.WebProxy = new BoxHttpProxy();
var boxConfig = BoxConfigBuilder.CreateFromJsonString(GetConfigJson())
// Set web proxy
.SetWebProxy(new BoxHttpProxy())
.Build();

var boxJWT = new BoxJWTAuth(boxConfig);

Expand Down
3 changes: 2 additions & 1 deletion Box.V2.Samples.JWTAuth/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ static async Task MainAsync()
// rename the private_key.pem.example to private_key.pem and put your JWT private key in the file
var privateKey = File.ReadAllText("private_key.pem.example");

var boxConfig = new BoxConfig(CLIENT_ID, CLIENT_SECRET, ENTERPRISE_ID, privateKey, JWT_PRIVATE_KEY_PASSWORD, JWT_PUBLIC_KEY_ID);
var boxConfig = new BoxConfigBuilder(CLIENT_ID, CLIENT_SECRET, ENTERPRISE_ID, privateKey, JWT_PRIVATE_KEY_PASSWORD, JWT_PUBLIC_KEY_ID)
.Build();
var boxJWT = new BoxJWTAuth(boxConfig);

var adminToken = boxJWT.AdminToken();
Expand Down
5 changes: 3 additions & 2 deletions Box.V2.Samples.TransactionalAuth/Program.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;
using System.Threading.Tasks;
using Box.V2.Auth;
using Box.V2.Auth.Token;
Expand Down Expand Up @@ -39,7 +39,8 @@ private static BoxClient CreateClientByToken(string token)
{
var auth = new OAuthSession(token, "YOUR_REFRESH_TOKEN", 3600, "bearer");

var config = new BoxConfig(string.Empty, string.Empty, new Uri("http://boxsdk"));
var config = new BoxConfigBuilder(string.Empty, string.Empty, new Uri("http://boxsdk"))
.Build();
var client = new BoxClient(config, auth);

return client;
Expand Down
3 changes: 2 additions & 1 deletion Box.V2.Test.Integration/BoxAuthTestIntegration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ public class BoxAuthTestIntegration : BoxResourceManagerTestIntegration
[TestMethod]
public void retriesWithNewJWTAssertionOnErrorResponseAndSucceeds()
{
var config = new BoxConfig(ClientId, ClientSecret, EnterpriseId, privateKey, passphrase, publicKeyID);
var config = new BoxConfigBuilder(ClientId, ClientSecret, EnterpriseId, privateKey, passphrase, publicKeyID)
.Build();
var session = new BoxJWTAuth(config);
var adminToken = session.AdminToken();
adminClient = session.AdminClient(adminToken);
Expand Down
13 changes: 9 additions & 4 deletions Box.V2.Test.Integration/BoxConfigTestIntegration.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using Box.V2.Config;
using Box.V2.Config;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System.Threading.Tasks;

Expand All @@ -24,11 +24,15 @@ public async Task BoxConfig_SetUriString()
'webhooks': {},
'enterpriseID': 'eid-123'
}";
var config = BoxConfig.CreateFromJsonString(jsonString);
var config = BoxConfigBuilder
.CreateFromJsonString(jsonString)
.Build();
Assert.AreEqual(config.BoxApiUri, new System.Uri(Constants.BoxApiUriString));

System.Uri exampleUri = new System.Uri("https://example.com/");
config.BoxApiUri = exampleUri;
config = BoxConfigBuilder.CreateFromJsonString(jsonString)
.SetBoxApiUri(exampleUri)
.Build();
Assert.AreEqual(config.BoxApiUri, exampleUri);
}

Expand All @@ -49,7 +53,8 @@ public async Task BoxConfig_CreateFromString()
'webhooks': {},
'enterpriseID': 'eid-123'
}";
var config = BoxConfig.CreateFromJsonString(jsonString);
var config = BoxConfigBuilder.CreateFromJsonString(jsonString)
.Build();

Assert.AreEqual(config.ClientId, "cid-123");
Assert.AreEqual(config.ClientSecret, "cre-123");
Expand Down
8 changes: 6 additions & 2 deletions Box.V2.Test.Integration/BoxFoldersManagerTestIntegration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,19 @@ public async Task GetFolder_LiveSession_ValidResponse()
[TestMethod]
public async Task GetFolder_LiveSession_ValidResponse_GzipCompression()
{
var boxConfig = new BoxConfig(ClientId, ClientSecret, RedirectUri){AcceptEncoding = CompressionType.gzip};
var boxConfig = new BoxConfigBuilder(ClientId, ClientSecret, RedirectUri)
.SetAcceptEncoding(CompressionType.gzip)
.Build();
var boxClient = new BoxClient(boxConfig, _auth);
await AssertFolderContents(boxClient);
}

[TestMethod]
public async Task GetFolder_LiveSession_ValidResponse_DeflateCompression()
{
var boxConfig = new BoxConfig(ClientId, ClientSecret, RedirectUri) { AcceptEncoding = CompressionType.deflate };
var boxConfig = new BoxConfigBuilder(ClientId, ClientSecret, RedirectUri)
.SetAcceptEncoding(CompressionType.deflate)
.Build();
var boxClient = new BoxClient(boxConfig, _auth);
await AssertFolderContents(boxClient);
}
Expand Down
11 changes: 7 additions & 4 deletions Box.V2.Test.Integration/BoxResourceManagerTestIntegration.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;
using System.Threading.Tasks;
using System.Diagnostics;
using Box.V2.Auth;
Expand Down Expand Up @@ -44,7 +44,8 @@ public static void Initialize(TestContext testContext)
{
Debug.WriteLine("json config content length : " + jsonConfig.Length);

var config = BoxConfig.CreateFromJsonString(jsonConfig);
var config = BoxConfigBuilder.CreateFromJsonString(jsonConfig)
.Build();
var session = new BoxJWTAuth(config);

// create a new app user
Expand Down Expand Up @@ -99,12 +100,14 @@ public BoxResourceManagerTestIntegration()
// Legacy way of getting the token
_auth = new OAuthSession("YOUR_ACCESS_TOKEN", "YOUR_REFRESH_TOKEN", 3600, "bearer");

_config = new BoxConfig(ClientId, ClientSecret, RedirectUri);
_config = new BoxConfigBuilder(ClientId, ClientSecret, RedirectUri)
.Build();
_client = new BoxClient(_config, _auth);
}
else
{
_config = BoxConfig.CreateFromJsonString(jsonConfig);
_config = BoxConfigBuilder.CreateFromJsonString(jsonConfig)
.Build();

_client = userClient;
_auth = new OAuthSession(userToken, "", 3600, "bearer");
Expand Down
5 changes: 3 additions & 2 deletions Box.V2.Test.Integration/BoxTokenExchangeTestIntegration.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using Box.V2.Auth;
using Box.V2.Auth;
using Box.V2.Auth.Token;
using Box.V2.Config;
using Box.V2.Exceptions;
Expand All @@ -16,7 +16,8 @@ private static BoxClient CreateClientByToken(string token)
{
var auth = new OAuthSession(token, "YOUR_REFRESH_TOKEN", 3600, "bearer");

var config = new BoxConfig(string.Empty, string.Empty, new Uri("http://boxsdk"));
var config = new BoxConfigBuilder(string.Empty, string.Empty, new Uri("http://boxsdk"))
.Build();
var client = new BoxClient(config, auth);

return client;
Expand Down
4 changes: 2 additions & 2 deletions Box.V2.Test/AuthRepositoryTest.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Moq;
using Box.V2.Services;
using System.Threading.Tasks;
Expand All @@ -23,7 +23,7 @@ public async Task AuthenticateLive_InvalidAuthCode_Exception()
// Arrange
IRequestHandler handler = new HttpRequestHandler();
IBoxService service = new BoxService(handler);
IBoxConfig config = new BoxConfig(null, null, null);
IBoxConfig config = new BoxConfigBuilder(null, null, null).Build();

IAuthRepository authRepository = new AuthRepository(config, service, Converter);

Expand Down
1 change: 1 addition & 0 deletions Box.V2.Test/Box.V2.Test.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@
<Compile Include="BoxSearchManagerTest.cs" />
<Compile Include="BoxStoragePoliciesManagerTest.cs" />
<Compile Include="BoxTasksManagerTest.cs" />
<Compile Include="BoxTermsOfServiceManagerTest.cs" />
<Compile Include="BoxUsersManagerTest.cs" />
<Compile Include="BoxCollaborationsManagerTest.cs" />
<Compile Include="BoxLegalHoldPoliciesManagerTest.cs" />
Expand Down
94 changes: 94 additions & 0 deletions Box.V2.Test/BoxTermsOfServiceManagerTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
using Box.V2.Config;
using Box.V2.Managers;
using Box.V2.Models;
using Box.V2.Models.Request;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Moq;
using Newtonsoft.Json;
using System;
using System.Threading.Tasks;

namespace Box.V2.Test
{
[TestClass]
public class BoxTermsOfServiceManagerTest : BoxResourceManagerTest
{
private readonly BoxTermsOfServiceManager _termsOfServiceManager;

public BoxTermsOfServiceManagerTest()
{
_termsOfServiceManager = new BoxTermsOfServiceManager(Config.Object, Service, Converter, AuthRepository);
}

[TestMethod]
public async Task CreateTermsOfServiceUserStatus_ValidResponse()
{
/*** Arrange ***/
string responseString = @"{
""type"": ""terms_of_service_user_status"",
""id"": ""11446498"",
""created_at"": ""2012-12-12T10:53:43-08:00"",
""is_accepted"": ""true"",
""modified_at"": ""2012-12-12T10:53:43-08:00"",
""tos"": {
""type"": ""terms_of_service"",
""id"": ""11446498"",
},
""user"": {
""type"": ""user"",
""id"": ""24446498"",
""name"": ""Aaron Levie"",
""login"": ""[email protected]""
},
}";
IBoxRequest boxRequest = null;
Uri tosUri = new Uri(Constants.BoxApiUriString + Constants.TermsOfServiceUserStatusesString);
Config.SetupGet(x => x.TermsOfServiceUserStatusesUri).Returns(tosUri);
Handler.Setup(h => h.ExecuteAsync<BoxTermsOfServiceUserStatuses>(It.IsAny<IBoxRequest>()))
.Returns(Task.FromResult<IBoxResponse<BoxTermsOfServiceUserStatuses>>(new BoxResponse<BoxTermsOfServiceUserStatuses>()
{
Status = ResponseStatus.Success,
ContentString = responseString
}))
.Callback<IBoxRequest>(r => boxRequest = r);

/*** Act ***/
var createStatusRequest = new BoxTermsOfServiceUserStatusCreateRequest()
{
TermsOfService = new BoxRequestEntity()
{
Id = "11446498",
Type = BoxType.terms_of_service
},
User = new BoxRequestEntity()
{
Id = "24446498",
Type = BoxType.user
},
IsAccepted = true
};
BoxTermsOfServiceUserStatuses result =
await _termsOfServiceManager.CreateBoxTermsOfServiceUserStatusesAsync(createStatusRequest);

/*** Assert ***/
//Request check
Assert.IsNotNull(boxRequest);
Assert.AreEqual(RequestMethod.Post, boxRequest.Method);
Assert.AreEqual(tosUri, boxRequest.AbsoluteUri.AbsoluteUri);
BoxTermsOfServiceUserStatusCreateRequest payload = JsonConvert.DeserializeObject<BoxTermsOfServiceUserStatusCreateRequest>(boxRequest.Payload);
Assert.AreEqual(createStatusRequest.TermsOfService.Id, payload.TermsOfService.Id);
Assert.AreEqual(createStatusRequest.TermsOfService.Type, payload.TermsOfService.Type);
Assert.AreEqual(createStatusRequest.User.Id, payload.User.Id);
Assert.AreEqual(createStatusRequest.User.Type, payload.User.Type);
Assert.AreEqual(createStatusRequest.IsAccepted, payload.IsAccepted);

//Response check
Assert.AreEqual("11446498", result.Id);
Assert.AreEqual("terms_of_service_user_status", result.Type);
Assert.AreEqual(true, result.IsAccepted);
Assert.AreEqual("11446498", result.TermsOfService.Id);
Assert.AreEqual("24446498", result.User.Id);
Assert.AreEqual("Aaron Levie", result.User.Name);
}
}
}
2 changes: 2 additions & 0 deletions Box.V2/Box.V2.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@
<Compile Include="Auth\Token\ActorTokenBuilder.cs" />
<Compile Include="Auth\Token\TokenExchange.cs" />
<Compile Include="BoxClient.cs" />
<Compile Include="Config\BoxConfigBuilder.cs" />
<Compile Include="IBoxClient.cs" />
<Compile Include="Converter\BoxZipConflictConverter.cs" />
<Compile Include="JWTAuth\BoxJWTAuth.cs" />
Expand Down Expand Up @@ -182,6 +183,7 @@
<Compile Include="Models\Request\BoxActionableByRequest.cs" />
<Compile Include="Models\BoxSessionParts.cs" />
<Compile Include="Models\Request\BoxFileUploadSessionRequest.cs" />
<Compile Include="Models\Request\BoxTermsOfServiceUserStatusCreateRequest.cs" />
<Compile Include="Models\Request\BoxZipRequest.cs" />
<Compile Include="Models\Request\BoxLegalHoldPolicyAssignmentRequest.cs" />
<Compile Include="Models\Request\BoxLegalHoldPolicyRequest.cs" />
Expand Down
Loading

0 comments on commit 8eb43eb

Please sign in to comment.