Skip to content

Fixed the GetDelivery token and added unit test cases #71

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

Merged
merged 8 commits into from
Jun 2, 2025
Merged
Show file tree
Hide file tree
Changes from 7 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
4 changes: 2 additions & 2 deletions .github/workflows/check-branch.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 != '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 != 'next'
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
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion Contentstack.Management.ASPNETCore/LICENSE.txt
Original file line number Diff line number Diff line change
@@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<PackageId>contentstack.management.aspnetcore</PackageId>
<PackageVersion>$(Version)</PackageVersion>
<Authors>Contentstack</Authors>
<Copyright>Copyright © 2012-2024 Contentstack. All Rights Reserved</Copyright>
<Copyright>Copyright © 2012-2025 Contentstack. All Rights Reserved</Copyright>
<Owners>Contentstack </Owners>
<PackageProjectUrl>https://github.com/contentstack/contentstack-management-dotnet</PackageProjectUrl>
<PackageReleaseNotes>Initial Release</PackageReleaseNotes>
Expand All @@ -15,7 +15,7 @@
<Description>.NET SDK for the Contentstack Content Management API.</Description>
<PackageLicenseFile>LICENSE.txt</PackageLicenseFile>
<PackageTags>v$(Version)</PackageTags>
<ReleaseVersion>0.1.3</ReleaseVersion>
<ReleaseVersion>$(Version)</ReleaseVersion>
<RootNamespace>Contentstack.Management.ASPNETCore</RootNamespace>
</PropertyGroup>

Expand All @@ -28,7 +28,7 @@
<ItemGroup>
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="9.0.1" />
<PackageReference Include="Microsoft.Extensions.Options.ConfigurationExtensions" Version="9.0.1" />
<PackageReference Include="contentstack.management.csharp" Version="0.1.11" />
<PackageReference Include="contentstack.management.csharp" Version="0.1.10" />
<PackageReference Include="Microsoft.Extensions.Http" Version="9.0.1" />
</ItemGroup>
</Project>
133 changes: 133 additions & 0 deletions Contentstack.Management.Core.Unit.Tests/Models/DeliveryTokenTest.cs
Original file line number Diff line number Diff line change
@@ -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<string>();
_stack = new Stack(client, _fixture.Create<string>());
}

[TestMethod]
public void Initialize_DeliveryToken()
{
DeliveryToken token = new DeliveryToken(_stack);
Assert.IsNull(token.Uid);
Assert.AreEqual("stacks/delivery_tokens", token.resourcePath);
Assert.ThrowsException<InvalidOperationException>(() => token.Fetch());
Assert.ThrowsExceptionAsync<InvalidOperationException>(() => token.FetchAsync());
Assert.ThrowsException<InvalidOperationException>(() => token.Update(_fixture.Create<DeliveryTokenModel>()));
Assert.ThrowsExceptionAsync<InvalidOperationException>(() => token.UpdateAsync(_fixture.Create<DeliveryTokenModel>()));
Assert.ThrowsException<InvalidOperationException>(() => token.Delete());
Assert.ThrowsExceptionAsync<InvalidOperationException>(() => token.DeleteAsync());
Assert.AreEqual(token.Query().GetType(), typeof(Query));
}

[TestMethod]
public void Initialize_DeliveryToken_With_Uid()
{
string uid = _fixture.Create<string>();
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<DeliveryTokenModel>());
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<DeliveryTokenModel>());
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<string>()).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<string>()).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<string>()).Update(_fixture.Create<DeliveryTokenModel>());
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<string>()).UpdateAsync(_fixture.Create<DeliveryTokenModel>());
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<string>()).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<string>()).DeleteAsync();
Assert.AreEqual(_contentstackResponse.OpenResponse(), response.OpenResponse());
Assert.AreEqual(_contentstackResponse.OpenJObjectResponse().ToString(), response.OpenJObjectResponse().ToString());
}
}
}
2 changes: 1 addition & 1 deletion Contentstack.Management.Core/ContentstackClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion Contentstack.Management.Core/LICENSE.txt
Original file line number Diff line number Diff line change
@@ -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
Expand Down
6 changes: 4 additions & 2 deletions Contentstack.Management.Core/Models/Token/DeliveryToken.cs
Original file line number Diff line number Diff line change
@@ -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
{
Expand All @@ -8,7 +10,7 @@ public class DeliveryToken : BaseModel<DeliveryTokenModel>
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}";
}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<TargetFrameworks>netstandard2.0;net471;net472;</TargetFrameworks>
<Title>Contentstack Management</Title>
<Authors>Contentstack</Authors>
<Copyright>Copyright © 2012-2024 Contentstack. All Rights Reserved</Copyright>
<Copyright>Copyright © 2012-2025 Contentstack. All Rights Reserved</Copyright>
<Description>.NET SDK for the Contentstack Content Management API.</Description>
<Owners>Contentstack </Owners>
<PackageId>contentstack.management.csharp</PackageId>
Expand Down
2 changes: 1 addition & 1 deletion Directory.Build.props
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<Project>
<PropertyGroup>
<Version>0.1.11</Version>
<Version>0.1.12</Version>
</PropertyGroup>
</Project>
2 changes: 1 addition & 1 deletion Scripts/run-test-case.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down
2 changes: 1 addition & 1 deletion Scripts/run-unit-test-case.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down