mirror of
https://github.com/BinaryAlley/Nemera.git
synced 2026-12-01 20:01:10 +00:00
85 lines
3.2 KiB
C#
85 lines
3.2 KiB
C#
#region ========================================================================= USING =====================================================================================
|
|
using Nemera.Application.Common.DataAccess.Entities.Plugins;
|
|
using Nemera.DataAccess.Core.UoW;
|
|
using Nemera.Domain.SharedKernel.Common.Enums.Plugins;
|
|
using Microsoft.EntityFrameworkCore;
|
|
using Microsoft.EntityFrameworkCore.Metadata;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Diagnostics.CodeAnalysis;
|
|
using System.Linq;
|
|
#endregion
|
|
|
|
namespace Nemera.DataAccess.UnitTests.Common.Configuration;
|
|
|
|
/// <summary>
|
|
/// Contains unit tests for the <see cref="PluginConfiguration"/> class.
|
|
/// </summary>
|
|
[ExcludeFromCodeCoverage]
|
|
public class PluginConfigurationTests
|
|
{
|
|
private readonly NemeraDbContext _context;
|
|
|
|
/// <summary>
|
|
/// Initializes a new instance of the <see cref="PluginConfigurationTests"/> class.
|
|
/// </summary>
|
|
public PluginConfigurationTests()
|
|
{
|
|
_context = new NemeraDbContext(new DbContextOptionsBuilder<NemeraDbContext>().UseSqlite("Data Source=:memory:").Options);
|
|
}
|
|
|
|
[Fact]
|
|
public void Configure_WhenApplied_ShouldSetTableNameAndKey()
|
|
{
|
|
// Arrange
|
|
IEntityType entityType = _context.Model.FindEntityType(typeof(PluginEntity))!;
|
|
|
|
// Act
|
|
string? tableName = entityType.GetTableName();
|
|
IReadOnlyList<IProperty> keyProperties = entityType.FindPrimaryKey()!.Properties;
|
|
|
|
// Assert
|
|
Assert.Equal("Plugins", tableName);
|
|
Assert.Equal(["Id"], keyProperties.Select(property => property.Name));
|
|
}
|
|
|
|
[Fact]
|
|
public void Configure_WhenApplied_ShouldConfigureScalarProperties()
|
|
{
|
|
// Arrange
|
|
IEntityType entityType = _context.Model.FindEntityType(typeof(PluginEntity))!;
|
|
|
|
// Act
|
|
IProperty nameProperty = entityType.GetProperty(nameof(PluginEntity.Name));
|
|
IProperty authorProperty = entityType.GetProperty(nameof(PluginEntity.Author));
|
|
IProperty versionProperty = entityType.GetProperty(nameof(PluginEntity.Version));
|
|
IProperty loadStatusProperty = entityType.GetProperty(nameof(PluginEntity.LoadStatus));
|
|
|
|
// Assert
|
|
Assert.False(nameProperty.IsNullable);
|
|
Assert.Equal(255, nameProperty.GetMaxLength());
|
|
Assert.False(authorProperty.IsNullable);
|
|
Assert.Equal(255, authorProperty.GetMaxLength());
|
|
Assert.False(versionProperty.IsNullable);
|
|
Assert.Equal(50, versionProperty.GetMaxLength());
|
|
Assert.Equal(typeof(PluginLoadStatus), loadStatusProperty.ClrType);
|
|
Assert.Equal("TEXT", loadStatusProperty.GetColumnType());
|
|
Assert.Equal(20, loadStatusProperty.GetMaxLength());
|
|
}
|
|
|
|
[Fact]
|
|
public void Configure_WhenApplied_ShouldConfigureAuditProperties()
|
|
{
|
|
// Arrange
|
|
IEntityType entityType = _context.Model.FindEntityType(typeof(PluginEntity))!;
|
|
|
|
// Act
|
|
IProperty createdOnUtcProperty = entityType.GetProperty(nameof(PluginEntity.CreatedOnUtc));
|
|
IProperty updatedOnUtcProperty = entityType.GetProperty(nameof(PluginEntity.UpdatedOnUtc));
|
|
|
|
// Assert
|
|
Assert.False(createdOnUtcProperty.IsNullable);
|
|
Assert.Null(updatedOnUtcProperty.GetDefaultValue());
|
|
}
|
|
}
|