Skip to content

Commit 3e67bfd

Browse files
authored
Merge pull request #71 from contentstack/fix/DX-3057
Fixed the GetDelivery token and added unit test cases
2 parents 428d11d + 68ec307 commit 3e67bfd

File tree

9 files changed

+147
-12
lines changed

9 files changed

+147
-12
lines changed

.github/workflows/check-branch.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,13 @@ jobs:
88
runs-on: ubuntu-latest
99
steps:
1010
- name: Comment PR
11-
if: github.base_ref == 'main' && github.head_ref != 'next'
11+
if: github.base_ref == 'main' && github.head_ref != 'staging'
1212
uses: thollander/actions-comment-pull-request@v2
1313
with:
1414
message: |
1515
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.
1616
- name: Check branch
17-
if: github.base_ref == 'main' && github.head_ref != 'next'
17+
if: github.base_ref == 'main' && github.head_ref != 'staging'
1818
run: |
1919
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."
2020
exit 1

Contentstack.Management.ASPNETCore/LICENSE.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
MIT License
22

3-
Copyright © 2012-2024 Contentstack. All Rights Reserved
3+
Copyright © 2012-2025 Contentstack. All Rights Reserved
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal

Contentstack.Management.ASPNETCore/contentstack.management.aspnetcore.csproj

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<PackageId>contentstack.management.aspnetcore</PackageId>
66
<PackageVersion>$(Version)</PackageVersion>
77
<Authors>Contentstack</Authors>
8-
<Copyright>Copyright © 2012-2024 Contentstack. All Rights Reserved</Copyright>
8+
<Copyright>Copyright © 2012-2025 Contentstack. All Rights Reserved</Copyright>
99
<Owners>Contentstack </Owners>
1010
<PackageProjectUrl>https://github.com/contentstack/contentstack-management-dotnet</PackageProjectUrl>
1111
<PackageReleaseNotes>Initial Release</PackageReleaseNotes>
@@ -15,7 +15,7 @@
1515
<Description>.NET SDK for the Contentstack Content Management API.</Description>
1616
<PackageLicenseFile>LICENSE.txt</PackageLicenseFile>
1717
<PackageTags>v$(Version)</PackageTags>
18-
<ReleaseVersion>0.1.3</ReleaseVersion>
18+
<ReleaseVersion>$(Version)</ReleaseVersion>
1919
<RootNamespace>Contentstack.Management.ASPNETCore</RootNamespace>
2020
</PropertyGroup>
2121

@@ -28,7 +28,7 @@
2828
<ItemGroup>
2929
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="9.0.1" />
3030
<PackageReference Include="Microsoft.Extensions.Options.ConfigurationExtensions" Version="9.0.1" />
31-
<PackageReference Include="contentstack.management.csharp" Version="0.1.11" />
31+
<PackageReference Include="contentstack.management.csharp" Version="0.1.10" />
3232
<PackageReference Include="Microsoft.Extensions.Http" Version="9.0.1" />
3333
</ItemGroup>
3434
</Project>
Lines changed: 133 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,133 @@
1+
using System;
2+
using System.Threading.Tasks;
3+
using AutoFixture;
4+
using Contentstack.Management.Core.Models;
5+
using Contentstack.Management.Core.Models.Token;
6+
using Contentstack.Management.Core.Queryable;
7+
using Contentstack.Management.Core.Unit.Tests.Mokes;
8+
using Microsoft.VisualStudio.TestTools.UnitTesting;
9+
10+
namespace Contentstack.Management.Core.Unit.Tests.Models
11+
{
12+
[TestClass]
13+
public class DeliveryTokenTest
14+
{
15+
private Stack _stack;
16+
private readonly IFixture _fixture = new Fixture();
17+
private ContentstackResponse _contentstackResponse;
18+
19+
[TestInitialize]
20+
public void initialize()
21+
{
22+
var client = new ContentstackClient();
23+
_contentstackResponse = MockResponse.CreateContentstackResponse("MockResponse.txt");
24+
client.ContentstackPipeline.ReplaceHandler(new MockHttpHandler(_contentstackResponse));
25+
client.contentstackOptions.Authtoken = _fixture.Create<string>();
26+
_stack = new Stack(client, _fixture.Create<string>());
27+
}
28+
29+
[TestMethod]
30+
public void Initialize_DeliveryToken()
31+
{
32+
DeliveryToken token = new DeliveryToken(_stack);
33+
Assert.IsNull(token.Uid);
34+
Assert.AreEqual("stacks/delivery_tokens", token.resourcePath);
35+
Assert.ThrowsException<InvalidOperationException>(() => token.Fetch());
36+
Assert.ThrowsExceptionAsync<InvalidOperationException>(() => token.FetchAsync());
37+
Assert.ThrowsException<InvalidOperationException>(() => token.Update(_fixture.Create<DeliveryTokenModel>()));
38+
Assert.ThrowsExceptionAsync<InvalidOperationException>(() => token.UpdateAsync(_fixture.Create<DeliveryTokenModel>()));
39+
Assert.ThrowsException<InvalidOperationException>(() => token.Delete());
40+
Assert.ThrowsExceptionAsync<InvalidOperationException>(() => token.DeleteAsync());
41+
Assert.AreEqual(token.Query().GetType(), typeof(Query));
42+
}
43+
44+
[TestMethod]
45+
public void Initialize_DeliveryToken_With_Uid()
46+
{
47+
string uid = _fixture.Create<string>();
48+
DeliveryToken token = new DeliveryToken(_stack, uid);
49+
Assert.AreEqual(uid, token.Uid);
50+
Assert.AreEqual($"stacks/delivery_tokens/{uid}", token.resourcePath);
51+
}
52+
53+
[TestMethod]
54+
public void Should_Create_DeliveryToken()
55+
{
56+
ContentstackResponse response = _stack.DeliveryToken().Create(_fixture.Create<DeliveryTokenModel>());
57+
Assert.AreEqual(_contentstackResponse.OpenResponse(), response.OpenResponse());
58+
Assert.AreEqual(_contentstackResponse.OpenJObjectResponse().ToString(), response.OpenJObjectResponse().ToString());
59+
}
60+
61+
[TestMethod]
62+
public async Task Should_Create_DeliveryToken_Async()
63+
{
64+
ContentstackResponse response = await _stack.DeliveryToken().CreateAsync(_fixture.Create<DeliveryTokenModel>());
65+
Assert.AreEqual(_contentstackResponse.OpenResponse(), response.OpenResponse());
66+
Assert.AreEqual(_contentstackResponse.OpenJObjectResponse().ToString(), response.OpenJObjectResponse().ToString());
67+
}
68+
69+
[TestMethod]
70+
public void Should_Query_DeliveryToken()
71+
{
72+
ContentstackResponse response = _stack.DeliveryToken().Query().Find();
73+
Assert.AreEqual(_contentstackResponse.OpenResponse(), response.OpenResponse());
74+
Assert.AreEqual(_contentstackResponse.OpenJObjectResponse().ToString(), response.OpenJObjectResponse().ToString());
75+
}
76+
77+
[TestMethod]
78+
public async Task Should_Query_DeliveryToken_Async()
79+
{
80+
ContentstackResponse response = await _stack.DeliveryToken().Query().FindAsync();
81+
Assert.AreEqual(_contentstackResponse.OpenResponse(), response.OpenResponse());
82+
Assert.AreEqual(_contentstackResponse.OpenJObjectResponse().ToString(), response.OpenJObjectResponse().ToString());
83+
}
84+
85+
[TestMethod]
86+
public void Should_Fetch_DeliveryToken()
87+
{
88+
ContentstackResponse response = _stack.DeliveryToken(_fixture.Create<string>()).Fetch();
89+
Assert.AreEqual(_contentstackResponse.OpenResponse(), response.OpenResponse());
90+
Assert.AreEqual(_contentstackResponse.OpenJObjectResponse().ToString(), response.OpenJObjectResponse().ToString());
91+
}
92+
93+
[TestMethod]
94+
public async Task Should_Fetch_DeliveryToken_Async()
95+
{
96+
ContentstackResponse response = await _stack.DeliveryToken(_fixture.Create<string>()).FetchAsync();
97+
Assert.AreEqual(_contentstackResponse.OpenResponse(), response.OpenResponse());
98+
Assert.AreEqual(_contentstackResponse.OpenJObjectResponse().ToString(), response.OpenJObjectResponse().ToString());
99+
}
100+
101+
[TestMethod]
102+
public void Should_Update_DeliveryToken()
103+
{
104+
ContentstackResponse response = _stack.DeliveryToken(_fixture.Create<string>()).Update(_fixture.Create<DeliveryTokenModel>());
105+
Assert.AreEqual(_contentstackResponse.OpenResponse(), response.OpenResponse());
106+
Assert.AreEqual(_contentstackResponse.OpenJObjectResponse().ToString(), response.OpenJObjectResponse().ToString());
107+
}
108+
109+
[TestMethod]
110+
public async Task Should_Update_DeliveryToken_Async()
111+
{
112+
ContentstackResponse response = await _stack.DeliveryToken(_fixture.Create<string>()).UpdateAsync(_fixture.Create<DeliveryTokenModel>());
113+
Assert.AreEqual(_contentstackResponse.OpenResponse(), response.OpenResponse());
114+
Assert.AreEqual(_contentstackResponse.OpenJObjectResponse().ToString(), response.OpenJObjectResponse().ToString());
115+
}
116+
117+
[TestMethod]
118+
public void Should_Delete_DeliveryToken()
119+
{
120+
ContentstackResponse response = _stack.DeliveryToken(_fixture.Create<string>()).Delete();
121+
Assert.AreEqual(_contentstackResponse.OpenResponse(), response.OpenResponse());
122+
Assert.AreEqual(_contentstackResponse.OpenJObjectResponse().ToString(), response.OpenJObjectResponse().ToString());
123+
}
124+
125+
[TestMethod]
126+
public async Task Should_Delete_DeliveryToken_Async()
127+
{
128+
ContentstackResponse response = await _stack.DeliveryToken(_fixture.Create<string>()).DeleteAsync();
129+
Assert.AreEqual(_contentstackResponse.OpenResponse(), response.OpenResponse());
130+
Assert.AreEqual(_contentstackResponse.OpenJObjectResponse().ToString(), response.OpenJObjectResponse().ToString());
131+
}
132+
}
133+
}

Contentstack.Management.Core/LICENSE.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
MIT License
22

3-
Copyright © 2012-2024 Contentstack. All Rights Reserved
3+
Copyright © 2012-2025 Contentstack. All Rights Reserved
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal

Contentstack.Management.Core/Models/Token/DeliveryToken.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1-
using System.Threading.Tasks;
1+
using System;
2+
using System.Threading.Tasks;
23
using Contentstack.Management.Core.Queryable;
4+
using Newtonsoft.Json.Linq;
35

46
namespace Contentstack.Management.Core.Models.Token
57
{
@@ -8,7 +10,7 @@ public class DeliveryToken : BaseModel<DeliveryTokenModel>
810
internal DeliveryToken(Stack stack, string uid = null)
911
: base(stack, "token", uid)
1012
{
11-
resourcePath = uid == null ? "/delivery_tokens" : $"/delivery_tokens/{uid}";
13+
resourcePath = uid == null ? "stacks/delivery_tokens" : $"stacks/delivery_tokens/{uid}";
1214
}
1315

1416
/// <summary>

Contentstack.Management.Core/contentstack.management.core.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<TargetFrameworks>netstandard2.0;net471;net472;</TargetFrameworks>
55
<Title>Contentstack Management</Title>
66
<Authors>Contentstack</Authors>
7-
<Copyright>Copyright © 2012-2024 Contentstack. All Rights Reserved</Copyright>
7+
<Copyright>Copyright © 2012-2025 Contentstack. All Rights Reserved</Copyright>
88
<Description>.NET SDK for the Contentstack Content Management API.</Description>
99
<Owners>Contentstack </Owners>
1010
<PackageId>contentstack.management.csharp</PackageId>

Scripts/run-test-case.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
# Contentstack
55
#
66
# Created by Uttam Ukkoji on 12/04/21.
7-
# Copyright © 2024 Contentstack. All rights reserved.
7+
# Copyright © 2025 Contentstack. All rights reserved.
88

99
echo "Removing files"
1010

Scripts/run-unit-test-case.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
# Contentstack
55
#
66
# Created by Uttam Ukkoji on 30/03/2023.
7-
# Copyright © 2024 Contentstack. All rights reserved.
7+
# Copyright © 2025 Contentstack. All rights reserved.
88

99
echo "Removing files"
1010
rm -rf "./Contentstack.Management.Core.Unit.Tests/TestResults"

0 commit comments

Comments
 (0)