From 375c81599ff21f5df51858f035f267cafb620578 Mon Sep 17 00:00:00 2001 From: Asenchik Oleg Date: Mon, 26 Aug 2024 14:12:31 +0300 Subject: [PATCH] .NET 8.0 --- FuelStation.Persistence/DbInitializer.cs | 6 +++--- FuelStation.Persistence/DependencyInjection.cs | 2 +- .../FuelStation.Persistence.csproj | 4 ++-- FuelStation.Persistence/FuelStationDbContext.cs | 7 +------ .../Common/FuelStationContextFactory.cs | 6 +++--- FuelStation.Tests/FuelStation.Tests.csproj | 12 ++++++------ .../Tanks/Queries/GetTankListQueryHandlerTests.cs | 12 +++--------- FuelStation.Web/FuelStation.Web.csproj | 8 ++++---- .../FuelStation.Application.csproj | 12 ++++++------ FuelStationDomain/FuelStation.Domain.csproj | 2 +- 10 files changed, 30 insertions(+), 41 deletions(-) diff --git a/FuelStation.Persistence/DbInitializer.cs b/FuelStation.Persistence/DbInitializer.cs index 47d9272..bc164dd 100644 --- a/FuelStation.Persistence/DbInitializer.cs +++ b/FuelStation.Persistence/DbInitializer.cs @@ -29,8 +29,8 @@ public static void Initialize(FuelStationDbContext context) Random randObj = new(1); //Заполнение таблицы емкостей - string[] tank_voc = { "Цистерна_", "Ведро_", "Бак_", "Фляга_", "Цистерна_" };//словарь названий емкостей - string[] material_voc = { "Сталь", "Платина", "Алюминий", "ПЭТ", "Чугун", "Алюминий", "Сталь" };//словарь названий видов топлива + string[] tank_voc = ["Цистерна_", "Ведро_", "Бак_", "Фляга_", "Цистерна_"];//словарь названий емкостей + string[] material_voc = ["Сталь", "Платина", "Алюминий", "ПЭТ", "Чугун", "Алюминий", "Сталь"];//словарь названий видов топлива int count_tank_voc = tank_voc.GetLength(0); int count_material_voc = material_voc.GetLength(0); for (int tankId = 1; tankId <= tanks_number; tankId++) @@ -46,7 +46,7 @@ public static void Initialize(FuelStationDbContext context) context.SaveChanges(); //Заполнение таблицы видов топлива - string[] fuel_voc = { "Нефть_", "Бензин_", "Керосин_", "Мазут_", "Спирт_" }; + string[] fuel_voc = ["Нефть_", "Бензин_", "Керосин_", "Мазут_", "Спирт_"]; int count_fuel_voc = fuel_voc.GetLength(0); for (int fuelId = 1; fuelId <= fuels_number; fuelId++) { diff --git a/FuelStation.Persistence/DependencyInjection.cs b/FuelStation.Persistence/DependencyInjection.cs index 5500e49..3c85dd6 100644 --- a/FuelStation.Persistence/DependencyInjection.cs +++ b/FuelStation.Persistence/DependencyInjection.cs @@ -10,7 +10,7 @@ public static class DependencyInjection public static IServiceCollection AddPersistence(this IServiceCollection services, IConfiguration configuration) { - string connectionString = configuration["DbConnection"]; + string connectionString = configuration["DbConnection"] ?? ""; services.AddDbContext(options => { options.UseSqlite(connectionString); diff --git a/FuelStation.Persistence/FuelStation.Persistence.csproj b/FuelStation.Persistence/FuelStation.Persistence.csproj index e4c5c73..d5083bf 100644 --- a/FuelStation.Persistence/FuelStation.Persistence.csproj +++ b/FuelStation.Persistence/FuelStation.Persistence.csproj @@ -1,13 +1,13 @@ - net6.0 + net8.0 enable enable - + diff --git a/FuelStation.Persistence/FuelStationDbContext.cs b/FuelStation.Persistence/FuelStationDbContext.cs index 9e46e69..b48c970 100644 --- a/FuelStation.Persistence/FuelStationDbContext.cs +++ b/FuelStation.Persistence/FuelStationDbContext.cs @@ -5,16 +5,11 @@ namespace FuelStation.Persistence { - public class FuelStationDbContext : DbContext, IFuelStationDbContext + public class FuelStationDbContext(DbContextOptions options) : DbContext(options), IFuelStationDbContext { public DbSet Fuels { get; set; } = null!; public DbSet Tanks { get; set; } = null!; public DbSet Operations { get; set; } = null!; - public FuelStationDbContext(DbContextOptions options) : base(options) - { - - - } protected override void OnModelCreating(ModelBuilder builder) { diff --git a/FuelStation.Tests/Common/FuelStationContextFactory.cs b/FuelStation.Tests/Common/FuelStationContextFactory.cs index f97f724..57515bb 100644 --- a/FuelStation.Tests/Common/FuelStationContextFactory.cs +++ b/FuelStation.Tests/Common/FuelStationContextFactory.cs @@ -32,8 +32,8 @@ public static FuelStationDbContext Create() Random randObj = new(1); //Заполнение таблицы емкостей - string[] tankDictionary = { "Цистерна_", "Ведро_", "Бак_", "Фляга_", "Цистерна_" };//словарь названий емкостей - string[] materialDictionary = { "Сталь", "Платина", "Алюминий", "ПЭТ", "Чугун", "Алюминий", "Сталь" };//словарь названий видов топлива + string[] tankDictionary = ["Цистерна_", "Ведро_", "Бак_", "Фляга_", "Цистерна_"];//словарь названий емкостей + string[] materialDictionary = ["Сталь", "Платина", "Алюминий", "ПЭТ", "Чугун", "Алюминий", "Сталь"];//словарь названий видов топлива int count_tankDictionary = tankDictionary.GetLength(0); int count_materialDictionary = materialDictionary.GetLength(0); for (int tankId = 1; tankId <= tanksNumber - 1; tankId++) @@ -70,7 +70,7 @@ public static FuelStationDbContext Create() context.SaveChanges(); //Заполнение таблицы видов топлива - string[] fuelDictionary = { "Нефть_", "Бензин_", "Керосин_", "Мазут_", "Спирт_" }; + string[] fuelDictionary = ["Нефть_", "Бензин_", "Керосин_", "Мазут_", "Спирт_"]; int count_fuelDictionary = fuelDictionary.GetLength(0); for (int fuelId = 1; fuelId <= fuelsNumber - 1; fuelId++) { diff --git a/FuelStation.Tests/FuelStation.Tests.csproj b/FuelStation.Tests/FuelStation.Tests.csproj index db31765..ad3424f 100644 --- a/FuelStation.Tests/FuelStation.Tests.csproj +++ b/FuelStation.Tests/FuelStation.Tests.csproj @@ -1,7 +1,7 @@ - net6.0 + net8.0 enable enable @@ -9,15 +9,15 @@ - - + + - - + + runtime; build; native; contentfiles; analyzers; buildtransitive all - + runtime; build; native; contentfiles; analyzers; buildtransitive all diff --git a/FuelStation.Tests/Tanks/Queries/GetTankListQueryHandlerTests.cs b/FuelStation.Tests/Tanks/Queries/GetTankListQueryHandlerTests.cs index 6fbcc39..23c43ce 100644 --- a/FuelStation.Tests/Tanks/Queries/GetTankListQueryHandlerTests.cs +++ b/FuelStation.Tests/Tanks/Queries/GetTankListQueryHandlerTests.cs @@ -7,16 +7,10 @@ namespace FuelStation.Tests.Tanks.Queries { [Collection("QueryCollection")] - public class GetTankListQueryHandlerTests + public class GetTankListQueryHandlerTests(QueryTestFixture fixture) { - private readonly FuelStationDbContext Context; - private readonly IMapper Mapper; - - public GetTankListQueryHandlerTests(QueryTestFixture fixture) - { - Context = fixture.Context; - Mapper = fixture.Mapper; - } + private readonly FuelStationDbContext Context = fixture.Context; + private readonly IMapper Mapper = fixture.Mapper; [Fact] public async Task GetTankListQueryHandler_Success() diff --git a/FuelStation.Web/FuelStation.Web.csproj b/FuelStation.Web/FuelStation.Web.csproj index f82f3f0..f973afc 100644 --- a/FuelStation.Web/FuelStation.Web.csproj +++ b/FuelStation.Web/FuelStation.Web.csproj @@ -1,7 +1,7 @@  - net6.0 + net8.0 enable enable true @@ -14,9 +14,9 @@ - - - + + + diff --git a/FuelStationApplication/FuelStation.Application.csproj b/FuelStationApplication/FuelStation.Application.csproj index aefdb7a..38260fd 100644 --- a/FuelStationApplication/FuelStation.Application.csproj +++ b/FuelStationApplication/FuelStation.Application.csproj @@ -1,17 +1,17 @@  - net6.0 + net8.0 enable enable - - - - - + + + + + diff --git a/FuelStationDomain/FuelStation.Domain.csproj b/FuelStationDomain/FuelStation.Domain.csproj index 132c02c..30402ac 100644 --- a/FuelStationDomain/FuelStation.Domain.csproj +++ b/FuelStationDomain/FuelStation.Domain.csproj @@ -1,7 +1,7 @@ - net6.0 + net8.0 enable enable