From 9e00052585f124e93c2651036ba01e01a6f302ad Mon Sep 17 00:00:00 2001 From: raj pandey Date: Tue, 27 May 2025 22:39:40 +0530 Subject: [PATCH 1/7] Fixed the GetDelivery token and added unit test cases --- .../Models/DeliveryTokenTest.cs | 133 ++++++++++++++++++ .../Models/Token/DeliveryToken.cs | 6 +- 2 files changed, 137 insertions(+), 2 deletions(-) create mode 100644 Contentstack.Management.Core.Unit.Tests/Models/DeliveryTokenTest.cs diff --git a/Contentstack.Management.Core.Unit.Tests/Models/DeliveryTokenTest.cs b/Contentstack.Management.Core.Unit.Tests/Models/DeliveryTokenTest.cs new file mode 100644 index 0000000..40dd87c --- /dev/null +++ b/Contentstack.Management.Core.Unit.Tests/Models/DeliveryTokenTest.cs @@ -0,0 +1,133 @@ +using System; +using System.Threading.Tasks; +using AutoFixture; +using Contentstack.Management.Core.Models; +using Contentstack.Management.Core.Models.Token; +using Contentstack.Management.Core.Queryable; +using Contentstack.Management.Core.Unit.Tests.Mokes; +using Microsoft.VisualStudio.TestTools.UnitTesting; + +namespace Contentstack.Management.Core.Unit.Tests.Models +{ + [TestClass] + public class DeliveryTokenTest + { + private Stack _stack; + private readonly IFixture _fixture = new Fixture(); + private ContentstackResponse _contentstackResponse; + + [TestInitialize] + public void initialize() + { + var client = new ContentstackClient(); + _contentstackResponse = MockResponse.CreateContentstackResponse("MockResponse.txt"); + client.ContentstackPipeline.ReplaceHandler(new MockHttpHandler(_contentstackResponse)); + client.contentstackOptions.Authtoken = _fixture.Create(); + _stack = new Stack(client, _fixture.Create()); + } + + [TestMethod] + public void Initialize_DeliveryToken() + { + DeliveryToken token = new DeliveryToken(_stack); + Assert.IsNull(token.Uid); + Assert.AreEqual("stacks/delivery_tokens", token.resourcePath); + Assert.ThrowsException(() => token.Fetch()); + Assert.ThrowsExceptionAsync(() => token.FetchAsync()); + Assert.ThrowsException(() => token.Update(_fixture.Create())); + Assert.ThrowsExceptionAsync(() => token.UpdateAsync(_fixture.Create())); + Assert.ThrowsException(() => token.Delete()); + Assert.ThrowsExceptionAsync(() => token.DeleteAsync()); + Assert.AreEqual(token.Query().GetType(), typeof(Query)); + } + + [TestMethod] + public void Initialize_DeliveryToken_With_Uid() + { + string uid = _fixture.Create(); + DeliveryToken token = new DeliveryToken(_stack, uid); + Assert.AreEqual(uid, token.Uid); + Assert.AreEqual($"stacks/delivery_tokens/{uid}", token.resourcePath); + } + + [TestMethod] + public void Should_Create_DeliveryToken() + { + ContentstackResponse response = _stack.DeliveryToken().Create(_fixture.Create()); + Assert.AreEqual(_contentstackResponse.OpenResponse(), response.OpenResponse()); + Assert.AreEqual(_contentstackResponse.OpenJObjectResponse().ToString(), response.OpenJObjectResponse().ToString()); + } + + [TestMethod] + public async Task Should_Create_DeliveryToken_Async() + { + ContentstackResponse response = await _stack.DeliveryToken().CreateAsync(_fixture.Create()); + Assert.AreEqual(_contentstackResponse.OpenResponse(), response.OpenResponse()); + Assert.AreEqual(_contentstackResponse.OpenJObjectResponse().ToString(), response.OpenJObjectResponse().ToString()); + } + + [TestMethod] + public void Should_Query_DeliveryToken() + { + ContentstackResponse response = _stack.DeliveryToken().Query().Find(); + Assert.AreEqual(_contentstackResponse.OpenResponse(), response.OpenResponse()); + Assert.AreEqual(_contentstackResponse.OpenJObjectResponse().ToString(), response.OpenJObjectResponse().ToString()); + } + + [TestMethod] + public async Task Should_Query_DeliveryToken_Async() + { + ContentstackResponse response = await _stack.DeliveryToken().Query().FindAsync(); + Assert.AreEqual(_contentstackResponse.OpenResponse(), response.OpenResponse()); + Assert.AreEqual(_contentstackResponse.OpenJObjectResponse().ToString(), response.OpenJObjectResponse().ToString()); + } + + [TestMethod] + public void Should_Fetch_DeliveryToken() + { + ContentstackResponse response = _stack.DeliveryToken(_fixture.Create()).Fetch(); + Assert.AreEqual(_contentstackResponse.OpenResponse(), response.OpenResponse()); + Assert.AreEqual(_contentstackResponse.OpenJObjectResponse().ToString(), response.OpenJObjectResponse().ToString()); + } + + [TestMethod] + public async Task Should_Fetch_DeliveryToken_Async() + { + ContentstackResponse response = await _stack.DeliveryToken(_fixture.Create()).FetchAsync(); + Assert.AreEqual(_contentstackResponse.OpenResponse(), response.OpenResponse()); + Assert.AreEqual(_contentstackResponse.OpenJObjectResponse().ToString(), response.OpenJObjectResponse().ToString()); + } + + [TestMethod] + public void Should_Update_DeliveryToken() + { + ContentstackResponse response = _stack.DeliveryToken(_fixture.Create()).Update(_fixture.Create()); + Assert.AreEqual(_contentstackResponse.OpenResponse(), response.OpenResponse()); + Assert.AreEqual(_contentstackResponse.OpenJObjectResponse().ToString(), response.OpenJObjectResponse().ToString()); + } + + [TestMethod] + public async Task Should_Update_DeliveryToken_Async() + { + ContentstackResponse response = await _stack.DeliveryToken(_fixture.Create()).UpdateAsync(_fixture.Create()); + Assert.AreEqual(_contentstackResponse.OpenResponse(), response.OpenResponse()); + Assert.AreEqual(_contentstackResponse.OpenJObjectResponse().ToString(), response.OpenJObjectResponse().ToString()); + } + + [TestMethod] + public void Should_Delete_DeliveryToken() + { + ContentstackResponse response = _stack.DeliveryToken(_fixture.Create()).Delete(); + Assert.AreEqual(_contentstackResponse.OpenResponse(), response.OpenResponse()); + Assert.AreEqual(_contentstackResponse.OpenJObjectResponse().ToString(), response.OpenJObjectResponse().ToString()); + } + + [TestMethod] + public async Task Should_Delete_DeliveryToken_Async() + { + ContentstackResponse response = await _stack.DeliveryToken(_fixture.Create()).DeleteAsync(); + Assert.AreEqual(_contentstackResponse.OpenResponse(), response.OpenResponse()); + Assert.AreEqual(_contentstackResponse.OpenJObjectResponse().ToString(), response.OpenJObjectResponse().ToString()); + } + } +} diff --git a/Contentstack.Management.Core/Models/Token/DeliveryToken.cs b/Contentstack.Management.Core/Models/Token/DeliveryToken.cs index cd6ab1d..8bb9bbd 100644 --- a/Contentstack.Management.Core/Models/Token/DeliveryToken.cs +++ b/Contentstack.Management.Core/Models/Token/DeliveryToken.cs @@ -1,5 +1,7 @@ -using System.Threading.Tasks; +using System; +using System.Threading.Tasks; using Contentstack.Management.Core.Queryable; +using Newtonsoft.Json.Linq; namespace Contentstack.Management.Core.Models.Token { @@ -8,7 +10,7 @@ public class DeliveryToken : BaseModel internal DeliveryToken(Stack stack, string uid = null) : base(stack, "token", uid) { - resourcePath = uid == null ? "/delivery_tokens" : $"/delivery_tokens/{uid}"; + resourcePath = uid == null ? "stacks/delivery_tokens" : $"stacks/delivery_tokens/{uid}"; } /// From da83285d06c6d8ea3a4dbaeca52aa4383b17847c Mon Sep 17 00:00:00 2001 From: raj pandey Date: Tue, 27 May 2025 22:51:25 +0530 Subject: [PATCH 2/7] branch update --- .github/workflows/check-branch.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/check-branch.yml b/.github/workflows/check-branch.yml index 0690dbc..12bae82 100644 --- a/.github/workflows/check-branch.yml +++ b/.github/workflows/check-branch.yml @@ -8,13 +8,13 @@ jobs: runs-on: ubuntu-latest steps: - name: Comment PR - if: github.base_ref == 'main' && github.head_ref != 'next' + if: github.base_ref == 'main' && github.head_ref != 'development' uses: thollander/actions-comment-pull-request@v2 with: message: | We regret to inform you that you are currently not able to merge your changes into the master branch due to restrictions applied by our SRE team. To proceed with merging your changes, we kindly request that you create a pull request from the next branch. Our team will then review the changes and work with you to ensure a successful merge into the master branch. - name: Check branch - if: github.base_ref == 'main' && github.head_ref != 'next' + if: github.base_ref == 'main' && github.head_ref != 'development' run: | echo "ERROR: We regret to inform you that you are currently not able to merge your changes into the master branch due to restrictions applied by our SRE team. To proceed with merging your changes, we kindly request that you create a pull request from the next branch. Our team will then review the changes and work with you to ensure a successful merge into the master branch." exit 1 From 737f3c1f20bf9988ae3828b3de0dd25c9cd9e962 Mon Sep 17 00:00:00 2001 From: raj pandey Date: Wed, 28 May 2025 13:52:56 +0530 Subject: [PATCH 3/7] Fixed Version --- .../contentstack.management.aspnetcore.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Contentstack.Management.ASPNETCore/contentstack.management.aspnetcore.csproj b/Contentstack.Management.ASPNETCore/contentstack.management.aspnetcore.csproj index 49a3a1f..2887b29 100644 --- a/Contentstack.Management.ASPNETCore/contentstack.management.aspnetcore.csproj +++ b/Contentstack.Management.ASPNETCore/contentstack.management.aspnetcore.csproj @@ -28,7 +28,7 @@ - + From 99984573ac67beadaf1a8d7aa5f13212b19b8dfe Mon Sep 17 00:00:00 2001 From: raj pandey Date: Wed, 28 May 2025 14:42:12 +0530 Subject: [PATCH 4/7] License update --- .../contentstack.management.aspnetcore.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Contentstack.Management.ASPNETCore/contentstack.management.aspnetcore.csproj b/Contentstack.Management.ASPNETCore/contentstack.management.aspnetcore.csproj index 2887b29..42ff9cf 100644 --- a/Contentstack.Management.ASPNETCore/contentstack.management.aspnetcore.csproj +++ b/Contentstack.Management.ASPNETCore/contentstack.management.aspnetcore.csproj @@ -5,7 +5,7 @@ contentstack.management.aspnetcore $(Version) Contentstack - Copyright © 2012-2024 Contentstack. All Rights Reserved + Copyright © 2012-2025 Contentstack. All Rights Reserved Contentstack https://github.com/contentstack/contentstack-management-dotnet Initial Release From aef96af9fb1c15280fa978fada6f3ab18dc194e5 Mon Sep 17 00:00:00 2001 From: raj pandey Date: Wed, 28 May 2025 14:43:21 +0530 Subject: [PATCH 5/7] update --- .github/workflows/check-branch.yml | 4 ++-- .../contentstack.management.aspnetcore.csproj | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/check-branch.yml b/.github/workflows/check-branch.yml index 12bae82..00a6a8a 100644 --- a/.github/workflows/check-branch.yml +++ b/.github/workflows/check-branch.yml @@ -8,13 +8,13 @@ jobs: runs-on: ubuntu-latest steps: - name: Comment PR - if: github.base_ref == 'main' && github.head_ref != 'development' + if: github.base_ref == 'main' && github.head_ref != 'staging' uses: thollander/actions-comment-pull-request@v2 with: message: | We regret to inform you that you are currently not able to merge your changes into the master branch due to restrictions applied by our SRE team. To proceed with merging your changes, we kindly request that you create a pull request from the next branch. Our team will then review the changes and work with you to ensure a successful merge into the master branch. - name: Check branch - if: github.base_ref == 'main' && github.head_ref != 'development' + if: github.base_ref == 'main' && github.head_ref != 'staging' run: | echo "ERROR: We regret to inform you that you are currently not able to merge your changes into the master branch due to restrictions applied by our SRE team. To proceed with merging your changes, we kindly request that you create a pull request from the next branch. Our team will then review the changes and work with you to ensure a successful merge into the master branch." exit 1 diff --git a/Contentstack.Management.ASPNETCore/contentstack.management.aspnetcore.csproj b/Contentstack.Management.ASPNETCore/contentstack.management.aspnetcore.csproj index 42ff9cf..5458abb 100644 --- a/Contentstack.Management.ASPNETCore/contentstack.management.aspnetcore.csproj +++ b/Contentstack.Management.ASPNETCore/contentstack.management.aspnetcore.csproj @@ -15,7 +15,7 @@ .NET SDK for the Contentstack Content Management API. LICENSE.txt v$(Version) - 0.1.3 + $(Version) Contentstack.Management.ASPNETCore From b9321c2a3cdbbd89a4ade25ebc197bd52c424cb2 Mon Sep 17 00:00:00 2001 From: raj pandey Date: Wed, 28 May 2025 15:16:33 +0530 Subject: [PATCH 6/7] Version bump --- CHANGELOG.md | 4 ++++ Contentstack.Management.Core/ContentstackClient.cs | 2 +- Directory.Build.props | 2 +- 3 files changed, 6 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 72557e9..9b320ad 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # Changelog +## [v0.1.12](https://github.com/contentstack/contentstack-management-dotnet/tree/v0.1.12) + - Fix + - Fixed the delivery token url + ## [v0.1.11](https://github.com/contentstack/contentstack-management-dotnet/tree/v0.1.11) - Feat - Add support for custom Http client and IHttpClientFactory diff --git a/Contentstack.Management.Core/ContentstackClient.cs b/Contentstack.Management.Core/ContentstackClient.cs index 5e4bb42..474d060 100644 --- a/Contentstack.Management.Core/ContentstackClient.cs +++ b/Contentstack.Management.Core/ContentstackClient.cs @@ -35,7 +35,7 @@ public class ContentstackClient : IContentstackClient private HttpClient _httpClient; private bool _disposed = false; - private string Version => "0.1.11"; + private string Version => "0.1.12"; private string xUserAgent => $"contentstack-management-dotnet/{Version}"; #endregion diff --git a/Directory.Build.props b/Directory.Build.props index b5e0738..e346ee5 100644 --- a/Directory.Build.props +++ b/Directory.Build.props @@ -1,5 +1,5 @@ - 0.1.11 + 0.1.12 From 4c719220d9256eeda87a59e9b79257dc162f54f6 Mon Sep 17 00:00:00 2001 From: raj pandey Date: Thu, 29 May 2025 11:29:24 +0530 Subject: [PATCH 7/7] License updated --- Contentstack.Management.ASPNETCore/LICENSE.txt | 2 +- Contentstack.Management.Core/LICENSE.txt | 2 +- .../contentstack.management.core.csproj | 2 +- Scripts/run-test-case.sh | 2 +- Scripts/run-unit-test-case.sh | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/Contentstack.Management.ASPNETCore/LICENSE.txt b/Contentstack.Management.ASPNETCore/LICENSE.txt index 3333caa..501f936 100644 --- a/Contentstack.Management.ASPNETCore/LICENSE.txt +++ b/Contentstack.Management.ASPNETCore/LICENSE.txt @@ -1,6 +1,6 @@ MIT License -Copyright © 2012-2024 Contentstack. All Rights Reserved +Copyright © 2012-2025 Contentstack. All Rights Reserved Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/Contentstack.Management.Core/LICENSE.txt b/Contentstack.Management.Core/LICENSE.txt index 3333caa..501f936 100644 --- a/Contentstack.Management.Core/LICENSE.txt +++ b/Contentstack.Management.Core/LICENSE.txt @@ -1,6 +1,6 @@ MIT License -Copyright © 2012-2024 Contentstack. All Rights Reserved +Copyright © 2012-2025 Contentstack. All Rights Reserved Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/Contentstack.Management.Core/contentstack.management.core.csproj b/Contentstack.Management.Core/contentstack.management.core.csproj index 94b1097..828e971 100644 --- a/Contentstack.Management.Core/contentstack.management.core.csproj +++ b/Contentstack.Management.Core/contentstack.management.core.csproj @@ -4,7 +4,7 @@ netstandard2.0;net471;net472; Contentstack Management Contentstack - Copyright © 2012-2024 Contentstack. All Rights Reserved + Copyright © 2012-2025 Contentstack. All Rights Reserved .NET SDK for the Contentstack Content Management API. Contentstack contentstack.management.csharp diff --git a/Scripts/run-test-case.sh b/Scripts/run-test-case.sh index 871d404..7550df9 100644 --- a/Scripts/run-test-case.sh +++ b/Scripts/run-test-case.sh @@ -4,7 +4,7 @@ # Contentstack # # Created by Uttam Ukkoji on 12/04/21. -# Copyright © 2024 Contentstack. All rights reserved. +# Copyright © 2025 Contentstack. All rights reserved. echo "Removing files" diff --git a/Scripts/run-unit-test-case.sh b/Scripts/run-unit-test-case.sh index d1f34fd..ff14bdc 100644 --- a/Scripts/run-unit-test-case.sh +++ b/Scripts/run-unit-test-case.sh @@ -4,7 +4,7 @@ # Contentstack # # Created by Uttam Ukkoji on 30/03/2023. -# Copyright © 2024 Contentstack. All rights reserved. +# Copyright © 2025 Contentstack. All rights reserved. echo "Removing files" rm -rf "./Contentstack.Management.Core.Unit.Tests/TestResults"