Files
ps.ipam/classlib.tests/Cmdlets/NewSessionCmdletTests.cs

111 lines
3.2 KiB
C#

namespace PS.IPAM.Tests.Cmdlets;
using FluentAssertions;
using PS.IPAM;
using PS.IPAM.Cmdlets;
using PS.IPAM.Helpers;
using Xunit;
/// <summary>
/// Tests for the NewSessionCmdlet.
/// Note: Full cmdlet testing with parameter sets requires a PowerShell runspace.
/// These tests focus on verifying the cmdlet structure and basic functionality.
/// </summary>
[Collection("Sequential")]
public class NewSessionCmdletTests : IDisposable
{
public NewSessionCmdletTests()
{
// Clean state before each test
SessionManager.CloseSession();
}
public void Dispose()
{
// Clean up after each test
SessionManager.CloseSession();
}
[Fact]
public void NewSessionCmdlet_Exists()
{
// Verify the cmdlet class exists and can be instantiated
var cmdlet = new NewSessionCmdlet();
cmdlet.Should().NotBeNull();
}
[Fact]
public void NewSessionCmdlet_URLProperty_Exists()
{
var cmdlet = new NewSessionCmdlet();
cmdlet.URL = "https://ipam.example.com";
cmdlet.URL.Should().Be("https://ipam.example.com");
}
[Fact]
public void NewSessionCmdlet_AppIDProperty_Exists()
{
var cmdlet = new NewSessionCmdlet();
cmdlet.AppID = "testapp";
cmdlet.AppID.Should().Be("testapp");
}
[Fact]
public void NewSessionCmdlet_TokenProperty_Exists()
{
var cmdlet = new NewSessionCmdlet();
cmdlet.Token = "my-api-token";
cmdlet.Token.Should().Be("my-api-token");
}
[Fact]
public void NewSessionCmdlet_CredentialsProperty_Exists()
{
var cmdlet = new NewSessionCmdlet();
cmdlet.Credentials = null;
cmdlet.Credentials.Should().BeNull();
}
[Fact]
public void NewSessionCmdlet_IgnoreSSLProperty_Exists()
{
var cmdlet = new NewSessionCmdlet();
// SwitchParameter defaults to false
cmdlet.IgnoreSSL.IsPresent.Should().BeFalse();
// Setting it to true
var switchParam = new System.Management.Automation.SwitchParameter(true);
cmdlet.IgnoreSSL = switchParam;
// Note: SwitchParameter is a struct, so getting the value back may not work as expected
// Just verify the property exists and can be set
}
[Fact]
public void SessionManager_CreateSessionWithToken_WorksCorrectly()
{
// This tests the underlying functionality that the cmdlet uses
var session = SessionManager.CreateSessionWithToken(
"https://ipam.example.com",
"testapp",
"my-api-token"
);
session.Should().NotBeNull();
session.URL.Should().Be("https://ipam.example.com");
session.AppID.Should().Be("testapp");
session.Token.Should().Be("my-api-token");
session.AuthType.Should().Be(AuthType.Token);
session.Expires.Should().BeNull();
session.Credentials.Should().BeNull();
// Verify it was set as current session
SessionManager.CurrentSession.Should().BeSameAs(session);
}
[Fact]
public void NewSessionCmdlet_InheritsFromBaseCmdlet()
{
var cmdlet = new NewSessionCmdlet();
cmdlet.Should().BeAssignableTo<BaseCmdlet>();
}
}