Atis.Testing
2.0.0-preview.5
dotnet add package Atis.Testing --version 2.0.0-preview.5
NuGet\Install-Package Atis.Testing -Version 2.0.0-preview.5
<PackageReference Include="Atis.Testing" Version="2.0.0-preview.5" />
<PackageVersion Include="Atis.Testing" Version="2.0.0-preview.5" />
<PackageReference Include="Atis.Testing" />
paket add Atis.Testing --version 2.0.0-preview.5
#r "nuget: Atis.Testing, 2.0.0-preview.5"
#:package Atis.Testing@2.0.0-preview.5
#addin nuget:?package=Atis.Testing&version=2.0.0-preview.5&prerelease
#tool nuget:?package=Atis.Testing&version=2.0.0-preview.5&prerelease
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əIClassFixtureilə paylaş.EnsureCreated()ilə sxemi yaradır, sonraExcludeFromMigrationsolan cədvəlləri də (dboread-only lüğətlər və yad entity-lər) design-time modeldənCREATE TABLEilə əlavə edir —EnsureCreatedonları özü yaratmır, amma testlərin oxuması üçün lazımdır; bu sütunlarHasDefaultValue/HasDefaultValueSqlilə DB-DEFAULT-u olan sütunlarsa, həminDEFAULTbə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(userparametri verilməyibsəNullAuditUserProvider→CreatedUserId = null).withInterceptors: falseilə 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əExcludeFromMigrationsolmadandbo-ya map olunmuş cədvəl varsaInvalidOperationException(siyahı ilə). Spec §6.2-nin "migrationdbo-ya dəymir" qaydasının testə çevrilmiş formasıdır.AssertOwnedTablesUseSchema(ctx, schema)— migration-a daxil olan (ExcludeFromMigrationsolmayan) hər cədvəl verilən sxemdə olmalıdır; read-onlydbocə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ıprefixilə başlayan varsa atır.AssertTypesInNamespaceDoNotUse(assembly, fromNs, forbiddenNs)—fromNsaltındakı tiplərin baza tipi, interfeysləri, sahə/xassə tipləri, konstruktor və metod parametrləri, qaytarma tipləriforbiddenNs-ə 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 | Versions 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. |
-
net8.0
- Atis.Persistence (>= 2.0.0-preview.5)
- Microsoft.EntityFrameworkCore.Sqlite (>= 8.0.18)
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.