fix: test in net 9
This commit is contained in:
@@ -2,6 +2,7 @@ using System;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.IO;
|
||||
using System.Reflection;
|
||||
using Microsoft.AspNetCore.Hosting;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Diagnostics;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
@@ -67,13 +68,16 @@ internal static class ServicesCollectionExtensions
|
||||
healthCheckBuilder.AddRedis(options.CacheConnection);
|
||||
}
|
||||
|
||||
public static IServiceCollection AddWriteDbContext(this IServiceCollection services)
|
||||
public static IServiceCollection AddWriteDbContext(this IServiceCollection services, IWebHostEnvironment environment)
|
||||
{
|
||||
services.AddDbContext<WriteDbContext>((serviceProvider, optionsBuilder) =>
|
||||
ConfigureDbContext<WriteDbContext>(serviceProvider, optionsBuilder, QueryTrackingBehavior.TrackAll));
|
||||
if (!environment.IsEnvironment("Testing"))
|
||||
{
|
||||
services.AddDbContext<WriteDbContext>((serviceProvider, optionsBuilder) =>
|
||||
ConfigureDbContext<WriteDbContext>(serviceProvider, optionsBuilder, QueryTrackingBehavior.TrackAll));
|
||||
|
||||
services.AddDbContext<EventStoreDbContext>((serviceProvider, optionsBuilder) =>
|
||||
ConfigureDbContext<EventStoreDbContext>(serviceProvider, optionsBuilder, QueryTrackingBehavior.NoTrackingWithIdentityResolution));
|
||||
services.AddDbContext<EventStoreDbContext>((serviceProvider, optionsBuilder) =>
|
||||
ConfigureDbContext<EventStoreDbContext>(serviceProvider, optionsBuilder, QueryTrackingBehavior.NoTrackingWithIdentityResolution));
|
||||
}
|
||||
|
||||
return services;
|
||||
}
|
||||
|
||||
@@ -65,7 +65,7 @@ builder.Services
|
||||
.AddInfrastructure()
|
||||
.AddCommandHandlers()
|
||||
.AddQueryHandlers()
|
||||
.AddWriteDbContext()
|
||||
.AddWriteDbContext(builder.Environment)
|
||||
.AddWriteOnlyRepositories()
|
||||
.AddReadDbContext()
|
||||
.AddReadOnlyRepositories()
|
||||
|
||||
@@ -10,9 +10,9 @@
|
||||
}
|
||||
},
|
||||
"ConnectionStrings": {
|
||||
"SqlConnection": "Server=shop-sql-server;Integrated Security=true;Initial Catalog=ShopContext;User Id=sa;Password=pMA63033n6tF;Trusted_Connection=false;MultipleActiveResultSets=true;Encrypt=True;TrustServerCertificate=True;",
|
||||
"NoSqlConnection": "mongodb://shop-mongo-server",
|
||||
"CacheConnection": "shop-redis:6379,password=pMA63033n6tF,abortConnect=false"
|
||||
"SqlConnection": "",
|
||||
"NoSqlConnection": "",
|
||||
"CacheConnection": ""
|
||||
},
|
||||
"CacheOptions": {
|
||||
"AbsoluteExpirationInHours": 2,
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data.Common;
|
||||
using System.Net;
|
||||
using System.Threading.Tasks;
|
||||
using Bogus;
|
||||
@@ -9,6 +10,7 @@ using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.Mvc.Testing;
|
||||
using Microsoft.Data.Sqlite;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Diagnostics;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.DependencyInjection.Extensions;
|
||||
using Microsoft.Extensions.Hosting;
|
||||
@@ -477,12 +479,14 @@ public class CustomersControllerTests : IAsyncLifetime
|
||||
hostBuilder.UseSetting("CacheOptions:AbsoluteExpirationInHours", "1");
|
||||
hostBuilder.UseSetting("CacheOptions:SlidingExpirationInSeconds", "30");
|
||||
|
||||
hostBuilder.UseEnvironment(Environments.Production);
|
||||
hostBuilder.UseEnvironment("Testing");
|
||||
|
||||
hostBuilder.ConfigureLogging(logging => logging.ClearProviders());
|
||||
|
||||
hostBuilder.ConfigureServices(services =>
|
||||
{
|
||||
services.RemoveAll<DbConnection>();
|
||||
services.RemoveAll<DbContextOptions>();
|
||||
services.RemoveAll<WriteDbContext>();
|
||||
services.RemoveAll<DbContextOptions<WriteDbContext>>();
|
||||
services.RemoveAll<EventStoreDbContext>();
|
||||
@@ -491,10 +495,14 @@ public class CustomersControllerTests : IAsyncLifetime
|
||||
services.RemoveAll<ISynchronizeDb>();
|
||||
|
||||
services.AddDbContext<WriteDbContext>(
|
||||
options => options.UseSqlite(_writeDbContextSqlite));
|
||||
options => options
|
||||
.UseSqlite(_writeDbContextSqlite)
|
||||
.ConfigureWarnings(warningBuilder => warningBuilder.Ignore(InMemoryEventId.TransactionIgnoredWarning)));
|
||||
|
||||
services.AddDbContext<EventStoreDbContext>(
|
||||
options => options.UseSqlite(_eventStoreDbContextSqlite));
|
||||
options => options
|
||||
.UseSqlite(_eventStoreDbContextSqlite)
|
||||
.ConfigureWarnings(warningBuilder => warningBuilder.Ignore(InMemoryEventId.TransactionIgnoredWarning)));
|
||||
|
||||
services.AddSingleton(_ => Substitute.For<IReadDbContext>());
|
||||
services.AddSingleton(_ => Substitute.For<ISynchronizeDb>());
|
||||
|
||||
Reference in New Issue
Block a user