From f60086b76336e409cdde93cf02696c1d8e5adc03 Mon Sep 17 00:00:00 2001 From: Harun Gachanja Gitundu Date: Tue, 17 Oct 2023 17:44:43 +0300 Subject: [PATCH] Add tests --- .github/workflows/main.yml | 51 +- datamanagement/test/TestDataManagement.cs | 501 +++++++++++++++++- .../Autodesk.Sdk.Manager.csproj | 0 {sdk-manager-dotnet => sdk-manager}/README.md | 0 .../src/APSClient.cs | 0 .../src/APSConfiguration.cs | 0 .../src/AuthClient.cs | 0 .../src/AuthClientConfiguration.cs | 0 .../src/IAPSClient.cs | 0 .../src/IAPSConfiguration.cs | 0 .../src/IAuthClient.cs | 0 .../src/IAuthClientConfiguration.cs | 0 .../src/IBuilder.cs | 0 .../src/IResiliencyConfiguration.cs | 0 .../src/ISDKManager.cs | 0 .../src/ResiliencyConfiguration.cs | 0 .../src/SDKManager.cs | 0 .../src/SDKManagerBuilder.cs | 0 webhooks/test/TestWebhooks.cs | 136 ++++- 19 files changed, 658 insertions(+), 30 deletions(-) rename {sdk-manager-dotnet => sdk-manager}/Autodesk.Sdk.Manager.csproj (100%) rename {sdk-manager-dotnet => sdk-manager}/README.md (100%) rename {sdk-manager-dotnet => sdk-manager}/src/APSClient.cs (100%) rename {sdk-manager-dotnet => sdk-manager}/src/APSConfiguration.cs (100%) rename {sdk-manager-dotnet => sdk-manager}/src/AuthClient.cs (100%) rename {sdk-manager-dotnet => sdk-manager}/src/AuthClientConfiguration.cs (100%) rename {sdk-manager-dotnet => sdk-manager}/src/IAPSClient.cs (100%) rename {sdk-manager-dotnet => sdk-manager}/src/IAPSConfiguration.cs (100%) rename {sdk-manager-dotnet => sdk-manager}/src/IAuthClient.cs (100%) rename {sdk-manager-dotnet => sdk-manager}/src/IAuthClientConfiguration.cs (100%) rename {sdk-manager-dotnet => sdk-manager}/src/IBuilder.cs (100%) rename {sdk-manager-dotnet => sdk-manager}/src/IResiliencyConfiguration.cs (100%) rename {sdk-manager-dotnet => sdk-manager}/src/ISDKManager.cs (100%) rename {sdk-manager-dotnet => sdk-manager}/src/ResiliencyConfiguration.cs (100%) rename {sdk-manager-dotnet => sdk-manager}/src/SDKManager.cs (100%) rename {sdk-manager-dotnet => sdk-manager}/src/SDKManagerBuilder.cs (100%) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index de81cea..d4286d0 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -1,4 +1,4 @@ -name: Run Tests +name: Run Tests on Develop on: push: @@ -20,38 +20,53 @@ jobs: - name: Build run: | + # Clean, restore, and build the .NET project dotnet clean dotnet restore dotnet build - - name: Set environment variables + - name: Set Environment Variables env: ACCESS_TOKEN: ${{ secrets.ACCESS_TOKEN }} CALLBACK_URL: ${{ secrets.CALLBACK_URL }} WORKFLOW_ID: ${{ secrets.WORKFLOW_ID }} - run: echo "The secret key is $ACCESS_TOKEN" + HOOK_ID: ${{ secrets.HOOK_ID }} + DOWNLOAD_ID: ${{ secrets.DOWNLOAD_ID }} + FOLDER_ID: ${{ secrets.FOLDER_ID }} + HUB_ID: ${{ secrets.HUB_ID }} + ITEM_ID: ${{ secrets.ITEM_ID }} + JOB_ID: ${{ secrets.JOB_ID }} + PROJECT_ID: ${{ secrets.PROJECT_ID }} + VERSION_ID: ${{ secrets.VERSION_ID }} + run: | + # Display the secret key for verification + echo "The secret key is $ACCESS_TOKEN" - name: Test Webhooks run: | + # Run tests for the Webhooks component cd webhooks/test - dotnet test --configuration Release + dotnet test --configuration Release /p:CollectCoverage=true /p:CoverletOutputFormat=opencover - - name: Test DataManagement + - name: Test Data Management run: | + # Run tests for the Data Management component cd datamanagement/test - dotnet test --configuration Release + dotnet test --configuration Release /p:CollectCoverage=true /p:CoverletOutputFormat=opencover - - name: Test OSS - run: | - cd oss/test - dotnet test --configuration Release + # - name: Test OSS + # run: | + # # Run tests for the Object Storage Service (OSS) + # cd oss/test + # dotnet test --configuration Release /p:CollectCoverage=true /p:CoverletOutputFormat=opencover - - name: Test Webhooks - run: | - cd webhooks/test - dotnet test --configuration Release + # - name: Test Model Derivative + # run: | + # # Run tests for the Model Derivative component + # cd modelderivative/test + # dotnet test --configuration Release /p:CollectCoverage=true /p:CoverletOutputFormat=opencover - - name: Test ModelDerivative - run: | - cd modelderivative/test - dotnet test --configuration Release + # - name: Upload Code Coverage Report to Codecov + # uses: codecov/codecov-action@v2 + # with: + # token: ${{ secrets.CODECOV_TOKEN }} diff --git a/datamanagement/test/TestDataManagement.cs b/datamanagement/test/TestDataManagement.cs index df5e7d8..07c7c65 100644 --- a/datamanagement/test/TestDataManagement.cs +++ b/datamanagement/test/TestDataManagement.cs @@ -4,6 +4,7 @@ using Autodesk.DataManagement.Model; using Microsoft.VisualStudio.TestTools.UnitTesting; using Autodesk.SDKManager; +using Type = Autodesk.DataManagement.Model.Type; namespace Autodesk.DataManagement.Test; @@ -13,7 +14,14 @@ public class TestDataManagement { private static DataManagementClient _dataManagementApi = null!; - private const string token = ""; + string token = Environment.GetEnvironmentVariable("ACCESS_TOKEN"); + string hubId = Environment.GetEnvironmentVariable("HUB_ID"); + string projectId = Environment.GetEnvironmentVariable("PROJECT_ID"); + string downloadId = Environment.GetEnvironmentVariable("DOWNLOAD_ID"); + string jobId = Environment.GetEnvironmentVariable("JOB_ID"); + string folderId = Environment.GetEnvironmentVariable("FOLDER_ID"); + string itemId = Environment.GetEnvironmentVariable("ITEM_ID"); + string versionId = Environment.GetEnvironmentVariable("VERSION_ID"); [ClassInitialize] public static void ClassInitialize(TestContext testContext) @@ -34,5 +42,496 @@ public async Task TestGetHubsAsync() Assert.IsTrue(getHubsResponse.Data.Count > 0); } + [TestMethod] + public async Task TestGetHubAsync() + { + Hub getHubResponse = await _dataManagementApi.GetHubAsync(hubId: hubId, accessToken: token); + HubData getHubData = getHubResponse.Data; + Assert.IsTrue(hubId == getHubData.Id); + } + + [TestMethod] + public async Task TestGetHubProjectsAsync() + { + Projects getHubProjects = await _dataManagementApi.GetHubProjectsAsync(hubId: hubId, accessToken: token); + Assert.IsTrue(getHubProjects.Data.Count > 0); + } + + [TestMethod] + public async Task TestGetProjectAsync() + { + Project getHubProject = await _dataManagementApi.GetProjectAsync(hubId: hubId, projectId: projectId, accessToken: token); + ProjectsData getHubProjectData = getHubProject.Data; + Assert.IsTrue(projectId == getHubProjectData.Id); + } + + [TestMethod] + public async Task TestGetProjectHubAsync() + { + Hub getHub = await _dataManagementApi.GetProjectHubAsync(hubId: hubId, projectId: projectId, accessToken: token); + HubData getHubData = getHub.Data; + Assert.IsTrue(hubId == getHubData.Id); + } + + [TestMethod] + public async Task TestGetProjectTopFoldersAsync() + { + TopFolders projectTopFolders = await _dataManagementApi.GetProjectTopFoldersAsync(hubId: hubId, projectId: projectId, accessToken: token); + Assert.IsTrue(projectTopFolders.Data.Count > 0); + } + + [TestMethod] + public async Task TestGetDownloadAsync() + { + Download download = await _dataManagementApi.GetDownloadAsync(projectId: projectId, downloadId: downloadId, accessToken: token); + CreatedDownloadData downloadData = download.Data; + Assert.IsTrue(downloadId == downloadData.Id); + } + + [TestMethod] + public async Task TestGetDownloadJobAsync() + { + Job job = await _dataManagementApi.GetDownloadJobAsync(projectId: projectId, jobId: jobId, accessToken: token); + CreatedDownloadData jobData = job.Data; + Assert.IsTrue(jobId == jobData.Id); + } + + [TestMethod] + public async Task TestCreateDownloadAsync() + { + CreateDownload createDownload = new CreateDownload(); + + createDownload.Jsonapi._Version = VersionNumber._10; + + CreateDownloadData createDownloadData = createDownload.Data; + createDownloadData.Type = Type.Downloads; + + CreateDownloadDataAttributes attributes = createDownloadData.Attributes; + CreateDownloadDataAttributesFormat Format = attributes.Format; + + CreateDownloadDataRelationships relationships = createDownloadData.Relationships; + StorageRequestDataRelationshipsTarget source = relationships.Source; + StorageRequestDataRelationshipsTargetData storageData = source.Data; + storageData.Type = Type.Versions; + storageData.Id = versionId; + + CreatedDownload createdDownload = await _dataManagementApi.CreateDownloadAsync(projectId: projectId, createDownload: createDownload, accessToken: token); + CreatedDownloadData createdDownloadData = createdDownload.Data; + Assert.IsTrue(createdDownloadData.Type == "jobs"); + + } + + [TestMethod] + public async Task TestCreateStorageAsync() + { + StorageRequest storageRequest = new StorageRequest(); + + storageRequest.Jsonapi._Version = VersionNumber._10; + + StorageRequestData storageData = storageRequest.Data; + storageData.Type = Type.Objects; + + StorageRequestDataAttributes attributes = storageData.Attributes; + attributes.Name = "drawing.dwg"; + + StorageRequestDataRelationships relationships = storageData.Relationships; + StorageRequestDataRelationshipsTarget target = relationships.Target; + StorageRequestDataRelationshipsTargetData targetData = target.Data; + targetData.Type = Type.Folders; + targetData.Id = "urn:adsk.wipprod:fs.folder:co.mgS-lb-BThaTdHnhiN_mbA"; + + Storage createdStorage = await _dataManagementApi.CreateStorageAsync(projectId: projectId, storageRequest: storageRequest, accessToken: token); + StorageData createdStorageData = createdStorage.Data; + Assert.IsTrue(createdStorageData.Type == "objects"); + } + + [TestMethod] + public async Task TestGetFolderAsync() + { + Folder folder = await _dataManagementApi.GetFolderAsync(projectId: projectId, folderId: folderId, accessToken: token); + FolderData folderData = folder.Data; + Assert.IsTrue(folderId == folderData.Id); + } + + [TestMethod] + public async Task TestGetFolderContentsAsync() + { + FolderContents folderContents = await _dataManagementApi.GetFolderContentsAsync(projectId: projectId, folderId: folderId, accessToken: token); + Assert.IsTrue(folderContents.Data.Count > 0); + } + + [TestMethod] + public async Task TestGetFolderParentAsync() + { + Folder folder = await _dataManagementApi.GetFolderParentAsync(projectId: projectId, folderId: folderId, accessToken: token); + FolderData folderData = folder.Data; + Assert.IsTrue(folderData.Type == "folders"); + } + + [TestMethod] + public async Task TestGetFolderRefsAsync() + { + FolderRefs folderRefs = await _dataManagementApi.GetFolderRefsAsync(projectId: projectId, folderId: folderId, accessToken: token); + Assert.IsInstanceOfType(folderRefs.Data, typeof(List)); + } + + [TestMethod] + public async Task TestGetFolderRelationshipsLinksAsync() + { + RelationshipLinks relationshipLinks = await _dataManagementApi.GetFolderRelationshipsLinksAsync(projectId: projectId, folderId: folderId, accessToken: token); + Assert.IsInstanceOfType(relationshipLinks.Data, typeof(List)); + } + + [TestMethod] + public async Task TestGetFolderRelationshipsRefsAsync() + { + RelationshipRefs relationshipRefs = await _dataManagementApi.GetFolderRelationshipsRefsAsync(folderId: folderId, projectId: projectId, accessToken: token); + Assert.IsInstanceOfType(relationshipRefs.Data, typeof(List)); + } + + [TestMethod] + public async Task TestGetFolderSearchAsync() + { + Search search = await _dataManagementApi.GetFolderSearchAsync(folderId: folderId, projectId: projectId, accessToken: token); + Assert.IsTrue(search.Data.Count > 0); + } + + [TestMethod] + public async Task TestCreateFolderAsync() + { + CreateFolder createFolder = new CreateFolder(); + + createFolder.Jsonapi._Version = VersionNumber._10; + + CreateFolderData folderData = createFolder.Data; + folderData.Type = Type.Folders; + + CreateFolderDataAttributes attributes = folderData.Attributes; + attributes.Name = "folder"; + + CreateFolderDataAttributesExtension attributesExtension = attributes.Extension; + attributesExtension.Type = Type.FoldersautodeskCoreFolder; + attributesExtension._Version = VersionNumber._10; + + CreateFolderDataRelationships relationship = folderData.Relationships; + StorageRequestDataRelationshipsTarget target = relationship.Parent; + StorageRequestDataRelationshipsTargetData targetData = target.Data; + targetData.Type = Type.Folders; + targetData.Id = folderId; + + Folder folder = await _dataManagementApi.CreateFolderAsync(projectId: projectId, createFolder: createFolder, accessToken: token); + FolderData createdFolderData = folder.Data; + Assert.IsTrue(createdFolderData.Type == "folders"); + } + + [TestMethod] + public async Task TestCreateFolderRelationshipsRefAsync() + { + RelationshipRefsRequest relationshipRefsRequest = new RelationshipRefsRequest(); + + relationshipRefsRequest.Jsonapi._Version = VersionNumber._10; + + RelationshipRefsRequestData relData = relationshipRefsRequest.Data; + relData.Type = Type.Versions; + relData.Id = versionId; + + RelationshipRefsRequestDataMeta relDataMeta = relData.Meta; + RelationshipRefsRequestDataMetaExtension relDataExtension = relDataMeta.Extension; + relDataExtension.Type = "auxiliary:autodesk.core:Attachment"; + relDataExtension._Version = VersionNumber._10; + + HttpResponseMessage relationship = await _dataManagementApi.CreateFolderRelationshipsRefAsync(folderId: folderId, projectId: projectId, relationshipRefsRequest: relationshipRefsRequest, accessToken: token); + var statusCode = relationship.StatusCode; + string statusCodeString = statusCode.ToString(); + Assert.IsTrue(statusCodeString == "NoContent"); + } + + [TestMethod] + public async Task TestPatchFolderAsync() + { + ModifyFolder modifyFolder = new ModifyFolder(); + + modifyFolder.Jsonapi._Version = VersionNumber._10; + + ModifyFolderData modifyFolderData = modifyFolder.Data; + modifyFolderData.Type = Type.Folders; + modifyFolderData.Id = folderId; + + ModifyFolderDataAttributes attributes = modifyFolderData.Attributes; + attributes.Name = "Drawings"; + + Folder folder = await _dataManagementApi.PatchFolderAsync(projectId: projectId, folderId: folderId, modifyFolder: modifyFolder, accessToken: token); + FolderData folderData = folder.Data; + Assert.IsTrue(folderId == folderData.Id); + } + + [TestMethod] + public async Task TestGetItemAsync() + { + Item item = await _dataManagementApi.GetItemAsync(projectId: projectId, itemId: itemId, accessToken: token); + ItemData itemData = item.Data; + Assert.IsTrue(itemData.Type == "items"); + } + + [TestMethod] + public async Task TestGetItemParentFolderAsync() + { + Folder folder = await _dataManagementApi.GetItemParentFolderAsync(projectId: projectId, itemId: itemId, accessToken: token); + FolderData folderData = folder.Data; + Assert.IsTrue(folderData.Type == "folders"); + } + + [TestMethod] + public async Task TestGetItemRefsAsync() + { + Refs refs = await _dataManagementApi.GetItemRefsAsync(projectId: projectId, itemId: itemId, accessToken: token); + Assert.IsInstanceOfType(refs.Data, typeof(List)); + } + + [TestMethod] + public async Task TestGetItemRelationshipsLinksAsync() + { + RelationshipLinks relationshipLinks = await _dataManagementApi.GetItemRelationshipsLinksAsync(projectId: projectId, itemId: itemId, accessToken: token); + Assert.IsInstanceOfType(relationshipLinks.Data, typeof(List)); + } + + [TestMethod] + public async Task TestGetItemRelationshipsRefsAsync() + { + RelationshipRefs relationshipRefs = await _dataManagementApi.GetItemRelationshipsRefsAsync(projectId: projectId, itemId: itemId, accessToken: token); + Assert.IsInstanceOfType(relationshipRefs.Data, typeof(List)); + } + + [TestMethod] + public async Task TestGetItemTipAsync() + { + ItemTip itemTip = await _dataManagementApi.GetItemTipAsync(projectId: projectId, itemId: itemId, accessToken: token); + ItemTipData itemTipData = itemTip.Data; + Assert.IsTrue(itemTipData.Type == "versions"); + } + + // [TestMethod] + // public async Task TestGetItemVersionsAsync() + // { + // Versions versions = await _dataManagementApi.GetItemVersionsAsync(projectId: projectId, itemId: itemId, accessToken: token); + // Assert.IsInstanceOfType(versions.Data, typeof(List)); + // } + + [TestMethod] + public async Task TestCreateItemAsync() + { + CreateItem createItem = new CreateItem(); + + createItem.Jsonapi._Version = VersionNumber._10; + + CreateItemData createItemData = createItem.Data; + createItemData.Type = Type.Items; + + CreateItemDataAttributes attributes = createItemData.Attributes; + attributes.DisplayName = "drawing.dwg"; + + CreateItemDataAttributesExtension extension = attributes.Extension; + extension.Type = Type.ItemsautodeskCoreFile; + extension._Version = VersionNumber._10; + + CreateItemDataRelationships relationships = createItemData.Relationships; + StorageRequestDataRelationshipsTarget tip = relationships.Tip; + StorageRequestDataRelationshipsTargetData tipData = tip.Data; + tipData.Type = Type.Versions; + tipData.Id = "1"; + + StorageRequestDataRelationshipsTarget parent = relationships.Parent; + StorageRequestDataRelationshipsTargetData parentData = parent.Data; + parentData.Type = Type.Versions; + parentData.Id = "1"; + + List included = createItem.Included; + + foreach (var includedData in included) + { + includedData.Type = Type.Versions; + includedData.Id = "1"; + + CreateItemIncludedAttributes includedAttributes = includedData.Attributes; + includedAttributes.Name = "drawing.dwg"; + + CreateItemDataAttributesExtension includedExtension = includedAttributes.Extension; + includedExtension.Type = Type.VersionsautodeskCoreFile; + includedExtension._Version = VersionNumber._10; + } + + Item item = await _dataManagementApi.CreateItemAsync(projectId: projectId, createItem: createItem, accessToken: token); + ItemData itemData = item.Data; + Assert.IsTrue(itemData.Type == "items"); + } + + [TestMethod] + public async Task TestCreateItemRelationshipsRefAsync() + { + RelationshipRefsRequest relationshipRefsRequest = new RelationshipRefsRequest(); + + relationshipRefsRequest.Jsonapi._Version = VersionNumber._10; + + RelationshipRefsRequestData relationshipRefsRequestData = relationshipRefsRequest.Data; + relationshipRefsRequestData.Type = Type.Versions; + relationshipRefsRequestData.Id = "urn:adsk.wipprod:fs.file:vf.ooWjwAQJR0uEoPRyfEnvew?version=1"; + + RelationshipRefsRequestDataMeta meta = relationshipRefsRequestData.Meta; + RelationshipRefsRequestDataMetaExtension extension = meta.Extension; + extension.Type = "auxiliary:autodesk.core:Attachment"; + extension._Version = VersionNumber._10; + + HttpResponseMessage responseMessage = await _dataManagementApi.CreateItemRelationshipsRefAsync(projectId: projectId, itemId: itemId, relationshipRefsRequest: relationshipRefsRequest, accessToken: token); + var statusCode = responseMessage.StatusCode; + string statusCodeString = statusCode.ToString(); + Assert.IsTrue(statusCodeString == "NoContent"); + } + + [TestMethod] + public async Task TestPatchItemAsync() + { + ItemRequest itemRequest = new ItemRequest(); + + itemRequest.Jsonapi._Version = VersionNumber._10; + + ItemRequestData itemRequestData = itemRequest.Data; + itemRequestData.Type = Type.Items; + itemRequestData.Id = "urn:adsk.wipprod:dm.lineage:AeYgDtcTSuqYoyMweWFhhQ"; + + ItemRequestDataAttributes attributes = itemRequestData.Attributes; + attributes.DisplayName = "drawing.dwg"; + + Item item = await _dataManagementApi.PatchItemAsync(projectId: projectId, itemId: itemId, itemRequest: itemRequest, accessToken: token); + ItemData itemData = item.Data; + Assert.IsTrue(itemData.Type == "items"); + } + + [TestMethod] + public async Task TestGetVersionAsync() + { + ModelVersion modelVersion = await _dataManagementApi.GetVersionAsync(projectId: projectId, versionId: versionId, accessToken: token); + ItemTipData modelVersionData = modelVersion.Data; + Assert.IsTrue(modelVersionData.Type == "versions"); + } + + [TestMethod] + public async Task TestGetVersionDownloadFormatsAsync() + { + DownloadFormats downloadFormats = await _dataManagementApi.GetVersionDownloadFormatsAsync(projectId: projectId, versionId: versionId, accessToken: token); + DownloadFormatsData downloadFormatsData = downloadFormats.Data; + Assert.IsTrue(downloadFormatsData.Type == "downloadFormats"); + } + + [TestMethod] + public async Task TestGetVersionDownloadsAsync() + { + Downloads downloads = await _dataManagementApi.GetVersionDownloadsAsync(projectId: projectId, versionId: versionId, accessToken: token); + Assert.IsInstanceOfType(downloads.Data, typeof(List)); + } + + [TestMethod] + public async Task TestGetVersionItemAsync() + { + Item item = await _dataManagementApi.GetVersionItemAsync(projectId: projectId, versionId: versionId, accessToken: token); + ItemData itemData = item.Data; + Assert.IsTrue(itemData.Type == "items"); + } + + [TestMethod] + public async Task TestGetVersionRefsAsync() + { + Refs refs = await _dataManagementApi.GetVersionRefsAsync(projectId: projectId, versionId: versionId, accessToken: token); + Assert.IsInstanceOfType(refs.Data, typeof(List)); + } + + [TestMethod] + public async Task TestGetVersionRelationshipsLinksAsync() + { + RelationshipLinks relationshipLinks = await _dataManagementApi.GetVersionRelationshipsLinksAsync(projectId: projectId, versionId: versionId, accessToken: token); + Assert.IsInstanceOfType(relationshipLinks.Data, typeof(List)); + } + + [TestMethod] + public async Task TestGetVersionRelationshipsRefsAsync() + { + RelationshipRefs relationshipRefs = await _dataManagementApi.GetVersionRelationshipsRefsAsync(projectId: projectId, versionId: versionId, accessToken: token); + Assert.IsInstanceOfType(relationshipRefs.Data, typeof(List)); + } + + [TestMethod] + public async Task TestCreateVersionAsync() + { + CreateVersion createVersion = new CreateVersion(); + + createVersion.Jsonapi._Version = VersionNumber._10; + + CreateVersionData createVersionData = createVersion.Data; + createVersionData.Type = Type.Items; + + CreateVersionDataAttributes attributes = createVersionData.Attributes; + attributes.Name = "drawing.dwg"; + + CreateVersionDataAttributesExtension extension = attributes.Extension; + extension.Type = "versions:autodesk.core:File"; + extension._Version = "1.0"; + + CreateVersionDataRelationships relationships = createVersionData.Relationships; + StorageRequestDataRelationshipsTarget item = relationships.Item; + StorageRequestDataRelationshipsTargetData itemData = item.Data; + itemData.Type = Type.Items; + itemData.Id = "urn:adsk.wipprod:dm.lineage:AeYgDtcTSuqYoyMweWFhhQ"; + + StorageRequestDataRelationshipsTarget storage = relationships.Storage; + StorageRequestDataRelationshipsTargetData storageData = storage.Data; + storageData.Type = Type.Objects; + storageData.Id = "urn:adsk.objects:os.object:wip.dm.prod/980cff2c-f0f8-43d9-a151-4a2d916b91a2.dwg"; + + CreatedVersion createdVersion = await _dataManagementApi.CreateVersionAsync(projectId: projectId, createVersion: createVersion, accessToken: token); + CreatedVersionData createdVersionData = createdVersion.Data; + Assert.IsTrue(createdVersionData.Type == "versions"); + } + + [TestMethod] + public async Task TestCreateVersionRelationshipsRefAsync() + { + RelationshipRefsRequest relationshipRefsRequest = new RelationshipRefsRequest(); + + relationshipRefsRequest.Jsonapi._Version = VersionNumber._10; + + RelationshipRefsRequestData relationshipRefsRequestData = relationshipRefsRequest.Data; + relationshipRefsRequestData.Type = Type.Versions; + relationshipRefsRequestData.Id = "urn:adsk.wipprod:fs.file:vf.ooWjwAQJR0uEoPRyfEnvew?version=1"; + + RelationshipRefsRequestDataMeta meta = relationshipRefsRequestData.Meta; + RelationshipRefsRequestDataMetaExtension extension = meta.Extension; + extension.Type = "auxiliary:autodesk.core:Attachment"; + extension._Version = VersionNumber._10; + + HttpResponseMessage responseMessage = await _dataManagementApi.CreateVersionRelationshipsRefAsync(projectId: projectId, versionId: versionId, relationshipRefsRequest: relationshipRefsRequest, accessToken: token); + var statusCode = responseMessage.StatusCode; + string statusCodeString = statusCode.ToString(); + Assert.IsTrue(statusCodeString == "NoContent"); + } + + [TestMethod] + public async Task TestPatchVersionAsync() + { + VersionRequest versionRequest = new VersionRequest(); + + versionRequest.Jsonapi._Version = VersionNumber._10; + + VersionRequestData versionRequestData = versionRequest.Data; + versionRequestData.Type = Type.Items; + versionRequestData.Id = "urn:adsk.wipprod:fs.file:vf.ooWjwAQJR0uEoPRyfEnvew?version=1"; + + VersionRequestDataAttributes attributes = versionRequestData.Attributes; + attributes.Name = "new name for drawing.dwg"; + + ModelVersion modelVersion = await _dataManagementApi.PatchVersionAsync(projectId: projectId, versionId: versionId, versionRequest: versionRequest, accessToken: token); + ItemTipData modelVersionData = modelVersion.Data; + Assert.IsTrue(modelVersionData.Type == "versions"); + } + + } diff --git a/sdk-manager-dotnet/Autodesk.Sdk.Manager.csproj b/sdk-manager/Autodesk.Sdk.Manager.csproj similarity index 100% rename from sdk-manager-dotnet/Autodesk.Sdk.Manager.csproj rename to sdk-manager/Autodesk.Sdk.Manager.csproj diff --git a/sdk-manager-dotnet/README.md b/sdk-manager/README.md similarity index 100% rename from sdk-manager-dotnet/README.md rename to sdk-manager/README.md diff --git a/sdk-manager-dotnet/src/APSClient.cs b/sdk-manager/src/APSClient.cs similarity index 100% rename from sdk-manager-dotnet/src/APSClient.cs rename to sdk-manager/src/APSClient.cs diff --git a/sdk-manager-dotnet/src/APSConfiguration.cs b/sdk-manager/src/APSConfiguration.cs similarity index 100% rename from sdk-manager-dotnet/src/APSConfiguration.cs rename to sdk-manager/src/APSConfiguration.cs diff --git a/sdk-manager-dotnet/src/AuthClient.cs b/sdk-manager/src/AuthClient.cs similarity index 100% rename from sdk-manager-dotnet/src/AuthClient.cs rename to sdk-manager/src/AuthClient.cs diff --git a/sdk-manager-dotnet/src/AuthClientConfiguration.cs b/sdk-manager/src/AuthClientConfiguration.cs similarity index 100% rename from sdk-manager-dotnet/src/AuthClientConfiguration.cs rename to sdk-manager/src/AuthClientConfiguration.cs diff --git a/sdk-manager-dotnet/src/IAPSClient.cs b/sdk-manager/src/IAPSClient.cs similarity index 100% rename from sdk-manager-dotnet/src/IAPSClient.cs rename to sdk-manager/src/IAPSClient.cs diff --git a/sdk-manager-dotnet/src/IAPSConfiguration.cs b/sdk-manager/src/IAPSConfiguration.cs similarity index 100% rename from sdk-manager-dotnet/src/IAPSConfiguration.cs rename to sdk-manager/src/IAPSConfiguration.cs diff --git a/sdk-manager-dotnet/src/IAuthClient.cs b/sdk-manager/src/IAuthClient.cs similarity index 100% rename from sdk-manager-dotnet/src/IAuthClient.cs rename to sdk-manager/src/IAuthClient.cs diff --git a/sdk-manager-dotnet/src/IAuthClientConfiguration.cs b/sdk-manager/src/IAuthClientConfiguration.cs similarity index 100% rename from sdk-manager-dotnet/src/IAuthClientConfiguration.cs rename to sdk-manager/src/IAuthClientConfiguration.cs diff --git a/sdk-manager-dotnet/src/IBuilder.cs b/sdk-manager/src/IBuilder.cs similarity index 100% rename from sdk-manager-dotnet/src/IBuilder.cs rename to sdk-manager/src/IBuilder.cs diff --git a/sdk-manager-dotnet/src/IResiliencyConfiguration.cs b/sdk-manager/src/IResiliencyConfiguration.cs similarity index 100% rename from sdk-manager-dotnet/src/IResiliencyConfiguration.cs rename to sdk-manager/src/IResiliencyConfiguration.cs diff --git a/sdk-manager-dotnet/src/ISDKManager.cs b/sdk-manager/src/ISDKManager.cs similarity index 100% rename from sdk-manager-dotnet/src/ISDKManager.cs rename to sdk-manager/src/ISDKManager.cs diff --git a/sdk-manager-dotnet/src/ResiliencyConfiguration.cs b/sdk-manager/src/ResiliencyConfiguration.cs similarity index 100% rename from sdk-manager-dotnet/src/ResiliencyConfiguration.cs rename to sdk-manager/src/ResiliencyConfiguration.cs diff --git a/sdk-manager-dotnet/src/SDKManager.cs b/sdk-manager/src/SDKManager.cs similarity index 100% rename from sdk-manager-dotnet/src/SDKManager.cs rename to sdk-manager/src/SDKManager.cs diff --git a/sdk-manager-dotnet/src/SDKManagerBuilder.cs b/sdk-manager/src/SDKManagerBuilder.cs similarity index 100% rename from sdk-manager-dotnet/src/SDKManagerBuilder.cs rename to sdk-manager/src/SDKManagerBuilder.cs diff --git a/webhooks/test/TestWebhooks.cs b/webhooks/test/TestWebhooks.cs index d7883b3..e8a709c 100644 --- a/webhooks/test/TestWebhooks.cs +++ b/webhooks/test/TestWebhooks.cs @@ -13,9 +13,10 @@ public class TestWebhooks { private static WebhooksClient _webhooksApi = null!; - string token = Environment.GetEnvironmentVariable("ACCESS_TOKEN") ?? "Access token not found"; - string callbackUrl = Environment.GetEnvironmentVariable("CALLBACK_URL") ?? "Callback Url not found"; - string workFlowId = Environment.GetEnvironmentVariable("WORKFLOW_ID") ?? "Workflow id not found"; + string token = Environment.GetEnvironmentVariable("ACCESS_TOKEN"); + string callbackUrl = Environment.GetEnvironmentVariable("CALLBACK_URL"); + string workFlowId = Environment.GetEnvironmentVariable("WORKFLOW_ID"); + string hookId = Environment.GetEnvironmentVariable("HOOK_ID"); [ClassInitialize] public static void ClassInitialize(TestContext testContext) @@ -29,25 +30,138 @@ public static void ClassInitialize(TestContext testContext) _webhooksApi = new WebhooksClient(sdkManager); } + //Get details of a webhook based on its webhook ID + [TestMethod] + public async Task TestGetHookDetailsAsync() + { + HookDetailsResult getSystemEventHook = await _webhooksApi.GetHookDetailsAsync(system: Systems.Data, _event: Events.DmVersionAdded, hookId: hookId, accessToken: token); + + var HookId = getSystemEventHook.HookId; + Assert.IsTrue(HookId == hookId); + } + + //Retrieves a paginated list of all the webhooks for a specified event. If the pageState query string is not specified, the first page is returned. + [TestMethod] + public async Task TestGetSystemEventHooksAsync() + { + HooksResult getSystemEventHooks = await _webhooksApi.GetSystemEventHooksAsync(system: Systems.Data, _event: Events.DmVersionAdded, accessToken: token); + Assert.IsTrue(getSystemEventHooks.Data.Count > 0); + } + + //Retrieves a paginated list of all the webhooks for a specified system. If the pageState query string is not specified, the first page is returned. + [TestMethod] + public async Task TestGetSystemHooksAsync() + { + HooksResult getSystemHooks = await _webhooksApi.GetSystemHooksAsync(system: Systems.Data, accessToken: token); + Assert.IsTrue(getSystemHooks.Data.Count > 0); + } + + //Retrieves a paginated list of all the webhooks. If the pageState query string is not specified, the first page is returned. [TestMethod] public async Task TestGetHooksAsync() { - HooksResult getHooksResponse = await _webhooksApi.GetHooksAsync(accessToken: token); - Assert.IsTrue(getHooksResponse.Data.Count > 0); + HooksResult getHooks = await _webhooksApi.GetHooksAsync(accessToken: token); + Assert.IsTrue(getHooks.Data.Count > 0); } + //Retrieves a paginated list of webhooks created in the context of a Client or Application. This API accepts 2-legged token of the application only. If the pageState query string is not specified, the first page is returned. [TestMethod] - public async Task TestCreateHookAsync() + public async Task TestGetAppHooksAsync() { - HookPayload createSpecifiedEventHook = new HookPayload(); - createSpecifiedEventHook.CallbackUrl = callbackUrl; - createSpecifiedEventHook.Scope = createSpecifiedEventHook.Scope.SetScope(Scopes.Workflow, workFlowId); + HooksResult getAppHooks = await _webhooksApi.GetAppHooksAsync(accessToken: token); + Assert.IsTrue(getAppHooks.Data.Count > 0); + } - HttpResponseMessage createSpecifiedEventHookResponse = await _webhooksApi.CreateSystemEventHookAsync(system: Systems.Derivative, _event: Events.ExtractionFinished, hookPayload: createSpecifiedEventHook, accessToken: token); - var statusCode = createSpecifiedEventHookResponse.StatusCode; + //Add new webhook to receive the notification on a specified event. + [TestMethod] + public async Task TestCreateSystemEventHookAsync() + { + HookPayload createSystemEventHook = new HookPayload(); + createSystemEventHook.CallbackUrl = callbackUrl; + createSystemEventHook.Scope = createSystemEventHook.Scope.SetScope(Scopes.Workflow, workFlowId); + + HttpResponseMessage createSystemEventHookResponse = await _webhooksApi.CreateSystemEventHookAsync(system: Systems.Derivative, _event: Events.ExtractionFinished, hookPayload: createSystemEventHook, accessToken: token); + var statusCode = createSystemEventHookResponse.StatusCode; string statusCodeString = statusCode.ToString(); Assert.IsTrue(statusCodeString == "Created"); } + //Add new webhooks to receive the notification on all the events. + [TestMethod] + public async Task TestCreateSystemHookAsync() + { + HookPayload createSystemHook = new HookPayload(); + createSystemHook.CallbackUrl = callbackUrl; + createSystemHook.Scope = createSystemHook.Scope.SetScope(Scopes.Workflow, workFlowId); + + HookCreationResult createSystemHookResponse = await _webhooksApi.CreateSystemHookAsync(system: Systems.Derivative, hookPayload: createSystemHook, accessToken: token); + Assert.IsTrue(createSystemHookResponse.Hooks.Count > 0); + } + + //Partially update a webhook based on its webhook ID. The only fields that may be updated are: status, filter, hookAttribute, and hookExpiry. + [TestMethod] + public async Task TestPatchSystemEventHookAsync() + { + ModifyHookPayload updateHook = new ModifyHookPayload(); + updateHook.Status = "inactive"; + + // Successful deactivation of a webhook: + HttpResponseMessage updateHookResponse = await _webhooksApi.PatchSystemEventHookAsync(system: Systems.Data, _event: Events.DmVersionAdded, hookId: hookId, modifyHookPayload: updateHook, accessToken: token); + var statusCode = updateHookResponse.StatusCode; + string statusCodeString = statusCode.ToString(); + Assert.IsTrue(statusCodeString == "NoContent"); + } + + //Deletes a webhook based on webhook ID + [TestMethod] + public async Task TestDeleteSystemEventHookAsync() + { + HttpResponseMessage deleteHook = await _webhooksApi.DeleteSystemEventHookAsync(system: Systems.Data, _event: Events.DmVersionAdded, hookId: hookId, accessToken: token); + + var statusCode = deleteHook.StatusCode; + string statusCodeString = statusCode.ToString(); + Assert.IsTrue(statusCodeString == "NoContent"); + } + + + //Add a new Webhook secret token + [TestMethod] + public async Task TestCreateTokenAsync() + { // create request body + TokenPayload createToken = new TokenPayload(); + createToken.Token = "awffbvdb3trf4fvdfbUyt39suHnbe5Mnrks8"; + + // Add a new Webhook secret token + TokenCreationResult createTokenResponse = await _webhooksApi.CreateTokenAsync(tokenPayload: createToken, accessToken: token); + Assert.IsTrue(createTokenResponse.Status == 200); + } + + + + //Update an existing Webhook secret token. Please note that the update can take up to 10 mins before being applied depending on the latest event delivery attempt which may still utilize the previous secret token. We recommend your callback accept both secret token values for a period of time to allow all requests to go through. + [TestMethod] + public async Task TestPutTokenAsync() + { + TokenPayload createToken = new TokenPayload(); + createToken.Token = "awffbvdb3trf4fvdfbUyt39suHnbe5Mnrks8"; + + HttpResponseMessage updateTokenResponse = await _webhooksApi.PutTokenAsync(tokenPayload: createToken, accessToken: token); + var statusCode = updateTokenResponse.StatusCode; + string statusCodeString = statusCode.ToString(); + Assert.IsTrue(statusCodeString == "NoContent"); + } + + + + //Delete a Webhook secret token. Please note that the secret token can still be available for up to 10 mins depending on the latest event delivery attempt. + [TestMethod] + public async Task TestDeleteTokenAsync() + { + HttpResponseMessage deleteTokenResponse = await _webhooksApi.DeleteTokenAsync(accessToken: token); + var statusCode = deleteTokenResponse.StatusCode; + string statusCodeString = statusCode.ToString(); + Assert.IsTrue(statusCodeString == "NoContent"); + } + }