Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: Retention policy assignments integration test (box/box-codegen#390) #25

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
2 changes: 1 addition & 1 deletion .codegen.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{ "engineHash": "df5b5de", "specHash": "b2f7568", "version": "0.1.0" }
{ "engineHash": "332479b", "specHash": "b2f7568", "version": "0.1.0" }
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
using Microsoft.VisualStudio.TestTools.UnitTesting;
using NullableExtensions;
using Box.Sdk.Gen;
using Box.Sdk.Gen.Schemas;
using Box.Sdk.Gen.Managers;

namespace Box.Sdk.Gen.Tests.Integration {
[TestClass]
public class RetentionPolicyAssignmentsManagerTests {
public BoxClient client { get; }

public RetentionPolicyAssignmentsManagerTests() {
client = new CommonsManager().GetDefaultClient();
}
[TestMethod]
public async System.Threading.Tasks.Task TestCreateUpdateGetDeleteRetentionPolicyAssignment() {
string retentionPolicyName = Utils.GetUUID();
const string retentionDescription = "test description";
RetentionPolicy retentionPolicy = await client.RetentionPolicies.CreateRetentionPolicyAsync(requestBody: new CreateRetentionPolicyRequestBody(policyName: retentionPolicyName, policyType: CreateRetentionPolicyRequestBodyPolicyTypeField.Finite, dispositionAction: CreateRetentionPolicyRequestBodyDispositionActionField.RemoveRetention) { AreOwnersNotified = true, CanOwnerExtendRetention = true, Description = retentionDescription, RetentionLength = "1", RetentionType = CreateRetentionPolicyRequestBodyRetentionTypeField.Modifiable }).ConfigureAwait(false);
FolderFull folder = await client.Folders.CreateFolderAsync(requestBody: new CreateFolderRequestBody(name: Utils.GetUUID(), parent: new CreateFolderRequestBodyParentField(id: "0"))).ConfigureAwait(false);
Files files = await client.Uploads.UploadFileAsync(requestBody: new UploadFileRequestBody(attributes: new UploadFileRequestBodyAttributesField(name: Utils.GetUUID(), parent: new UploadFileRequestBodyAttributesParentField(id: folder.Id)), file: Utils.GenerateByteStream(size: 10))).ConfigureAwait(false);
FileFull file = NullableUtils.Unwrap(files.Entries)[0];
Files newVersions = await client.Uploads.UploadFileVersionAsync(fileId: file.Id, requestBody: new UploadFileVersionRequestBody(attributes: new UploadFileVersionRequestBodyAttributesField(name: Utils.GetUUID()), file: Utils.GenerateByteStream(size: 20))).ConfigureAwait(false);
FileFull newVersion = NullableUtils.Unwrap(newVersions.Entries)[0];
RetentionPolicyAssignment retentionPolicyAssignment = await client.RetentionPolicyAssignments.CreateRetentionPolicyAssignmentAsync(requestBody: new CreateRetentionPolicyAssignmentRequestBody(policyId: retentionPolicy.Id, assignTo: new CreateRetentionPolicyAssignmentRequestBodyAssignToField(type: CreateRetentionPolicyAssignmentRequestBodyAssignToTypeField.Folder) { Id = folder.Id })).ConfigureAwait(false);
Assert.IsTrue(NullableUtils.Unwrap(retentionPolicyAssignment.RetentionPolicy).Id == retentionPolicy.Id);
Assert.IsTrue(NullableUtils.Unwrap(retentionPolicyAssignment.AssignedTo).Id == folder.Id);
RetentionPolicyAssignment retentionPolicyAssignmentById = await client.RetentionPolicyAssignments.GetRetentionPolicyAssignmentByIdAsync(retentionPolicyAssignmentId: retentionPolicyAssignment.Id).ConfigureAwait(false);
Assert.IsTrue(retentionPolicyAssignmentById.Id == retentionPolicyAssignment.Id);
RetentionPolicyAssignments retentionPolicyAssignments = await client.RetentionPolicyAssignments.GetRetentionPolicyAssignmentsAsync(retentionPolicyId: retentionPolicy.Id).ConfigureAwait(false);
Assert.IsTrue(NullableUtils.Unwrap(retentionPolicyAssignments.Entries).Count == 1);
FilesUnderRetention filesUnderRetention = await client.RetentionPolicyAssignments.GetFilesUnderRetentionPolicyAssignmentAsync(retentionPolicyAssignmentId: retentionPolicyAssignment.Id).ConfigureAwait(false);
Assert.IsTrue(NullableUtils.Unwrap(filesUnderRetention.Entries).Count == 1);
await client.RetentionPolicyAssignments.DeleteRetentionPolicyAssignmentByIdAsync(retentionPolicyAssignmentId: retentionPolicyAssignment.Id).ConfigureAwait(false);
RetentionPolicyAssignments retentionPolicyAssignmentsAfterDelete = await client.RetentionPolicyAssignments.GetRetentionPolicyAssignmentsAsync(retentionPolicyId: retentionPolicy.Id).ConfigureAwait(false);
Assert.IsTrue(NullableUtils.Unwrap(retentionPolicyAssignmentsAfterDelete.Entries).Count == 0);
await client.RetentionPolicies.DeleteRetentionPolicyByIdAsync(retentionPolicyId: retentionPolicy.Id).ConfigureAwait(false);
await client.Files.DeleteFileByIdAsync(fileId: file.Id).ConfigureAwait(false);
}

}
}
22 changes: 17 additions & 5 deletions docs/RetentionPolicyAssignments.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,10 @@ This operation is performed by calling function `GetRetentionPolicyAssignments`.
See the endpoint docs at
[API Reference](https://developer.box.com/reference/get-retention-policies-id-assignments/).

*Currently we don't have an example for calling `GetRetentionPolicyAssignments` in integration tests*
<!-- sample get_retention_policies_id_assignments -->
```
await client.RetentionPolicyAssignments.GetRetentionPolicyAssignmentsAsync(retentionPolicyId: retentionPolicy.Id).ConfigureAwait(false)
```

### Arguments

Expand Down Expand Up @@ -51,7 +54,7 @@ See the endpoint docs at

<!-- sample post_retention_policy_assignments -->
```
await client.RetentionPolicyAssignments.CreateRetentionPolicyAssignmentAsync(requestBody: new CreateRetentionPolicyAssignmentRequestBody(policyId: retentionPolicy.Id, assignTo: new CreateRetentionPolicyAssignmentRequestBodyAssignToField(id: folder.Id, type: CreateRetentionPolicyAssignmentRequestBodyAssignToTypeField.Folder))).ConfigureAwait(false)
await client.RetentionPolicyAssignments.CreateRetentionPolicyAssignmentAsync(requestBody: new CreateRetentionPolicyAssignmentRequestBody(policyId: retentionPolicy.Id, assignTo: new CreateRetentionPolicyAssignmentRequestBodyAssignToField(type: CreateRetentionPolicyAssignmentRequestBodyAssignToTypeField.Folder, id: folder.Id))).ConfigureAwait(false)
```

### Arguments
Expand Down Expand Up @@ -80,7 +83,10 @@ This operation is performed by calling function `GetRetentionPolicyAssignmentByI
See the endpoint docs at
[API Reference](https://developer.box.com/reference/get-retention-policy-assignments-id/).

*Currently we don't have an example for calling `GetRetentionPolicyAssignmentById` in integration tests*
<!-- sample get_retention_policy_assignments_id -->
```
await client.RetentionPolicyAssignments.GetRetentionPolicyAssignmentByIdAsync(retentionPolicyAssignmentId: retentionPolicyAssignment.Id).ConfigureAwait(false)
```

### Arguments

Expand Down Expand Up @@ -111,7 +117,10 @@ This operation is performed by calling function `DeleteRetentionPolicyAssignment
See the endpoint docs at
[API Reference](https://developer.box.com/reference/delete-retention-policy-assignments-id/).

*Currently we don't have an example for calling `DeleteRetentionPolicyAssignmentById` in integration tests*
<!-- sample delete_retention_policy_assignments_id -->
```
await client.RetentionPolicyAssignments.DeleteRetentionPolicyAssignmentByIdAsync(retentionPolicyAssignmentId: retentionPolicyAssignment.Id).ConfigureAwait(false)
```

### Arguments

Expand Down Expand Up @@ -140,7 +149,10 @@ This operation is performed by calling function `GetFilesUnderRetentionPolicyAss
See the endpoint docs at
[API Reference](https://developer.box.com/reference/get-retention-policy-assignments-id-files-under-retention/).

*Currently we don't have an example for calling `GetFilesUnderRetentionPolicyAssignment` in integration tests*
<!-- sample get_retention_policy_assignments_id_files_under_retention -->
```
await client.RetentionPolicyAssignments.GetFilesUnderRetentionPolicyAssignmentAsync(retentionPolicyAssignmentId: retentionPolicyAssignment.Id).ConfigureAwait(false)
```

### Arguments

Expand Down
Loading