tests: add test for unit of work
This commit is contained in:
Generated
+226
@@ -0,0 +1,226 @@
|
||||
// <auto-generated />
|
||||
using System;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Infrastructure;
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
|
||||
using SanctionsSearch.Worker.Persistence;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace SanctionsSearch.Worker.Migrations
|
||||
{
|
||||
[DbContext(typeof(AppDbContext))]
|
||||
[Migration("20240822235325_add_addresses_and_comments_to_sdn")]
|
||||
partial class add_addresses_and_comments_to_sdn
|
||||
{
|
||||
/// <inheritdoc />
|
||||
protected override void BuildTargetModel(ModelBuilder modelBuilder)
|
||||
{
|
||||
#pragma warning disable 612, 618
|
||||
modelBuilder.HasAnnotation("ProductVersion", "8.0.8");
|
||||
|
||||
modelBuilder.Entity("SanctionsSearch.Worker.Models.Address", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("INTEGER");
|
||||
|
||||
b.Property<string>("CityProvincePostal")
|
||||
.IsRequired()
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<string>("Country")
|
||||
.IsRequired()
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<DateTime>("CreatedAt")
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<string>("Remarks")
|
||||
.IsRequired()
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<int>("SdnId")
|
||||
.HasColumnType("INTEGER");
|
||||
|
||||
b.Property<string>("StreetAddress")
|
||||
.IsRequired()
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<DateTime>("UpdatedAt")
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("SdnId");
|
||||
|
||||
b.ToTable("Addresses");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("SanctionsSearch.Worker.Models.Alias", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("INTEGER");
|
||||
|
||||
b.Property<DateTime>("CreatedAt")
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<string>("Name")
|
||||
.IsRequired()
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<string>("Remarks")
|
||||
.IsRequired()
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<int>("SdnId")
|
||||
.HasColumnType("INTEGER");
|
||||
|
||||
b.Property<string>("Type")
|
||||
.IsRequired()
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<DateTime>("UpdatedAt")
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("SdnId");
|
||||
|
||||
b.ToTable("Aliases");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("SanctionsSearch.Worker.Models.Comment", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("INTEGER");
|
||||
|
||||
b.Property<DateTime>("CreatedAt")
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<string>("Remarks")
|
||||
.IsRequired()
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<int>("SdnId")
|
||||
.HasColumnType("INTEGER");
|
||||
|
||||
b.Property<DateTime>("UpdatedAt")
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("SdnId");
|
||||
|
||||
b.ToTable("Comments");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("SanctionsSearch.Worker.Models.Sdn", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("INTEGER");
|
||||
|
||||
b.Property<string>("CallSign")
|
||||
.IsRequired()
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<DateTime>("CreatedAt")
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<string>("GrossRegisteredTonnage")
|
||||
.IsRequired()
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<string>("Name")
|
||||
.IsRequired()
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<string>("Program")
|
||||
.IsRequired()
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<string>("Remarks")
|
||||
.IsRequired()
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<string>("Title")
|
||||
.IsRequired()
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<string>("Tonnage")
|
||||
.IsRequired()
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<string>("Type")
|
||||
.IsRequired()
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<DateTime>("UpdatedAt")
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<string>("VesselFlag")
|
||||
.IsRequired()
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<string>("VesselOwner")
|
||||
.IsRequired()
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<string>("VesselType")
|
||||
.IsRequired()
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.ToTable("Sdns");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("SanctionsSearch.Worker.Models.Address", b =>
|
||||
{
|
||||
b.HasOne("SanctionsSearch.Worker.Models.Sdn", "Sdn")
|
||||
.WithMany("Addresses")
|
||||
.HasForeignKey("SdnId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.Navigation("Sdn");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("SanctionsSearch.Worker.Models.Alias", b =>
|
||||
{
|
||||
b.HasOne("SanctionsSearch.Worker.Models.Sdn", "Sdn")
|
||||
.WithMany("Aliases")
|
||||
.HasForeignKey("SdnId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.Navigation("Sdn");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("SanctionsSearch.Worker.Models.Comment", b =>
|
||||
{
|
||||
b.HasOne("SanctionsSearch.Worker.Models.Sdn", "Sdn")
|
||||
.WithMany("Comments")
|
||||
.HasForeignKey("SdnId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.Navigation("Sdn");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("SanctionsSearch.Worker.Models.Sdn", b =>
|
||||
{
|
||||
b.Navigation("Addresses");
|
||||
|
||||
b.Navigation("Aliases");
|
||||
|
||||
b.Navigation("Comments");
|
||||
});
|
||||
#pragma warning restore 612, 618
|
||||
}
|
||||
}
|
||||
}
|
||||
+22
@@ -0,0 +1,22 @@
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace SanctionsSearch.Worker.Migrations
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public partial class add_addresses_and_comments_to_sdn : Migration
|
||||
{
|
||||
/// <inheritdoc />
|
||||
protected override void Up(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override void Down(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -179,7 +179,7 @@ namespace SanctionsSearch.Worker.Migrations
|
||||
modelBuilder.Entity("SanctionsSearch.Worker.Models.Address", b =>
|
||||
{
|
||||
b.HasOne("SanctionsSearch.Worker.Models.Sdn", "Sdn")
|
||||
.WithMany()
|
||||
.WithMany("Addresses")
|
||||
.HasForeignKey("SdnId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
@@ -201,7 +201,7 @@ namespace SanctionsSearch.Worker.Migrations
|
||||
modelBuilder.Entity("SanctionsSearch.Worker.Models.Comment", b =>
|
||||
{
|
||||
b.HasOne("SanctionsSearch.Worker.Models.Sdn", "Sdn")
|
||||
.WithMany()
|
||||
.WithMany("Comments")
|
||||
.HasForeignKey("SdnId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
@@ -211,7 +211,11 @@ namespace SanctionsSearch.Worker.Migrations
|
||||
|
||||
modelBuilder.Entity("SanctionsSearch.Worker.Models.Sdn", b =>
|
||||
{
|
||||
b.Navigation("Addresses");
|
||||
|
||||
b.Navigation("Aliases");
|
||||
|
||||
b.Navigation("Comments");
|
||||
});
|
||||
#pragma warning restore 612, 618
|
||||
}
|
||||
|
||||
@@ -14,5 +14,7 @@ class Sdn : Entity
|
||||
public string VesselOwner { get; set; } = string.Empty;
|
||||
public string Remarks { get; set; } = string.Empty;
|
||||
|
||||
public virtual ICollection<Address> Addresses { get; set; } = [];
|
||||
public virtual ICollection<Alias> Aliases { get; set; } = [];
|
||||
public virtual ICollection<Comment> Comments { get; set; } = [];
|
||||
}
|
||||
@@ -1,8 +1,8 @@
|
||||
namespace SanctionsSearch.Worker.Persistence;
|
||||
|
||||
class EfUnitOfWork(AppDbContext context, ILoggerFactory loggerFactory) : IUnitOfWork, IAsyncDisposable
|
||||
class EfUnitOfWork(DbContext context, ILoggerFactory loggerFactory) : IUnitOfWork, IAsyncDisposable
|
||||
{
|
||||
private readonly AppDbContext _context = context;
|
||||
private readonly DbContext _context = context;
|
||||
public ISdnRepository Sdns { get; } = new SdnRepository(context, loggerFactory.CreateLogger<SdnRepository>());
|
||||
public IAddressRepository Addresses { get; } = new AddressRepository(context, loggerFactory.CreateLogger<AddressRepository>());
|
||||
public IAliasRepository Aliases { get; } = new AliasRepository(context, loggerFactory.CreateLogger<AliasRepository>());
|
||||
|
||||
@@ -63,14 +63,14 @@ class Program
|
||||
builder.Services.AddScoped(rs => rs.GetRequiredService<IOptionsSnapshot<DbOptions>>().Value);
|
||||
|
||||
builder.Services.AddSingleton(TimeProvider.System);
|
||||
builder.Services.AddScoped<IOfacFileService, OfacFileService>();
|
||||
// builder.Services.AddScoped<IOfacFileService, OfacFileService>();
|
||||
|
||||
builder.Services.AddScoped<ISdnRepository, SdnRepository>();
|
||||
builder.Services.AddScoped<IAddressRepository, AddressRepository>();
|
||||
builder.Services.AddScoped<IAliasRepository, AliasRepository>();
|
||||
builder.Services.AddScoped<ICommentRepository, CommentRepository>();
|
||||
builder.Services.AddScoped<IUnitOfWork, EfUnitOfWork>();
|
||||
builder.Services.AddDbContext<AppDbContext>();
|
||||
builder.Services.AddDbContext<DbContext, AppDbContext>();
|
||||
|
||||
builder.Services.AddHostedService<Worker>();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user