Skip to content
4 changes: 4 additions & 0 deletions .talismanrc
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,8 @@ fileignoreconfig:
checksum: 854eb83dcacd62d3bf233c82e5cfd0c69dd20478fa0e7c6af9028f6c6386749d
- filename: Contentstack.Management.Core/Attributes/CSMJsonConverterAttribute.cs
checksum: 774bc2a4cf7f62fb890ba39ba1319769f0ff4e13d94781d394fcac2adf14381e
- filename: Contentstack.Management.Core.Unit.Tests/OAuth/OAuthOptionsTest.cs
checksum: 3d1ed19a9c7d311d9662632f48169d3a9013f605674cbd18b9f45039b0f83ff6
- filename: Contentstack.Management.Core/Models/OAuthOptions.cs
checksum: c328bfd5241e11e6e9d630527ba9084fb5b361abac48e8af2f96379dd6357c6c
version: ""
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
- Automatic TOTP token generation from Base32-encoded MFA secrets using Otp.NET library
- Comprehensive test coverage for MFA functionality including unit and integration tests
- Supports both explicit token and MFA secret-based authentication flows
- Added Support for OAuth
- Added Comprehensive test coverage for OAuth Functionality in Unit Test cases.
- Supports both Login with and without OAuth Flows

## [v0.3.2](https://github.com/contentstack/contentstack-management-dotnet/tree/v0.3.2)
- Fix
Expand Down
212 changes: 212 additions & 0 deletions Contentstack.Management.Core.Unit.Tests/OAuth/OAuthExceptionTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,212 @@
using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Contentstack.Management.Core.Exceptions;

namespace Contentstack.Management.Core.Unit.Tests.OAuth
{
[TestClass]
public class OAuthExceptionTest
{
[TestMethod]
public void OAuthException_DefaultConstructor_ShouldUseDefaultMessage()
{

var exception = new OAuthException();
Assert.AreEqual("OAuth operation failed.", exception.Message);
Assert.IsNull(exception.InnerException);
}

[TestMethod]
public void OAuthException_WithMessage_ShouldUseProvidedMessage()
{

var message = "Custom OAuth error message";
var exception = new OAuthException(message);
Assert.AreEqual(message, exception.Message);
Assert.IsNull(exception.InnerException);
}

[TestMethod]
public void OAuthException_WithMessageAndInnerException_ShouldUseBoth()
{

var message = "Custom OAuth error message";
var innerException = new InvalidOperationException("Inner exception");
var exception = new OAuthException(message, innerException);
Assert.AreEqual(message, exception.Message);
Assert.AreEqual(innerException, exception.InnerException);
}

[TestMethod]
public void OAuthConfigurationException_DefaultConstructor_ShouldUseDefaultMessage()
{

var exception = new OAuthConfigurationException();
Assert.AreEqual("OAuth configuration is invalid.", exception.Message);
Assert.IsNull(exception.InnerException);
}

[TestMethod]
public void OAuthConfigurationException_WithMessage_ShouldUseProvidedMessage()
{

var message = "Custom configuration error message";
var exception = new OAuthConfigurationException(message);
Assert.AreEqual(message, exception.Message);
Assert.IsNull(exception.InnerException);
}

[TestMethod]
public void OAuthConfigurationException_WithMessageAndInnerException_ShouldUseBoth()
{

var message = "Custom configuration error message";
var innerException = new ArgumentException("Inner exception");
var exception = new OAuthConfigurationException(message, innerException);
Assert.AreEqual(message, exception.Message);
Assert.AreEqual(innerException, exception.InnerException);
}

[TestMethod]
public void OAuthTokenException_DefaultConstructor_ShouldUseDefaultMessage()
{

var exception = new OAuthTokenException();
Assert.AreEqual("OAuth token operation failed.", exception.Message);
Assert.IsNull(exception.InnerException);
}

[TestMethod]
public void OAuthTokenException_WithMessage_ShouldUseProvidedMessage()
{

var message = "Custom token error message";
var exception = new OAuthTokenException(message);
Assert.AreEqual(message, exception.Message);
Assert.IsNull(exception.InnerException);
}

[TestMethod]
public void OAuthTokenException_WithMessageAndInnerException_ShouldUseBoth()
{

var message = "Custom token error message";
var innerException = new InvalidOperationException("Inner exception");
var exception = new OAuthTokenException(message, innerException);
Assert.AreEqual(message, exception.Message);
Assert.AreEqual(innerException, exception.InnerException);
}

[TestMethod]
public void OAuthAuthorizationException_DefaultConstructor_ShouldUseDefaultMessage()
{

var exception = new OAuthAuthorizationException();
Assert.AreEqual("OAuth authorization failed.", exception.Message);
Assert.IsNull(exception.InnerException);
}

[TestMethod]
public void OAuthAuthorizationException_WithMessage_ShouldUseProvidedMessage()
{

var message = "Custom authorization error message";
var exception = new OAuthAuthorizationException(message);
Assert.AreEqual(message, exception.Message);
Assert.IsNull(exception.InnerException);
}

[TestMethod]
public void OAuthAuthorizationException_WithMessageAndInnerException_ShouldUseBoth()
{

var message = "Custom authorization error message";
var innerException = new InvalidOperationException("Inner exception");
var exception = new OAuthAuthorizationException(message, innerException);
Assert.AreEqual(message, exception.Message);
Assert.AreEqual(innerException, exception.InnerException);
}

[TestMethod]
public void OAuthTokenRefreshException_DefaultConstructor_ShouldUseDefaultMessage()
{

var exception = new OAuthTokenRefreshException();
Assert.AreEqual("OAuth token refresh failed.", exception.Message);
Assert.IsNull(exception.InnerException);
}

[TestMethod]
public void OAuthTokenRefreshException_WithMessage_ShouldUseProvidedMessage()
{

var message = "Custom refresh error message";
var exception = new OAuthTokenRefreshException(message);
Assert.AreEqual(message, exception.Message);
Assert.IsNull(exception.InnerException);
}

[TestMethod]
public void OAuthTokenRefreshException_WithMessageAndInnerException_ShouldUseBoth()
{

var message = "Custom refresh error message";
var innerException = new InvalidOperationException("Inner exception");
var exception = new OAuthTokenRefreshException(message, innerException);
Assert.AreEqual(message, exception.Message);
Assert.AreEqual(innerException, exception.InnerException);
}

[TestMethod]
public void OAuthException_Inheritance_ShouldBeCorrect()
{

var oauthException = new OAuthException();
var configException = new OAuthConfigurationException();
var tokenException = new OAuthTokenException();
var authException = new OAuthAuthorizationException();
var refreshException = new OAuthTokenRefreshException();
Assert.IsInstanceOfType(oauthException, typeof(Exception));
Assert.IsInstanceOfType(configException, typeof(OAuthException));
Assert.IsInstanceOfType(tokenException, typeof(OAuthException));
Assert.IsInstanceOfType(authException, typeof(OAuthException));
Assert.IsInstanceOfType(refreshException, typeof(OAuthTokenException));
}

[TestMethod]
public void OAuthException_Serialization_ShouldWork()
{

var originalException = new OAuthException("Test message", new InvalidOperationException("Inner"));
Assert.IsNotNull(originalException);
Assert.AreEqual("Test message", originalException.Message);
Assert.IsNotNull(originalException.InnerException);
}

[TestMethod]
public void OAuthException_ToString_ShouldIncludeMessage()
{

var message = "Test OAuth error message";
var exception = new OAuthException(message);
var result = exception.ToString();
Assert.IsTrue(result.Contains(message));
Assert.IsTrue(result.Contains("OAuthException"));
}

[TestMethod]
public void OAuthException_WithInnerException_ToString_ShouldIncludeBoth()
{

var message = "Test OAuth error message";
var innerMessage = "Inner exception message";
var innerException = new InvalidOperationException(innerMessage);
var exception = new OAuthException(message, innerException);
var result = exception.ToString();
Assert.IsTrue(result.Contains(message));
Assert.IsTrue(result.Contains(innerMessage));
Assert.IsTrue(result.Contains("OAuthException"));
Assert.IsTrue(result.Contains("InvalidOperationException"));
}
}
}
Loading
Loading