Skip to content

Commit 2cc1e5f

Browse files
authored
Merge pull request #109 from contentstack/development
Development
2 parents e103b6e + 9e1453d commit 2cc1e5f

22 files changed

+4454
-3
lines changed

.talismanrc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,8 @@ fileignoreconfig:
77
checksum: 854eb83dcacd62d3bf233c82e5cfd0c69dd20478fa0e7c6af9028f6c6386749d
88
- filename: Contentstack.Management.Core/Attributes/CSMJsonConverterAttribute.cs
99
checksum: 774bc2a4cf7f62fb890ba39ba1319769f0ff4e13d94781d394fcac2adf14381e
10+
- filename: Contentstack.Management.Core.Unit.Tests/OAuth/OAuthOptionsTest.cs
11+
checksum: 3d1ed19a9c7d311d9662632f48169d3a9013f605674cbd18b9f45039b0f83ff6
12+
- filename: Contentstack.Management.Core/Models/OAuthOptions.cs
13+
checksum: c328bfd5241e11e6e9d630527ba9084fb5b361abac48e8af2f96379dd6357c6c
1014
version: ""

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@
66
- Automatic TOTP token generation from Base32-encoded MFA secrets using Otp.NET library
77
- Comprehensive test coverage for MFA functionality including unit and integration tests
88
- Supports both explicit token and MFA secret-based authentication flows
9+
- Added Support for OAuth
10+
- Added Comprehensive test coverage for OAuth Functionality in Unit Test cases.
11+
- Supports both Login with and without OAuth Flows
912

1013
## [v0.3.2](https://github.com/contentstack/contentstack-management-dotnet/tree/v0.3.2)
1114
- Fix
Lines changed: 212 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,212 @@
1+
using System;
2+
using Microsoft.VisualStudio.TestTools.UnitTesting;
3+
using Contentstack.Management.Core.Exceptions;
4+
5+
namespace Contentstack.Management.Core.Unit.Tests.OAuth
6+
{
7+
[TestClass]
8+
public class OAuthExceptionTest
9+
{
10+
[TestMethod]
11+
public void OAuthException_DefaultConstructor_ShouldUseDefaultMessage()
12+
{
13+
14+
var exception = new OAuthException();
15+
Assert.AreEqual("OAuth operation failed.", exception.Message);
16+
Assert.IsNull(exception.InnerException);
17+
}
18+
19+
[TestMethod]
20+
public void OAuthException_WithMessage_ShouldUseProvidedMessage()
21+
{
22+
23+
var message = "Custom OAuth error message";
24+
var exception = new OAuthException(message);
25+
Assert.AreEqual(message, exception.Message);
26+
Assert.IsNull(exception.InnerException);
27+
}
28+
29+
[TestMethod]
30+
public void OAuthException_WithMessageAndInnerException_ShouldUseBoth()
31+
{
32+
33+
var message = "Custom OAuth error message";
34+
var innerException = new InvalidOperationException("Inner exception");
35+
var exception = new OAuthException(message, innerException);
36+
Assert.AreEqual(message, exception.Message);
37+
Assert.AreEqual(innerException, exception.InnerException);
38+
}
39+
40+
[TestMethod]
41+
public void OAuthConfigurationException_DefaultConstructor_ShouldUseDefaultMessage()
42+
{
43+
44+
var exception = new OAuthConfigurationException();
45+
Assert.AreEqual("OAuth configuration is invalid.", exception.Message);
46+
Assert.IsNull(exception.InnerException);
47+
}
48+
49+
[TestMethod]
50+
public void OAuthConfigurationException_WithMessage_ShouldUseProvidedMessage()
51+
{
52+
53+
var message = "Custom configuration error message";
54+
var exception = new OAuthConfigurationException(message);
55+
Assert.AreEqual(message, exception.Message);
56+
Assert.IsNull(exception.InnerException);
57+
}
58+
59+
[TestMethod]
60+
public void OAuthConfigurationException_WithMessageAndInnerException_ShouldUseBoth()
61+
{
62+
63+
var message = "Custom configuration error message";
64+
var innerException = new ArgumentException("Inner exception");
65+
var exception = new OAuthConfigurationException(message, innerException);
66+
Assert.AreEqual(message, exception.Message);
67+
Assert.AreEqual(innerException, exception.InnerException);
68+
}
69+
70+
[TestMethod]
71+
public void OAuthTokenException_DefaultConstructor_ShouldUseDefaultMessage()
72+
{
73+
74+
var exception = new OAuthTokenException();
75+
Assert.AreEqual("OAuth token operation failed.", exception.Message);
76+
Assert.IsNull(exception.InnerException);
77+
}
78+
79+
[TestMethod]
80+
public void OAuthTokenException_WithMessage_ShouldUseProvidedMessage()
81+
{
82+
83+
var message = "Custom token error message";
84+
var exception = new OAuthTokenException(message);
85+
Assert.AreEqual(message, exception.Message);
86+
Assert.IsNull(exception.InnerException);
87+
}
88+
89+
[TestMethod]
90+
public void OAuthTokenException_WithMessageAndInnerException_ShouldUseBoth()
91+
{
92+
93+
var message = "Custom token error message";
94+
var innerException = new InvalidOperationException("Inner exception");
95+
var exception = new OAuthTokenException(message, innerException);
96+
Assert.AreEqual(message, exception.Message);
97+
Assert.AreEqual(innerException, exception.InnerException);
98+
}
99+
100+
[TestMethod]
101+
public void OAuthAuthorizationException_DefaultConstructor_ShouldUseDefaultMessage()
102+
{
103+
104+
var exception = new OAuthAuthorizationException();
105+
Assert.AreEqual("OAuth authorization failed.", exception.Message);
106+
Assert.IsNull(exception.InnerException);
107+
}
108+
109+
[TestMethod]
110+
public void OAuthAuthorizationException_WithMessage_ShouldUseProvidedMessage()
111+
{
112+
113+
var message = "Custom authorization error message";
114+
var exception = new OAuthAuthorizationException(message);
115+
Assert.AreEqual(message, exception.Message);
116+
Assert.IsNull(exception.InnerException);
117+
}
118+
119+
[TestMethod]
120+
public void OAuthAuthorizationException_WithMessageAndInnerException_ShouldUseBoth()
121+
{
122+
123+
var message = "Custom authorization error message";
124+
var innerException = new InvalidOperationException("Inner exception");
125+
var exception = new OAuthAuthorizationException(message, innerException);
126+
Assert.AreEqual(message, exception.Message);
127+
Assert.AreEqual(innerException, exception.InnerException);
128+
}
129+
130+
[TestMethod]
131+
public void OAuthTokenRefreshException_DefaultConstructor_ShouldUseDefaultMessage()
132+
{
133+
134+
var exception = new OAuthTokenRefreshException();
135+
Assert.AreEqual("OAuth token refresh failed.", exception.Message);
136+
Assert.IsNull(exception.InnerException);
137+
}
138+
139+
[TestMethod]
140+
public void OAuthTokenRefreshException_WithMessage_ShouldUseProvidedMessage()
141+
{
142+
143+
var message = "Custom refresh error message";
144+
var exception = new OAuthTokenRefreshException(message);
145+
Assert.AreEqual(message, exception.Message);
146+
Assert.IsNull(exception.InnerException);
147+
}
148+
149+
[TestMethod]
150+
public void OAuthTokenRefreshException_WithMessageAndInnerException_ShouldUseBoth()
151+
{
152+
153+
var message = "Custom refresh error message";
154+
var innerException = new InvalidOperationException("Inner exception");
155+
var exception = new OAuthTokenRefreshException(message, innerException);
156+
Assert.AreEqual(message, exception.Message);
157+
Assert.AreEqual(innerException, exception.InnerException);
158+
}
159+
160+
[TestMethod]
161+
public void OAuthException_Inheritance_ShouldBeCorrect()
162+
{
163+
164+
var oauthException = new OAuthException();
165+
var configException = new OAuthConfigurationException();
166+
var tokenException = new OAuthTokenException();
167+
var authException = new OAuthAuthorizationException();
168+
var refreshException = new OAuthTokenRefreshException();
169+
Assert.IsInstanceOfType(oauthException, typeof(Exception));
170+
Assert.IsInstanceOfType(configException, typeof(OAuthException));
171+
Assert.IsInstanceOfType(tokenException, typeof(OAuthException));
172+
Assert.IsInstanceOfType(authException, typeof(OAuthException));
173+
Assert.IsInstanceOfType(refreshException, typeof(OAuthTokenException));
174+
}
175+
176+
[TestMethod]
177+
public void OAuthException_Serialization_ShouldWork()
178+
{
179+
180+
var originalException = new OAuthException("Test message", new InvalidOperationException("Inner"));
181+
Assert.IsNotNull(originalException);
182+
Assert.AreEqual("Test message", originalException.Message);
183+
Assert.IsNotNull(originalException.InnerException);
184+
}
185+
186+
[TestMethod]
187+
public void OAuthException_ToString_ShouldIncludeMessage()
188+
{
189+
190+
var message = "Test OAuth error message";
191+
var exception = new OAuthException(message);
192+
var result = exception.ToString();
193+
Assert.IsTrue(result.Contains(message));
194+
Assert.IsTrue(result.Contains("OAuthException"));
195+
}
196+
197+
[TestMethod]
198+
public void OAuthException_WithInnerException_ToString_ShouldIncludeBoth()
199+
{
200+
201+
var message = "Test OAuth error message";
202+
var innerMessage = "Inner exception message";
203+
var innerException = new InvalidOperationException(innerMessage);
204+
var exception = new OAuthException(message, innerException);
205+
var result = exception.ToString();
206+
Assert.IsTrue(result.Contains(message));
207+
Assert.IsTrue(result.Contains(innerMessage));
208+
Assert.IsTrue(result.Contains("OAuthException"));
209+
Assert.IsTrue(result.Contains("InvalidOperationException"));
210+
}
211+
}
212+
}

0 commit comments

Comments
 (0)