Skip to content

Commit

Permalink
fix: fix docs code samples (box/box-codegen#451) (#53)
Browse files Browse the repository at this point in the history
  • Loading branch information
box-sdk-build authored Mar 22, 2024
1 parent 02c7c2b commit 5f79cfd
Show file tree
Hide file tree
Showing 129 changed files with 756 additions and 756 deletions.
2 changes: 1 addition & 1 deletion .codegen.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{ "engineHash": "3d3d072", "specHash": "d50ab5f", "version": "0.3.0" }
{ "engineHash": "ac30b07", "specHash": "d50ab5f", "version": "0.3.0" }
74 changes: 37 additions & 37 deletions Box.Sdk.Gen.Tests.Integration/Test/Auth/AuthManagerTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@ public async System.Threading.Tasks.Task TestJwtAuth() {
BoxJwtAuth auth = new BoxJwtAuth(config: jwtConfig);
BoxJwtAuth userAuth = auth.AsUser(userId: userId);
BoxClient userClient = new BoxClient(auth: userAuth);
UserFull currentUser = await userClient.Users.GetUserMeAsync().ConfigureAwait(false);
UserFull currentUser = await userClient.Users.GetUserMeAsync();
Assert.IsTrue(currentUser.Id == userId);
BoxJwtAuth enterpriseAuth = auth.AsEnterprise(userId: enterpriseId);
BoxClient enterpriseClient = new BoxClient(auth: enterpriseAuth);
UserFull newUser = await enterpriseClient.Users.GetUserMeAsync(queryParams: new GetUserMeQueryParams() { Fields = Array.AsReadOnly(new [] {"enterprise"}) }).ConfigureAwait(false);
UserFull newUser = await enterpriseClient.Users.GetUserMeAsync(queryParams: new GetUserMeQueryParams() { Fields = Array.AsReadOnly(new [] {"enterprise"}) });
Assert.IsTrue(newUser.Enterprise != null);
Assert.IsTrue(NullableUtils.Unwrap(newUser.Enterprise).Id == enterpriseId);
Assert.IsTrue(newUser.Id != userId);
Expand All @@ -34,25 +34,25 @@ public async System.Threading.Tasks.Task TestJwtAuthDownscope() {
JwtConfig jwtConfig = JwtConfig.FromConfigJsonString(configJsonString: Utils.DecodeBase64(value: Utils.GetEnvVar(name: "JWT_CONFIG_BASE_64")));
BoxJwtAuth auth = new BoxJwtAuth(config: jwtConfig);
BoxClient parentClient = new BoxClient(auth: auth);
Files uploadedFiles = await parentClient.Uploads.UploadFileAsync(requestBody: new UploadFileRequestBody(attributes: new UploadFileRequestBodyAttributesField(name: Utils.GetUUID(), parent: new UploadFileRequestBodyAttributesParentField(id: "0")), file: Utils.GenerateByteStream(size: 1024 * 1024))).ConfigureAwait(false);
Files uploadedFiles = await parentClient.Uploads.UploadFileAsync(requestBody: new UploadFileRequestBody(attributes: new UploadFileRequestBodyAttributesField(name: Utils.GetUUID(), parent: new UploadFileRequestBodyAttributesParentField(id: "0")), file: Utils.GenerateByteStream(size: 1024 * 1024)));
FileFull file = NullableUtils.Unwrap(uploadedFiles.Entries)[0];
string resourcePath = string.Concat("https://api.box.com/2.0/files/", file.Id);
AccessToken downscopedToken = await auth.DownscopeTokenAsync(scopes: Array.AsReadOnly(new [] {"item_rename","item_preview"}), resource: resourcePath).ConfigureAwait(false);
AccessToken downscopedToken = await auth.DownscopeTokenAsync(scopes: Array.AsReadOnly(new [] {"item_rename","item_preview"}), resource: resourcePath);
Assert.IsTrue(downscopedToken.AccessTokenField != null);
BoxClient downscopedClient = new BoxClient(auth: new BoxDeveloperTokenAuth(token: downscopedToken.AccessTokenField));
await downscopedClient.Files.UpdateFileByIdAsync(fileId: file.Id, requestBody: new UpdateFileByIdRequestBody() { Name = Utils.GetUUID() }).ConfigureAwait(false);
await Assert.That.IsExceptionAsync(async() => await downscopedClient.Files.DeleteFileByIdAsync(fileId: file.Id).ConfigureAwait(false));
await parentClient.Files.DeleteFileByIdAsync(fileId: file.Id).ConfigureAwait(false);
await downscopedClient.Files.UpdateFileByIdAsync(fileId: file.Id, requestBody: new UpdateFileByIdRequestBody() { Name = Utils.GetUUID() });
await Assert.That.IsExceptionAsync(async() => await downscopedClient.Files.DeleteFileByIdAsync(fileId: file.Id));
await parentClient.Files.DeleteFileByIdAsync(fileId: file.Id);
}

[TestMethod]
public async System.Threading.Tasks.Task TestJwtAuthRevoke() {
JwtConfig jwtConfig = JwtConfig.FromConfigJsonString(configJsonString: Utils.DecodeBase64(value: Utils.GetEnvVar(name: "JWT_CONFIG_BASE_64")));
BoxJwtAuth auth = new BoxJwtAuth(config: jwtConfig);
await auth.RetrieveTokenAsync().ConfigureAwait(false);
AccessToken? tokenFromStorageBeforeRevoke = await auth.TokenStorage.GetAsync().ConfigureAwait(false);
await auth.RevokeTokenAsync().ConfigureAwait(false);
AccessToken? tokenFromStorageAfterRevoke = await auth.TokenStorage.GetAsync().ConfigureAwait(false);
await auth.RetrieveTokenAsync();
AccessToken? tokenFromStorageBeforeRevoke = await auth.TokenStorage.GetAsync();
await auth.RevokeTokenAsync();
AccessToken? tokenFromStorageAfterRevoke = await auth.TokenStorage.GetAsync();
Assert.IsTrue(tokenFromStorageBeforeRevoke != null);
Assert.IsTrue(tokenFromStorageAfterRevoke == null);
}
Expand All @@ -73,11 +73,11 @@ public async System.Threading.Tasks.Task TestCcgAuth() {
BoxCcgAuth auth = new BoxCcgAuth(config: ccgConfig);
BoxCcgAuth userAuth = auth.AsUser(userId: userId);
BoxClient userClient = new BoxClient(auth: userAuth);
UserFull currentUser = await userClient.Users.GetUserMeAsync().ConfigureAwait(false);
UserFull currentUser = await userClient.Users.GetUserMeAsync();
Assert.IsTrue(currentUser.Id == userId);
BoxCcgAuth enterpriseAuth = auth.AsEnterprise(enterpriseId: enterpriseId);
BoxClient enterpriseClient = new BoxClient(auth: enterpriseAuth);
UserFull newUser = await enterpriseClient.Users.GetUserMeAsync(queryParams: new GetUserMeQueryParams() { Fields = Array.AsReadOnly(new [] {"enterprise"}) }).ConfigureAwait(false);
UserFull newUser = await enterpriseClient.Users.GetUserMeAsync(queryParams: new GetUserMeQueryParams() { Fields = Array.AsReadOnly(new [] {"enterprise"}) });
Assert.IsTrue(newUser.Enterprise != null);
Assert.IsTrue(NullableUtils.Unwrap(newUser.Enterprise).Id == enterpriseId);
Assert.IsTrue(newUser.Id != userId);
Expand All @@ -88,24 +88,24 @@ public async System.Threading.Tasks.Task TestCcgAuthDownscope() {
CcgConfig ccgConfig = new CcgConfig(clientId: Utils.GetEnvVar(name: "CLIENT_ID"), clientSecret: Utils.GetEnvVar(name: "CLIENT_SECRET")) { UserId = Utils.GetEnvVar(name: "USER_ID") };
BoxCcgAuth auth = new BoxCcgAuth(config: ccgConfig);
BoxClient parentClient = new BoxClient(auth: auth);
FolderFull folder = await parentClient.Folders.CreateFolderAsync(requestBody: new CreateFolderRequestBody(name: Utils.GetUUID(), parent: new CreateFolderRequestBodyParentField(id: "0"))).ConfigureAwait(false);
FolderFull folder = await parentClient.Folders.CreateFolderAsync(requestBody: new CreateFolderRequestBody(name: Utils.GetUUID(), parent: new CreateFolderRequestBodyParentField(id: "0")));
string resourcePath = string.Concat("https://api.box.com/2.0/folders/", folder.Id);
AccessToken downscopedToken = await auth.DownscopeTokenAsync(scopes: Array.AsReadOnly(new [] {"item_rename","item_preview"}), resource: resourcePath).ConfigureAwait(false);
AccessToken downscopedToken = await auth.DownscopeTokenAsync(scopes: Array.AsReadOnly(new [] {"item_rename","item_preview"}), resource: resourcePath);
Assert.IsTrue(downscopedToken.AccessTokenField != null);
BoxClient downscopedClient = new BoxClient(auth: new BoxDeveloperTokenAuth(token: downscopedToken.AccessTokenField));
await downscopedClient.Folders.UpdateFolderByIdAsync(folderId: folder.Id, requestBody: new UpdateFolderByIdRequestBody() { Name = Utils.GetUUID() }).ConfigureAwait(false);
await Assert.That.IsExceptionAsync(async() => await downscopedClient.Folders.DeleteFolderByIdAsync(folderId: folder.Id).ConfigureAwait(false));
await parentClient.Folders.DeleteFolderByIdAsync(folderId: folder.Id).ConfigureAwait(false);
await downscopedClient.Folders.UpdateFolderByIdAsync(folderId: folder.Id, requestBody: new UpdateFolderByIdRequestBody() { Name = Utils.GetUUID() });
await Assert.That.IsExceptionAsync(async() => await downscopedClient.Folders.DeleteFolderByIdAsync(folderId: folder.Id));
await parentClient.Folders.DeleteFolderByIdAsync(folderId: folder.Id);
}

[TestMethod]
public async System.Threading.Tasks.Task TestCcgAuthRevoke() {
CcgConfig ccgConfig = new CcgConfig(clientId: Utils.GetEnvVar(name: "CLIENT_ID"), clientSecret: Utils.GetEnvVar(name: "CLIENT_SECRET")) { UserId = Utils.GetEnvVar(name: "USER_ID") };
BoxCcgAuth auth = new BoxCcgAuth(config: ccgConfig);
await auth.RetrieveTokenAsync().ConfigureAwait(false);
AccessToken? tokenFromStorageBeforeRevoke = await auth.TokenStorage.GetAsync().ConfigureAwait(false);
await auth.RevokeTokenAsync().ConfigureAwait(false);
AccessToken? tokenFromStorageAfterRevoke = await auth.TokenStorage.GetAsync().ConfigureAwait(false);
await auth.RetrieveTokenAsync();
AccessToken? tokenFromStorageBeforeRevoke = await auth.TokenStorage.GetAsync();
await auth.RevokeTokenAsync();
AccessToken? tokenFromStorageAfterRevoke = await auth.TokenStorage.GetAsync();
Assert.IsTrue(tokenFromStorageBeforeRevoke != null);
Assert.IsTrue(tokenFromStorageAfterRevoke == null);
}
Expand All @@ -116,17 +116,17 @@ public async System.Threading.Tasks.Task<AccessToken> GetAccessTokenAsync() {
CcgConfig ccgConfig = new CcgConfig(clientId: Utils.GetEnvVar(name: "CLIENT_ID"), clientSecret: Utils.GetEnvVar(name: "CLIENT_SECRET")) { EnterpriseId = enterpriseId, UserId = userId };
BoxCcgAuth auth = new BoxCcgAuth(config: ccgConfig);
auth.AsUser(userId: userId);
AccessToken token = await auth.RetrieveTokenAsync().ConfigureAwait(false);
AccessToken token = await auth.RetrieveTokenAsync();
return token;
}

[TestMethod]
public async System.Threading.Tasks.Task TestDeveloperTokenAuth() {
string userId = Utils.GetEnvVar(name: "USER_ID");
AccessToken token = await GetAccessTokenAsync().ConfigureAwait(false);
AccessToken token = await GetAccessTokenAsync();
BoxDeveloperTokenAuth devAuth = new BoxDeveloperTokenAuth(token: token.AccessTokenField);
BoxClient client = new BoxClient(auth: devAuth);
UserFull currentUser = await client.Users.GetUserMeAsync().ConfigureAwait(false);
UserFull currentUser = await client.Users.GetUserMeAsync();
Assert.IsTrue(currentUser.Id == userId);
}

Expand All @@ -135,29 +135,29 @@ public async System.Threading.Tasks.Task TestOauthAuthRevoke() {
OAuthConfig config = new OAuthConfig(clientId: Utils.GetEnvVar(name: "CLIENT_ID"), clientSecret: Utils.GetEnvVar(name: "CLIENT_SECRET"));
BoxOAuth auth = new BoxOAuth(config: config);
BoxClient client = new BoxClient(auth: auth);
AccessToken token = await GetAccessTokenAsync().ConfigureAwait(false);
await auth.TokenStorage.StoreAsync(token: token).ConfigureAwait(false);
await client.Users.GetUserMeAsync().ConfigureAwait(false);
await auth.RevokeTokenAsync().ConfigureAwait(false);
await Assert.That.IsExceptionAsync(async() => await client.Users.GetUserMeAsync().ConfigureAwait(false));
AccessToken token = await GetAccessTokenAsync();
await auth.TokenStorage.StoreAsync(token: token);
await client.Users.GetUserMeAsync();
await auth.RevokeTokenAsync();
await Assert.That.IsExceptionAsync(async() => await client.Users.GetUserMeAsync());
}

[TestMethod]
public async System.Threading.Tasks.Task TestOauthAuthDownscope() {
OAuthConfig config = new OAuthConfig(clientId: Utils.GetEnvVar(name: "CLIENT_ID"), clientSecret: Utils.GetEnvVar(name: "CLIENT_SECRET"));
BoxOAuth auth = new BoxOAuth(config: config);
AccessToken token = await GetAccessTokenAsync().ConfigureAwait(false);
await auth.TokenStorage.StoreAsync(token: token).ConfigureAwait(false);
AccessToken token = await GetAccessTokenAsync();
await auth.TokenStorage.StoreAsync(token: token);
BoxClient parentClient = new BoxClient(auth: auth);
Files uploadedFiles = await parentClient.Uploads.UploadFileAsync(requestBody: new UploadFileRequestBody(attributes: new UploadFileRequestBodyAttributesField(name: Utils.GetUUID(), parent: new UploadFileRequestBodyAttributesParentField(id: "0")), file: Utils.GenerateByteStream(size: 1024 * 1024))).ConfigureAwait(false);
Files uploadedFiles = await parentClient.Uploads.UploadFileAsync(requestBody: new UploadFileRequestBody(attributes: new UploadFileRequestBodyAttributesField(name: Utils.GetUUID(), parent: new UploadFileRequestBodyAttributesParentField(id: "0")), file: Utils.GenerateByteStream(size: 1024 * 1024)));
FileFull file = NullableUtils.Unwrap(uploadedFiles.Entries)[0];
string resourcePath = string.Concat("https://api.box.com/2.0/files/", file.Id);
AccessToken downscopedToken = await auth.DownscopeTokenAsync(scopes: Array.AsReadOnly(new [] {"item_rename","item_preview"}), resource: resourcePath).ConfigureAwait(false);
AccessToken downscopedToken = await auth.DownscopeTokenAsync(scopes: Array.AsReadOnly(new [] {"item_rename","item_preview"}), resource: resourcePath);
Assert.IsTrue(downscopedToken.AccessTokenField != null);
BoxClient downscopedClient = new BoxClient(auth: new BoxDeveloperTokenAuth(token: downscopedToken.AccessTokenField));
await downscopedClient.Files.UpdateFileByIdAsync(fileId: file.Id, requestBody: new UpdateFileByIdRequestBody() { Name = Utils.GetUUID() }).ConfigureAwait(false);
await Assert.That.IsExceptionAsync(async() => await downscopedClient.Files.DeleteFileByIdAsync(fileId: file.Id).ConfigureAwait(false));
await parentClient.Files.DeleteFileByIdAsync(fileId: file.Id).ConfigureAwait(false);
await downscopedClient.Files.UpdateFileByIdAsync(fileId: file.Id, requestBody: new UpdateFileByIdRequestBody() { Name = Utils.GetUUID() });
await Assert.That.IsExceptionAsync(async() => await downscopedClient.Files.DeleteFileByIdAsync(fileId: file.Id));
await parentClient.Files.DeleteFileByIdAsync(fileId: file.Id);
}

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,15 @@ public AvatarsManagerTests() {
}
[TestMethod]
public async System.Threading.Tasks.Task TestAvatars() {
UserFull user = await client.Users.GetUserMeAsync().ConfigureAwait(false);
UserAvatar createdAvatar = await client.Avatars.CreateUserAvatarAsync(userId: user.Id, requestBody: new CreateUserAvatarRequestBody(pic: Utils.DecodeBase64ByteStream(data: "iVBORw0KGgoAAAANSUhEUgAAAQAAAAEAAQMAAABmvDolAAAAA1BMVEW10NBjBBbqAAAAH0lEQVRoge3BAQ0AAADCoPdPbQ43oAAAAAAAAAAAvg0hAAABmmDh1QAAAABJRU5ErkJggg==")) { PicContentType = "image/png", PicFileName = "avatar.png" }).ConfigureAwait(false);
UserFull user = await client.Users.GetUserMeAsync();
UserAvatar createdAvatar = await client.Avatars.CreateUserAvatarAsync(userId: user.Id, requestBody: new CreateUserAvatarRequestBody(pic: Utils.DecodeBase64ByteStream(data: "iVBORw0KGgoAAAANSUhEUgAAAQAAAAEAAQMAAABmvDolAAAAA1BMVEW10NBjBBbqAAAAH0lEQVRoge3BAQ0AAADCoPdPbQ43oAAAAAAAAAAAvg0hAAABmmDh1QAAAABJRU5ErkJggg==")) { PicContentType = "image/png", PicFileName = "avatar.png" });
Assert.IsTrue(NullableUtils.Unwrap(createdAvatar.PicUrls).Small != null);
Assert.IsTrue(NullableUtils.Unwrap(createdAvatar.PicUrls).Large != null);
Assert.IsTrue(NullableUtils.Unwrap(createdAvatar.PicUrls).Preview != null);
System.IO.Stream response = await client.Avatars.GetUserAvatarAsync(userId: user.Id).ConfigureAwait(false);
Assert.IsTrue(Utils.BufferEquals(buffer1: await Utils.ReadByteStreamAsync(byteStream: response).ConfigureAwait(false), buffer2: Utils.GenerateByteBuffer(size: 0)) == false);
await client.Avatars.DeleteUserAvatarAsync(userId: user.Id).ConfigureAwait(false);
await Assert.That.IsExceptionAsync(async() => await client.Avatars.GetUserAvatarAsync(userId: user.Id).ConfigureAwait(false));
System.IO.Stream response = await client.Avatars.GetUserAvatarAsync(userId: user.Id);
Assert.IsTrue(Utils.BufferEquals(buffer1: await Utils.ReadByteStreamAsync(byteStream: response), buffer2: Utils.GenerateByteBuffer(size: 0)) == false);
await client.Avatars.DeleteUserAvatarAsync(userId: user.Id);
await Assert.That.IsExceptionAsync(async() => await client.Avatars.GetUserAvatarAsync(userId: user.Id));
}

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@ public async System.Threading.Tasks.Task TestChunkedUpload() {
System.IO.Stream fileByteStream = Utils.GenerateByteStream(size: fileSize);
string fileName = Utils.GetUUID();
const string parentFolderId = "0";
File uploadedFile = await client.ChunkedUploads.UploadBigFileAsync(file: fileByteStream, fileName: fileName, fileSize: fileSize, parentFolderId: parentFolderId).ConfigureAwait(false);
File uploadedFile = await client.ChunkedUploads.UploadBigFileAsync(file: fileByteStream, fileName: fileName, fileSize: fileSize, parentFolderId: parentFolderId);
Assert.IsTrue(uploadedFile.Name == fileName);
Assert.IsTrue(uploadedFile.Size == fileSize);
Assert.IsTrue(NullableUtils.Unwrap(uploadedFile.Parent).Id == parentFolderId);
await client.Files.DeleteFileByIdAsync(fileId: uploadedFile.Id).ConfigureAwait(false);
await client.Files.DeleteFileByIdAsync(fileId: uploadedFile.Id);
}

}
Expand Down
Loading

0 comments on commit 5f79cfd

Please sign in to comment.