Atis.Testing 2.0.0-preview.5

This is a prerelease version of Atis.Testing.
dotnet add package Atis.Testing --version 2.0.0-preview.5
                    
NuGet\Install-Package Atis.Testing -Version 2.0.0-preview.5
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Atis.Testing" Version="2.0.0-preview.5" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Atis.Testing" Version="2.0.0-preview.5" />
                    
Directory.Packages.props
<PackageReference Include="Atis.Testing" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Atis.Testing --version 2.0.0-preview.5
                    
#r "nuget: Atis.Testing, 2.0.0-preview.5"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package Atis.Testing@2.0.0-preview.5
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Atis.Testing&version=2.0.0-preview.5&prerelease
                    
Install as a Cake Addin
#tool nuget:?package=Atis.Testing&version=2.0.0-preview.5&prerelease
                    
Install as a Cake Tool

Atis.Testing

ATIS servisləri üçün test köməkçiləri: yaddaşiçi SQLite context fixture-u, arxitektura qaydaları və EF model qaydaları. Yalnız test layihələrində referans verilir (IsPackable-dır, amma runtime paketi deyil).

SqliteContextFixture<TContext>

// SqliteContextFixture sealed-dir — IClassFixture üçün parametrsiz sarğı (wrapper) yaz:
public sealed class StaffDbFixture : IDisposable
{
    private readonly SqliteContextFixture<StaffDbContext> _inner = new(
        schema: "staff",
        factory: (o, a) => new StaffDbContext(o, a));

    public SqliteConnection Connection => _inner.Connection;
    public StaffDbContext Create(bool withInterceptors = true) => _inner.Create(withInterceptors);
    public void Dispose() => _inner.Dispose();
}

public class StaffRepositoryTests(StaffDbFixture fixture) : IClassFixture<StaffDbFixture>
{
    [Fact]
    public async Task Adds_a_request()
    {
        await using var ctx = fixture.Create();          // interceptor-larla (audit, soft-delete, read-only)
        ctx.Add(new StaffSubjectRequest { /* ... */ });
        await ctx.SaveChangesAsync();

        await using var check = fixture.Create(withInterceptors: false);
        (await check.StaffSubjectRequests.CountAsync()).Should().Be(1);
    }
}

Nə edir:

  • DataSource=:memory: SQLite bağlantısı açır və fixture yaşadıqca açıq saxlayır (bağlantı bağlansa yaddaşiçi DB itir) — ona görə IClassFixture ilə paylaş.
  • EnsureCreated() ilə sxemi yaradır, sonra ExcludeFromMigrations olan cədvəlləri də (dbo read-only lüğətlər və yad entity-lər) design-time modeldən CREATE TABLE ilə əlavə edir — EnsureCreated onları özü yaratmır, amma testlərin oxuması üçün lazımdır; bu sütunlar HasDefaultValue/HasDefaultValueSql ilə DB-DEFAULT-u olan sütunlarsa, həmin DEFAULT bəndi də DDL-ə köçürülür (əks halda EF sentinel qiymətdə sütunu INSERT-dən çıxarır və SQLite NOT NULL-da "constraint failed" atır).
  • Create(withInterceptors: true) Atis.Persistence-in üç interceptor-unu qoşur: ReadOnlyEntitySaveChangesInterceptor, SoftDeleteSaveChangesInterceptor, AuditSaveChangesInterceptor (user parametri verilməyibsə NullAuditUserProvider → CreatedUserId = null).
  • withInterceptors: false ilə yaradılan context qoruma olmadan yazır — read-only cədvəllərə test datası doldurmaq üçün məhz bu yol nəzərdə tutulub.

SQLite fərqləri: sxem adları (staff., dbo.) SQLite-da mənasızdır və EF Core tərəfindən atılır; SQL Server-ə məxsus tiplər/funksiyalar (GETDATE(), datetime2 dəqiqliyi, NEWSEQUENTIALID()) yoxdur. Sxem və migration düzgünlüyü SQLite ilə deyil, aşağıdakı ModelRules ilə yoxlanır.

Host testləri

Fixture-un açdığı yaddaşiçi SQLite bağlantısı Connection xassəsi ilə ifşa olunur — host tərəfin öz AddAtisPersistence qeydiyyatını (production provider-i əvəz etmədən) eyni yaddaşiçi DB-yə yönləndirmək üçün:

services.AddAtisPersistence<UserDbContext>(configuration, o =>
{
    o.Schema = "user";
    o.MigrateOnStartup = false;
    o.ConfigureProvider = b => b.UseSqlite(fixture.Connection);
});

Bağlantı fixture ilə açılıb-bağlanır (Dispose) — host tərəf onu özü bağlamamalıdır, əks halda yaddaşiçi DB itir və fixture-un qalan istifadəçiləri (IClassFixture) boş bazaya qoşulur.

ModelRules

[Fact]
public void Migrations_never_touch_dbo()
{
    using var ctx = fixture.Create(withInterceptors: false);
    ModelRules.AssertNoDboObjectInMigrations(ctx);      // dbo obyekti migration-a düşübsə atır
    ModelRules.AssertOwnedTablesUseSchema(ctx, "staff"); // sahib cədvəllər staff.* olmalıdır
}
  • AssertNoDboObjectInMigrations(ctx) — modeldə ExcludeFromMigrations olmadan dbo-ya map olunmuş cədvəl varsa InvalidOperationException (siyahı ilə). Spec §6.2-nin "migration dbo-ya dəymir" qaydasının testə çevrilmiş formasıdır.
  • AssertOwnedTablesUseSchema(ctx, schema) — migration-a daxil olan (ExcludeFromMigrations olmayan) hər cədvəl verilən sxemdə olmalıdır; read-only dbo cədvəlləri yoxlamadan kənardır.

ArchitectureRules

[Fact]
public void Layers_are_respected()
{
    var services = typeof(StaffDbContext).Assembly;
    ArchitectureRules.AssertNoReference(typeof(StaffContracts).Assembly, "Atis.");      // Contracts → Atis.* yoxdur
    ArchitectureRules.AssertTypesInNamespaceDoNotUse(services, "Services.Core", "Microsoft.EntityFrameworkCore");
    ArchitectureRules.AssertTypesInNamespaceDoNotUse(services, "Services.Applications", "Services.Infrastructure");
}
  • AssertNoReference(assembly, prefix) — assembly-nin referansları arasında adı prefix ilə başlayan varsa atır.
  • AssertTypesInNamespaceDoNotUse(assembly, fromNs, forbiddenNs) — fromNs altındakı tiplərin baza tipi, interfeysləri, sahə/xassə tipləri, konstruktor və metod parametrləri, qaytarma tipləri forbiddenNs-ə toxunursa atır (pozuntu siyahısı ilə). Spec §3-dəki qat qaydalarını (Core → heç nə; Applications → Core; Infrastructure → hər ikisi) pin etmək üçündür.

Bütün qaydalar InvalidOperationException atır (test framework-dən asılı deyil) — xUnit/NUnit fərqi yoxdur.

Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
2.0.0-preview.5 4 10/1/2026
2.0.0-preview.4 67 9/14/2026

2.0.0-preview.1: SqliteContextFixture<TContext> (yaddaşiçi SQLite + ExcludeFromMigrations cədvəlləri), ModelRules (dbo/sxem qaydaları), ArchitectureRules (qat sərhədləri). preview.4: README — SqliteContextFixture sealed-dir, IClassFixture üçün wrapper nümunəsi.