Remove duplicate source files from old ApiKeys/, Authentication/, and Authorization/ folders that were already migrated to Common/Security/. Update test namespace usings to match. Pin EFC Relational 10.0.5 to resolve MSB3277 version conflict with Npgsql's transitive dependency. Add LangVersion and TreatWarningsAsErrors to AppHost and ServiceDefaults.
54 lines
1.3 KiB
C#
Executable File
54 lines
1.3 KiB
C#
Executable File
using NUnit.Framework;
|
|
using MicCheck.Api.Common.Security.ApiKeys;
|
|
|
|
namespace MicCheck.Api.Tests.Unit.ApiKeys;
|
|
|
|
[TestFixture]
|
|
public class ApiKeyTests
|
|
{
|
|
[Test]
|
|
public void WhenAnApiKeyIsCreated_ThenRequiredFieldsAreSet()
|
|
{
|
|
var apiKey = new ApiKey
|
|
{
|
|
Key = "hashed-value",
|
|
Prefix = "abc12345",
|
|
Name = "CI Pipeline Key",
|
|
OrganizationId = 1
|
|
};
|
|
|
|
Assert.That(apiKey.Key, Is.EqualTo("hashed-value"));
|
|
Assert.That(apiKey.Prefix, Is.EqualTo("hashed-value".Substring(0, 8)).Or.EqualTo("abc12345"));
|
|
Assert.That(apiKey.Name, Is.EqualTo("CI Pipeline Key"));
|
|
Assert.That(apiKey.OrganizationId, Is.EqualTo(1));
|
|
}
|
|
|
|
[Test]
|
|
public void WhenAnApiKeyIsCreated_ThenIsActiveDefaultsToFalse()
|
|
{
|
|
var apiKey = new ApiKey
|
|
{
|
|
Key = "hashed-value",
|
|
Prefix = "abc12345",
|
|
Name = "Test Key",
|
|
OrganizationId = 1
|
|
};
|
|
|
|
Assert.That(apiKey.IsActive, Is.False);
|
|
}
|
|
|
|
[Test]
|
|
public void WhenAnApiKeyIsCreated_ThenExpiresAtDefaultsToNull()
|
|
{
|
|
var apiKey = new ApiKey
|
|
{
|
|
Key = "hashed-value",
|
|
Prefix = "abc12345",
|
|
Name = "Test Key",
|
|
OrganizationId = 1
|
|
};
|
|
|
|
Assert.That(apiKey.ExpiresAt, Is.Null);
|
|
}
|
|
}
|