diff --git a/Directory.Build.props b/Directory.Build.props index a1a2c26d3..ee9eb6a7b 100644 --- a/Directory.Build.props +++ b/Directory.Build.props @@ -3,6 +3,7 @@ 10.0.0 net10.0 latest + enable true latest NU5105 diff --git a/src/Directory.Build.props b/src/Directory.Build.props index 609d0a4e7..b5e6b77b5 100644 --- a/src/Directory.Build.props +++ b/src/Directory.Build.props @@ -5,7 +5,6 @@ true snupkg true - enable nullablePublicOnly diff --git a/test/EFCore.PG.FunctionalTests/BadDataJsonDeserializationNpgsqlTest.cs b/test/EFCore.PG.FunctionalTests/BadDataJsonDeserializationNpgsqlTest.cs index dcf301eba..29e0cfa28 100644 --- a/test/EFCore.PG.FunctionalTests/BadDataJsonDeserializationNpgsqlTest.cs +++ b/test/EFCore.PG.FunctionalTests/BadDataJsonDeserializationNpgsqlTest.cs @@ -1,5 +1,3 @@ -#nullable enable - namespace Npgsql.EntityFrameworkCore.PostgreSQL; public class BadDataJsonDeserializationSqlServerTest : BadDataJsonDeserializationTestBase diff --git a/test/EFCore.PG.FunctionalTests/BatchingTest.cs b/test/EFCore.PG.FunctionalTests/BatchingTest.cs index f7c87c74d..5f3fe5761 100644 --- a/test/EFCore.PG.FunctionalTests/BatchingTest.cs +++ b/test/EFCore.PG.FunctionalTests/BatchingTest.cs @@ -7,6 +7,8 @@ // ReSharper disable InconsistentNaming namespace Npgsql.EntityFrameworkCore.PostgreSQL; +#nullable disable + public class BatchingTest(BatchingTest.BatchingTestFixture fixture) : IClassFixture { protected BatchingTestFixture Fixture { get; } = fixture; diff --git a/test/EFCore.PG.FunctionalTests/BuiltInDataTypesNpgsqlTest.cs b/test/EFCore.PG.FunctionalTests/BuiltInDataTypesNpgsqlTest.cs index 99c1a5996..59433e393 100644 --- a/test/EFCore.PG.FunctionalTests/BuiltInDataTypesNpgsqlTest.cs +++ b/test/EFCore.PG.FunctionalTests/BuiltInDataTypesNpgsqlTest.cs @@ -5,6 +5,8 @@ namespace Npgsql.EntityFrameworkCore.PostgreSQL; +#nullable disable + public class BuiltInDataTypesNpgsqlTest : BuiltInDataTypesTestBase { // ReSharper disable once UnusedParameter.Local diff --git a/test/EFCore.PG.FunctionalTests/BulkUpdates/NonSharedModelBulkUpdatesNpgsqlTest.cs b/test/EFCore.PG.FunctionalTests/BulkUpdates/NonSharedModelBulkUpdatesNpgsqlTest.cs index 6672c16b7..55b9460fe 100644 --- a/test/EFCore.PG.FunctionalTests/BulkUpdates/NonSharedModelBulkUpdatesNpgsqlTest.cs +++ b/test/EFCore.PG.FunctionalTests/BulkUpdates/NonSharedModelBulkUpdatesNpgsqlTest.cs @@ -236,7 +236,7 @@ protected class Context3001(DbContextOptions options) : DbContext(options) protected class EntityWithPrimitiveCollection { public int Id { get; set; } - public List Tags { get; set; } + public List Tags { get; set; } = null!; } public override async Task Delete_with_view_mapping(bool async) diff --git a/test/EFCore.PG.FunctionalTests/ComputedColumnTest.cs b/test/EFCore.PG.FunctionalTests/ComputedColumnTest.cs index 5c3c86cab..49f767528 100644 --- a/test/EFCore.PG.FunctionalTests/ComputedColumnTest.cs +++ b/test/EFCore.PG.FunctionalTests/ComputedColumnTest.cs @@ -134,7 +134,7 @@ public void Can_use_computed_columns_with_nullable_enum() Assert.Equal(FlagEnum.AValue | FlagEnum.BValue, entity.CalculatedFlagEnum); } - protected NpgsqlTestStore TestStore { get; private set; } + protected NpgsqlTestStore TestStore { get; private set; } = null!; public async Task InitializeAsync() => TestStore = await NpgsqlTestStore.CreateInitializedAsync("ComputedColumnTest"); diff --git a/test/EFCore.PG.FunctionalTests/ConferencePlannerNpgsqlTest.cs b/test/EFCore.PG.FunctionalTests/ConferencePlannerNpgsqlTest.cs index fbfe6f2c2..eed20e42f 100644 --- a/test/EFCore.PG.FunctionalTests/ConferencePlannerNpgsqlTest.cs +++ b/test/EFCore.PG.FunctionalTests/ConferencePlannerNpgsqlTest.cs @@ -4,6 +4,8 @@ namespace Npgsql.EntityFrameworkCore.PostgreSQL; +#nullable disable + public class ConferencePlannerNpgsqlTest(ConferencePlannerNpgsqlTest.ConferencePlannerNpgsqlFixture fixture) : ConferencePlannerTestBase(fixture) { diff --git a/test/EFCore.PG.FunctionalTests/ConnectionInterceptionNpgsqlTest.cs b/test/EFCore.PG.FunctionalTests/ConnectionInterceptionNpgsqlTest.cs index 2d8f44e13..c111fc4e1 100644 --- a/test/EFCore.PG.FunctionalTests/ConnectionInterceptionNpgsqlTest.cs +++ b/test/EFCore.PG.FunctionalTests/ConnectionInterceptionNpgsqlTest.cs @@ -1,5 +1,6 @@ using System.Data; using System.Data.Common; +using System.Diagnostics.CodeAnalysis; using Npgsql.EntityFrameworkCore.PostgreSQL.TestUtilities; namespace Npgsql.EntityFrameworkCore.PostgreSQL; @@ -45,6 +46,7 @@ protected override BadUniverseContext CreateBadUniverse(DbContextOptionsBuilder public class FakeDbConnection : DbConnection { + [AllowNull] public override string ConnectionString { get; set; } public override string Database diff --git a/test/EFCore.PG.FunctionalTests/ConnectionSpecificationTest.cs b/test/EFCore.PG.FunctionalTests/ConnectionSpecificationTest.cs index 2cac8e343..f75b6186d 100644 --- a/test/EFCore.PG.FunctionalTests/ConnectionSpecificationTest.cs +++ b/test/EFCore.PG.FunctionalTests/ConnectionSpecificationTest.cs @@ -4,6 +4,8 @@ // ReSharper disable StringLiteralTypo namespace Npgsql.EntityFrameworkCore.PostgreSQL; +#nullable disable + public class ConnectionSpecificationTest { [Fact] diff --git a/test/EFCore.PG.FunctionalTests/DefaultValuesTest.cs b/test/EFCore.PG.FunctionalTests/DefaultValuesTest.cs index 611655a01..6a7977d94 100644 --- a/test/EFCore.PG.FunctionalTests/DefaultValuesTest.cs +++ b/test/EFCore.PG.FunctionalTests/DefaultValuesTest.cs @@ -69,7 +69,7 @@ private class KettleChips { // ReSharper disable once UnusedMember.Local public int Id { get; set; } - public string Name { get; set; } + public string Name { get; set; } = null!; public DateTime BestBuyDate { get; set; } } } diff --git a/test/EFCore.PG.FunctionalTests/ExecutionStrategyTest.cs b/test/EFCore.PG.FunctionalTests/ExecutionStrategyTest.cs index f488081c6..542f95432 100644 --- a/test/EFCore.PG.FunctionalTests/ExecutionStrategyTest.cs +++ b/test/EFCore.PG.FunctionalTests/ExecutionStrategyTest.cs @@ -7,6 +7,8 @@ // ReSharper disable AccessToDisposedClosure namespace Npgsql.EntityFrameworkCore.PostgreSQL; +#nullable disable + public class ExecutionStrategyTest : IClassFixture { public ExecutionStrategyTest(ExecutionStrategyFixture fixture) diff --git a/test/EFCore.PG.FunctionalTests/ExistingConnectionTest.cs b/test/EFCore.PG.FunctionalTests/ExistingConnectionTest.cs index abbe8f3f5..f7b2fcffc 100644 --- a/test/EFCore.PG.FunctionalTests/ExistingConnectionTest.cs +++ b/test/EFCore.PG.FunctionalTests/ExistingConnectionTest.cs @@ -93,12 +93,12 @@ protected override void OnModelCreating(ModelBuilder modelBuilder) private class Customer { // ReSharper disable once UnusedAutoPropertyAccessor.Local - public string CustomerId { get; set; } + public string CustomerId { get; set; } = null!; // ReSharper disable once UnusedMember.Local - public string CompanyName { get; set; } + public string CompanyName { get; set; } = null!; // ReSharper disable once UnusedMember.Local - public string Fax { get; set; } + public string Fax { get; set; } = null!; } } diff --git a/test/EFCore.PG.FunctionalTests/F1NpgsqlFixture.cs b/test/EFCore.PG.FunctionalTests/F1NpgsqlFixture.cs index 91be0a0e5..3281de74b 100644 --- a/test/EFCore.PG.FunctionalTests/F1NpgsqlFixture.cs +++ b/test/EFCore.PG.FunctionalTests/F1NpgsqlFixture.cs @@ -34,15 +34,15 @@ protected override void BuildModelExternal(ModelBuilder modelBuilder) base.BuildModelExternal(modelBuilder); // TODO: This is a hack to work around, remove in 8.0 after https://github.com/dotnet/efcore/pull/29401 - modelBuilder.Entity().Property("Version").HasConversion((ValueConverter)null); - modelBuilder.Entity().Property("Version").HasConversion((ValueConverter)null); - modelBuilder.Entity().Property("Version").HasConversion((ValueConverter)null); - modelBuilder.Entity().Property("Version").HasConversion((ValueConverter)null); + modelBuilder.Entity().Property("Version").HasConversion((ValueConverter?)null); + modelBuilder.Entity().Property("Version").HasConversion((ValueConverter?)null); + modelBuilder.Entity().Property("Version").HasConversion((ValueConverter?)null); + modelBuilder.Entity().Property("Version").HasConversion((ValueConverter?)null); modelBuilder.Entity() .OwnsOne( s => s.Details, eb => { - eb.Property("Version").IsRowVersion().HasConversion((ValueConverter)null); + eb.Property("Version").IsRowVersion().HasConversion((ValueConverter?)null); }); } } diff --git a/test/EFCore.PG.FunctionalTests/JsonTypesNpgsqlTest.cs b/test/EFCore.PG.FunctionalTests/JsonTypesNpgsqlTest.cs index 1f15efa71..f3b5b20d2 100644 --- a/test/EFCore.PG.FunctionalTests/JsonTypesNpgsqlTest.cs +++ b/test/EFCore.PG.FunctionalTests/JsonTypesNpgsqlTest.cs @@ -1,5 +1,3 @@ -#nullable enable - using System.Collections; using System.Globalization; using System.Numerics; diff --git a/test/EFCore.PG.FunctionalTests/LazyLoadProxyNpgsqlTest.cs b/test/EFCore.PG.FunctionalTests/LazyLoadProxyNpgsqlTest.cs index 77f463f4f..b299a9f9b 100644 --- a/test/EFCore.PG.FunctionalTests/LazyLoadProxyNpgsqlTest.cs +++ b/test/EFCore.PG.FunctionalTests/LazyLoadProxyNpgsqlTest.cs @@ -25,7 +25,7 @@ protected override void RecordLog() => Sql = Fixture.TestSqlLoggerFactory.Sql; // ReSharper disable once UnusedAutoPropertyAccessor.Local - private string Sql { get; set; } + private string Sql { get; set; } = null!; #region Expected JSON override diff --git a/test/EFCore.PG.FunctionalTests/LoadNpgsqlTest.cs b/test/EFCore.PG.FunctionalTests/LoadNpgsqlTest.cs index 3a982ba6c..1b11afc96 100644 --- a/test/EFCore.PG.FunctionalTests/LoadNpgsqlTest.cs +++ b/test/EFCore.PG.FunctionalTests/LoadNpgsqlTest.cs @@ -18,7 +18,7 @@ protected override void RecordLog() => Sql = Fixture.TestSqlLoggerFactory.Sql; // ReSharper disable once UnusedAutoPropertyAccessor.Local - private string Sql { get; set; } + private string Sql { get; set; } = null!; public class LoadNpgsqlFixture : LoadFixtureBase { diff --git a/test/EFCore.PG.FunctionalTests/LoggingNpgsqlTest.cs b/test/EFCore.PG.FunctionalTests/LoggingNpgsqlTest.cs index a495a96cb..ad77a5eb3 100644 --- a/test/EFCore.PG.FunctionalTests/LoggingNpgsqlTest.cs +++ b/test/EFCore.PG.FunctionalTests/LoggingNpgsqlTest.cs @@ -72,5 +72,5 @@ protected override string ProviderName protected override string ProviderVersion => typeof(NpgsqlOptionsExtension).Assembly - .GetCustomAttribute()?.InformationalVersion; + .GetCustomAttribute()?.InformationalVersion!; } diff --git a/test/EFCore.PG.FunctionalTests/MaterializationInterceptionNpgsqlTest.cs b/test/EFCore.PG.FunctionalTests/MaterializationInterceptionNpgsqlTest.cs index 1e44c27db..503a23f5d 100644 --- a/test/EFCore.PG.FunctionalTests/MaterializationInterceptionNpgsqlTest.cs +++ b/test/EFCore.PG.FunctionalTests/MaterializationInterceptionNpgsqlTest.cs @@ -1,5 +1,3 @@ -#nullable enable - using Npgsql.EntityFrameworkCore.PostgreSQL.TestUtilities; namespace Npgsql.EntityFrameworkCore.PostgreSQL; diff --git a/test/EFCore.PG.FunctionalTests/Migrations/MigrationsInfrastructureNpgsqlTest.cs b/test/EFCore.PG.FunctionalTests/Migrations/MigrationsInfrastructureNpgsqlTest.cs index 542d3ddda..1675c11db 100644 --- a/test/EFCore.PG.FunctionalTests/Migrations/MigrationsInfrastructureNpgsqlTest.cs +++ b/test/EFCore.PG.FunctionalTests/Migrations/MigrationsInfrastructureNpgsqlTest.cs @@ -2,6 +2,8 @@ using Npgsql.EntityFrameworkCore.PostgreSQL.Storage.Internal; using Npgsql.EntityFrameworkCore.PostgreSQL.TestUtilities; +#nullable disable + namespace Npgsql.EntityFrameworkCore.PostgreSQL.Migrations { public class MigrationsInfrastructureNpgsqlTest(MigrationsInfrastructureNpgsqlTest.MigrationsInfrastructureNpgsqlFixture fixture) diff --git a/test/EFCore.PG.FunctionalTests/Migrations/MigrationsNpgsqlTest.cs b/test/EFCore.PG.FunctionalTests/Migrations/MigrationsNpgsqlTest.cs index 82918f6b8..f92cb4799 100644 --- a/test/EFCore.PG.FunctionalTests/Migrations/MigrationsNpgsqlTest.cs +++ b/test/EFCore.PG.FunctionalTests/Migrations/MigrationsNpgsqlTest.cs @@ -1,6 +1,4 @@ -#nullable enable - -using Npgsql.EntityFrameworkCore.PostgreSQL.Infrastructure; +using Npgsql.EntityFrameworkCore.PostgreSQL.Infrastructure; using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata.Internal; using Npgsql.EntityFrameworkCore.PostgreSQL.Scaffolding.Internal; diff --git a/test/EFCore.PG.FunctionalTests/Migrations/NpgsqlMigrationsSqlGeneratorTest.cs b/test/EFCore.PG.FunctionalTests/Migrations/NpgsqlMigrationsSqlGeneratorTest.cs index 0b3dc8292..a5881dec1 100644 --- a/test/EFCore.PG.FunctionalTests/Migrations/NpgsqlMigrationsSqlGeneratorTest.cs +++ b/test/EFCore.PG.FunctionalTests/Migrations/NpgsqlMigrationsSqlGeneratorTest.cs @@ -615,7 +615,7 @@ public override void InsertDataOperation_throws_for_unsupported_column_types() Schema = "dbo", Columns = ["First Name"], ColumnTypes = ["foo"], - Values = new object[,] { { null } } + Values = new object?[,] { { null } } })).Message); #pragma warning restore 618 diff --git a/test/EFCore.PG.FunctionalTests/ModelBuilding/NpgsqlModelBuilderGenericTest.cs b/test/EFCore.PG.FunctionalTests/ModelBuilding/NpgsqlModelBuilderGenericTest.cs index 9478c332d..588c94336 100644 --- a/test/EFCore.PG.FunctionalTests/ModelBuilding/NpgsqlModelBuilderGenericTest.cs +++ b/test/EFCore.PG.FunctionalTests/ModelBuilding/NpgsqlModelBuilderGenericTest.cs @@ -2,8 +2,6 @@ namespace Npgsql.EntityFrameworkCore.PostgreSQL.ModelBuilding; -#nullable enable - public class NpgsqlModelBuilderGenericTest : NpgsqlModelBuilderTestBase { public class NpgsqlGenericNonRelationship(NpgsqlModelBuilderFixture fixture) : NpgsqlNonRelationship(fixture) diff --git a/test/EFCore.PG.FunctionalTests/ModelBuilding/NpgsqlModelBuilderTestBase.cs b/test/EFCore.PG.FunctionalTests/ModelBuilding/NpgsqlModelBuilderTestBase.cs index afce39d7a..59ba51863 100644 --- a/test/EFCore.PG.FunctionalTests/ModelBuilding/NpgsqlModelBuilderTestBase.cs +++ b/test/EFCore.PG.FunctionalTests/ModelBuilding/NpgsqlModelBuilderTestBase.cs @@ -1,5 +1,3 @@ -#nullable enable - using Microsoft.EntityFrameworkCore.ModelBuilding; using Npgsql.EntityFrameworkCore.PostgreSQL.TestUtilities; diff --git a/test/EFCore.PG.FunctionalTests/NpgsqlApiConsistencyTest.cs b/test/EFCore.PG.FunctionalTests/NpgsqlApiConsistencyTest.cs index 5b331b827..bb0b363e2 100644 --- a/test/EFCore.PG.FunctionalTests/NpgsqlApiConsistencyTest.cs +++ b/test/EFCore.PG.FunctionalTests/NpgsqlApiConsistencyTest.cs @@ -3,6 +3,8 @@ namespace Npgsql.EntityFrameworkCore.PostgreSQL; +#nullable disable + public class NpgsqlApiConsistencyTest(NpgsqlApiConsistencyTest.NpgsqlApiConsistencyFixture fixture) : ApiConsistencyTestBase(fixture) { diff --git a/test/EFCore.PG.FunctionalTests/NpgsqlDatabaseCreatorTest.cs b/test/EFCore.PG.FunctionalTests/NpgsqlDatabaseCreatorTest.cs index 9954a7b15..f3fcb04c3 100644 --- a/test/EFCore.PG.FunctionalTests/NpgsqlDatabaseCreatorTest.cs +++ b/test/EFCore.PG.FunctionalTests/NpgsqlDatabaseCreatorTest.cs @@ -7,6 +7,8 @@ namespace Npgsql.EntityFrameworkCore.PostgreSQL; +#nullable disable + public class NpgsqlDatabaseCreatorExistsTest : NpgsqlDatabaseCreatorTest { [ConditionalTheory] diff --git a/test/EFCore.PG.FunctionalTests/NpgsqlValueGenerationScenariosTest.cs b/test/EFCore.PG.FunctionalTests/NpgsqlValueGenerationScenariosTest.cs index bf6b1ca0d..276896683 100644 --- a/test/EFCore.PG.FunctionalTests/NpgsqlValueGenerationScenariosTest.cs +++ b/test/EFCore.PG.FunctionalTests/NpgsqlValueGenerationScenariosTest.cs @@ -3,6 +3,8 @@ namespace Npgsql.EntityFrameworkCore.PostgreSQL; +#nullable disable + public class NpgsqlValueGenerationScenariosTest { private static readonly string DatabaseName = "NpgsqlValueGenerationScenariosTest"; diff --git a/test/EFCore.PG.FunctionalTests/OptimisticConcurrencyNpgsqlTest.cs b/test/EFCore.PG.FunctionalTests/OptimisticConcurrencyNpgsqlTest.cs index e68095f3c..4162f307d 100644 --- a/test/EFCore.PG.FunctionalTests/OptimisticConcurrencyNpgsqlTest.cs +++ b/test/EFCore.PG.FunctionalTests/OptimisticConcurrencyNpgsqlTest.cs @@ -2,6 +2,8 @@ namespace Npgsql.EntityFrameworkCore.PostgreSQL; +#nullable disable + public class OptimisticConcurrencyBytesNpgsqlTest(F1BytesNpgsqlFixture fixture) : OptimisticConcurrencyNpgsqlTestBase(fixture); diff --git a/test/EFCore.PG.FunctionalTests/Query/AdHocJsonQueryNpgsqlTest.cs b/test/EFCore.PG.FunctionalTests/Query/AdHocJsonQueryNpgsqlTest.cs index 9dd0570f6..2893cc60a 100644 --- a/test/EFCore.PG.FunctionalTests/Query/AdHocJsonQueryNpgsqlTest.cs +++ b/test/EFCore.PG.FunctionalTests/Query/AdHocJsonQueryNpgsqlTest.cs @@ -2,6 +2,8 @@ namespace Npgsql.EntityFrameworkCore.PostgreSQL.Query; +#nullable disable + public class AdHocJsonQueryNpgsqlTest : AdHocJsonQueryTestBase { protected override ITestStoreFactory TestStoreFactory diff --git a/test/EFCore.PG.FunctionalTests/Query/AdHocQuerySplittingQueryNpgsqlTest.cs b/test/EFCore.PG.FunctionalTests/Query/AdHocQuerySplittingQueryNpgsqlTest.cs index 927fe2ff8..d5c4a9e25 100644 --- a/test/EFCore.PG.FunctionalTests/Query/AdHocQuerySplittingQueryNpgsqlTest.cs +++ b/test/EFCore.PG.FunctionalTests/Query/AdHocQuerySplittingQueryNpgsqlTest.cs @@ -4,6 +4,8 @@ namespace Npgsql.EntityFrameworkCore.PostgreSQL.Query; +#nullable disable + public class AdHocQuerySplittingQueryNpgsqlTest : AdHocQuerySplittingQueryTestBase { protected override DbContextOptionsBuilder SetQuerySplittingBehavior( diff --git a/test/EFCore.PG.FunctionalTests/Query/ArrayArrayQueryTest.cs b/test/EFCore.PG.FunctionalTests/Query/ArrayArrayQueryTest.cs index d0226d174..e6af296bf 100644 --- a/test/EFCore.PG.FunctionalTests/Query/ArrayArrayQueryTest.cs +++ b/test/EFCore.PG.FunctionalTests/Query/ArrayArrayQueryTest.cs @@ -235,7 +235,7 @@ public override void Array_column_Contains_null_parameter_does_not_work() { using var ctx = CreateContext(); - string p = null; + string? p = null; // We incorrectly miss arrays containing non-constant nulls, because detecting those // would prevent index use. @@ -642,7 +642,7 @@ await AssertQuery( ss => ss.Set() .Where(e => new[] { "a%", "b%", "c%" }.Any(p => EF.Functions.Like(e.NullableText, p))), ss => ss.Set() - .Where(e => new[] { "a", "b", "c" }.Any(p => e.NullableText.StartsWith(p, StringComparison.Ordinal)))); + .Where(e => new[] { "a", "b", "c" }.Any(p => e.NullableText!.StartsWith(p, StringComparison.Ordinal)))); AssertSql( """ @@ -657,9 +657,9 @@ public override async Task Any_ilike(bool async) await AssertQuery( async, ss => ss.Set() - .Where(e => new[] { "a%", "b%", "c%" }.Any(p => EF.Functions.ILike(e.NullableText, p))), + .Where(e => new[] { "a%", "b%", "c%" }.Any(p => EF.Functions.ILike(e.NullableText!, p))), ss => ss.Set() - .Where(e => new[] { "a", "b", "c" }.Any(p => e.NullableText.StartsWith(p, StringComparison.OrdinalIgnoreCase)))); + .Where(e => new[] { "a", "b", "c" }.Any(p => e.NullableText!.StartsWith(p, StringComparison.OrdinalIgnoreCase)))); AssertSql( """ @@ -681,7 +681,7 @@ await AssertQuery( ss => ss.Set() .Where(e => patternsActual.Any(p => EF.Functions.Like(e.NullableText, p))), ss => ss.Set() - .Where(e => patternsExpected.Any(p => e.NullableText.StartsWith(p, StringComparison.Ordinal)))); + .Where(e => patternsExpected.Any(p => e.NullableText!.StartsWith(p, StringComparison.Ordinal)))); AssertSql( """ @@ -700,7 +700,7 @@ await AssertQuery( ss => ss.Set() .Where(e => new[] { "b%", "ba%" }.All(p => EF.Functions.Like(e.NullableText, p))), ss => ss.Set() - .Where(e => new[] { "b", "ba" }.All(p => e.NullableText.StartsWith(p, StringComparison.Ordinal)))); + .Where(e => new[] { "b", "ba" }.All(p => e.NullableText!.StartsWith(p, StringComparison.Ordinal)))); AssertSql( """ @@ -715,9 +715,9 @@ public override async Task All_ilike(bool async) await AssertQuery( async, ss => ss.Set() - .Where(e => new[] { "B%", "ba%" }.All(p => EF.Functions.ILike(e.NullableText, p))), + .Where(e => new[] { "B%", "ba%" }.All(p => EF.Functions.ILike(e.NullableText!, p))), ss => ss.Set() - .Where(e => new[] { "B", "ba" }.All(p => e.NullableText.StartsWith(p, StringComparison.OrdinalIgnoreCase)))); + .Where(e => new[] { "B", "ba" }.All(p => e.NullableText!.StartsWith(p, StringComparison.OrdinalIgnoreCase)))); AssertSql( """ diff --git a/test/EFCore.PG.FunctionalTests/Query/ArrayListQueryTest.cs b/test/EFCore.PG.FunctionalTests/Query/ArrayListQueryTest.cs index 896060c8f..8cc4c46f7 100644 --- a/test/EFCore.PG.FunctionalTests/Query/ArrayListQueryTest.cs +++ b/test/EFCore.PG.FunctionalTests/Query/ArrayListQueryTest.cs @@ -224,13 +224,13 @@ public override void Array_column_Contains_null_parameter_does_not_work() { using var ctx = CreateContext(); - string p = null; + string? p = null; // We incorrectly miss arrays containing non-constant nulls, because detecting those // would prevent index use. Assert.Equal( 0, - ctx.SomeEntities.Count(e => e.StringList.Contains(p))); + ctx.SomeEntities.Count(e => e.StringList.Contains(p!))); AssertSql( """ @@ -272,7 +272,7 @@ public override async Task Array_param_Contains_nullable_column(bool async) await AssertQuery( async, - ss => ss.Set().Where(e => array.Contains(e.NullableText))); + ss => ss.Set().Where(e => array.Contains(e.NullableText!))); AssertSql( """ @@ -306,7 +306,7 @@ public override void Array_param_with_null_Contains_non_nullable_not_found() { using var ctx = CreateContext(); - var array = new List + var array = new List { "unknown1", "unknown2", @@ -329,7 +329,7 @@ public override void Array_param_with_null_Contains_non_nullable_not_found_negat { using var ctx = CreateContext(); - var array = new List + var array = new List { "unknown1", "unknown2", @@ -352,7 +352,7 @@ public override void Array_param_with_null_Contains_nullable_not_found() { using var ctx = CreateContext(); - var array = new List + var array = new List { "unknown1", "unknown2", @@ -375,14 +375,14 @@ public override void Array_param_with_null_Contains_nullable_not_found_negated() { using var ctx = CreateContext(); - var array = new List + var array = new List { "unknown1", "unknown2", null }; - Assert.Equal(2, ctx.SomeEntities.Count(e => !array.Contains(e.NullableText))); + Assert.Equal(2, ctx.SomeEntities.Count(e => !array.Contains(e.NullableText!))); AssertSql( """ @@ -650,7 +650,7 @@ await AssertQuery( ss => ss.Set() .Where(e => new[] { "a%", "b%", "c%" }.Any(p => EF.Functions.Like(e.NullableText, p))), ss => ss.Set() - .Where(e => new[] { "a", "b", "c" }.Any(p => e.NullableText.StartsWith(p, StringComparison.Ordinal)))); + .Where(e => new[] { "a", "b", "c" }.Any(p => e.NullableText!.StartsWith(p, StringComparison.Ordinal)))); AssertSql( """ @@ -665,9 +665,9 @@ public override async Task Any_ilike(bool async) await AssertQuery( async, ss => ss.Set() - .Where(e => new[] { "a%", "b%", "c%" }.Any(p => EF.Functions.ILike(e.NullableText, p))), + .Where(e => new[] { "a%", "b%", "c%" }.Any(p => EF.Functions.ILike(e.NullableText!, p))), ss => ss.Set() - .Where(e => new[] { "a", "b", "c" }.Any(p => e.NullableText.StartsWith(p, StringComparison.OrdinalIgnoreCase)))); + .Where(e => new[] { "a", "b", "c" }.Any(p => e.NullableText!.StartsWith(p, StringComparison.OrdinalIgnoreCase)))); AssertSql( """ @@ -699,7 +699,7 @@ await AssertQuery( ss => ss.Set() .Where(e => patternsActual.Any(p => EF.Functions.Like(e.NullableText, p))), ss => ss.Set() - .Where(e => patternsExpected.Any(p => e.NullableText.StartsWith(p, StringComparison.Ordinal)))); + .Where(e => patternsExpected.Any(p => e.NullableText!.StartsWith(p, StringComparison.Ordinal)))); AssertSql( """ @@ -718,7 +718,7 @@ await AssertQuery( ss => ss.Set() .Where(e => new List { "b%", "ba%" }.All(p => EF.Functions.Like(e.NullableText, p))), ss => ss.Set() - .Where(e => new List { "b", "ba" }.All(p => e.NullableText.StartsWith(p, StringComparison.Ordinal)))); + .Where(e => new List { "b", "ba" }.All(p => e.NullableText!.StartsWith(p, StringComparison.Ordinal)))); AssertSql( """ @@ -733,9 +733,9 @@ public override async Task All_ilike(bool async) await AssertQuery( async, ss => ss.Set() - .Where(e => new List { "B%", "ba%" }.All(p => EF.Functions.ILike(e.NullableText, p))), + .Where(e => new List { "B%", "ba%" }.All(p => EF.Functions.ILike(e.NullableText!, p))), ss => ss.Set() - .Where(e => new List { "B", "ba" }.All(p => e.NullableText.StartsWith(p, StringComparison.OrdinalIgnoreCase)))); + .Where(e => new List { "B", "ba" }.All(p => e.NullableText!.StartsWith(p, StringComparison.OrdinalIgnoreCase)))); AssertSql( """ @@ -931,34 +931,34 @@ protected override Expression RewriteServerQueryExpression(Expression serverQuer private class ArrayToListReplacingExpressionVisitor : ExpressionVisitor { private static readonly PropertyInfo IntArray - = typeof(ArrayEntity).GetProperty(nameof(ArrayEntity.IntArray)); + = typeof(ArrayEntity).GetProperty(nameof(ArrayEntity.IntArray))!; private static readonly PropertyInfo NullableIntArray - = typeof(ArrayEntity).GetProperty(nameof(ArrayEntity.NullableIntArray)); + = typeof(ArrayEntity).GetProperty(nameof(ArrayEntity.NullableIntArray))!; private static readonly PropertyInfo IntList - = typeof(ArrayEntity).GetProperty(nameof(ArrayEntity.IntList)); + = typeof(ArrayEntity).GetProperty(nameof(ArrayEntity.IntList))!; private static readonly PropertyInfo NullableIntList - = typeof(ArrayEntity).GetProperty(nameof(ArrayEntity.NullableIntList)); + = typeof(ArrayEntity).GetProperty(nameof(ArrayEntity.NullableIntList))!; private static readonly PropertyInfo StringArray - = typeof(ArrayEntity).GetProperty(nameof(ArrayEntity.StringArray)); + = typeof(ArrayEntity).GetProperty(nameof(ArrayEntity.StringArray))!; private static readonly PropertyInfo NullableStringArray - = typeof(ArrayEntity).GetProperty(nameof(ArrayEntity.NullableStringArray)); + = typeof(ArrayEntity).GetProperty(nameof(ArrayEntity.NullableStringArray))!; private static readonly PropertyInfo StringList - = typeof(ArrayEntity).GetProperty(nameof(ArrayEntity.StringList)); + = typeof(ArrayEntity).GetProperty(nameof(ArrayEntity.StringList))!; private static readonly PropertyInfo NullableStringList - = typeof(ArrayEntity).GetProperty(nameof(ArrayEntity.NullableStringList)); + = typeof(ArrayEntity).GetProperty(nameof(ArrayEntity.NullableStringList))!; private static readonly PropertyInfo ValueConvertedArrayOfEnum - = typeof(ArrayEntity).GetProperty(nameof(ArrayEntity.ValueConvertedArrayOfEnum)); + = typeof(ArrayEntity).GetProperty(nameof(ArrayEntity.ValueConvertedArrayOfEnum))!; private static readonly PropertyInfo ValueConvertedListOfEnum - = typeof(ArrayEntity).GetProperty(nameof(ArrayEntity.ValueConvertedListOfEnum)); + = typeof(ArrayEntity).GetProperty(nameof(ArrayEntity.ValueConvertedListOfEnum))!; protected override Expression VisitMember(MemberExpression node) { diff --git a/test/EFCore.PG.FunctionalTests/Query/ArrayQueryFixture.cs b/test/EFCore.PG.FunctionalTests/Query/ArrayQueryFixture.cs index 1809ce560..7a0e02122 100644 --- a/test/EFCore.PG.FunctionalTests/Query/ArrayQueryFixture.cs +++ b/test/EFCore.PG.FunctionalTests/Query/ArrayQueryFixture.cs @@ -11,7 +11,7 @@ protected override ITestStoreFactory TestStoreFactory public TestSqlLoggerFactory TestSqlLoggerFactory => (TestSqlLoggerFactory)ListLoggerFactory; - private ArrayQueryData _expectedData; + private ArrayQueryData? _expectedData; public override DbContextOptionsBuilder AddOptions(DbContextOptionsBuilder builder) => base.AddOptions(builder).ConfigureWarnings(wcb => wcb.Ignore(CoreEventId.CollectionWithoutComparer)); @@ -26,9 +26,9 @@ public ISetSource GetExpectedData() => _expectedData ??= new ArrayQueryData(); public IReadOnlyDictionary EntitySorters - => new Dictionary> + => new Dictionary> { - { typeof(ArrayEntity), e => ((ArrayEntity)e)?.Id }, { typeof(ArrayContainerEntity), e => ((ArrayContainerEntity)e)?.Id } + { typeof(ArrayEntity), e => ((ArrayEntity)e).Id }, { typeof(ArrayContainerEntity), e => ((ArrayContainerEntity)e)?.Id } }.ToDictionary(e => e.Key, e => (object)e.Value); public IReadOnlyDictionary EntityAsserters @@ -38,7 +38,8 @@ public IReadOnlyDictionary EntityAsserters typeof(ArrayEntity), (e, a) => { Assert.Equal(e is null, a is null); - if (a is not null) + + if (e is not null && a is not null) { var ee = (ArrayEntity)e; var aa = (ArrayEntity)a; @@ -69,7 +70,8 @@ public IReadOnlyDictionary EntityAsserters typeof(ArrayContainerEntity), (e, a) => { Assert.Equal(e is null, a is null); - if (a is not null) + + if (e is not null && a is not null) { var ee = (ArrayContainerEntity)e; var aa = (ArrayContainerEntity)a; diff --git a/test/EFCore.PG.FunctionalTests/Query/ArrayQueryTest.cs b/test/EFCore.PG.FunctionalTests/Query/ArrayQueryTest.cs index 1951cd85e..a970c8c3f 100644 --- a/test/EFCore.PG.FunctionalTests/Query/ArrayQueryTest.cs +++ b/test/EFCore.PG.FunctionalTests/Query/ArrayQueryTest.cs @@ -377,7 +377,7 @@ await AssertQuery( async, ss => ss.Set().Select(e => new[] { e.NullableText, e.NonNullableText }), elementAsserter: Assert.Equal, - elementSorter: strings => strings != null ? string.Join(separator: "", strings) : null); + elementSorter: strings => strings != null ? string.Join(separator: "", strings) : ""); AssertSql( """ @@ -412,7 +412,7 @@ await AssertQuery( async, ss => ss.Set().Select(e => new[] { e.Varchar10, e.Varchar15 }), elementAsserter: Assert.Equal, - elementSorter: strings => strings != null ? string.Join(separator: "", strings) : null); + elementSorter: strings => strings != null ? string.Join(separator: "", strings) : ""); AssertSql( """ @@ -429,7 +429,7 @@ await AssertQuery( async, ss => ss.Set().Select(e => new[] { e.NonNullableText, e.Varchar15 }), elementAsserter: Assert.Equal, - elementSorter: strings => strings != null ? string.Join(separator: "", strings) : null); + elementSorter: strings => strings != null ? string.Join(separator: "", strings) : ""); AssertSql( """ @@ -446,7 +446,7 @@ await AssertQuery( async, ss => ss.Set().Select(e => new[] { e.Id.ToString(), e.Varchar15 }), elementAsserter: Assert.Equal, - elementSorter: strings => strings != null ? string.Join(separator: "", strings) : null); + elementSorter: strings => strings != null ? string.Join(separator: "", strings) : ""); AssertSql( """ @@ -463,7 +463,7 @@ await AssertQuery( async, ss => ss.Set().Select(e => new[] { e.NonNullableText, e.NullableText ?? "" }), elementAsserter: Assert.Equal, - elementSorter: strings => strings != null ? string.Join(separator: "", strings) : null); + elementSorter: strings => strings != null ? string.Join(separator: "", strings) : ""); AssertSql( """ diff --git a/test/EFCore.PG.FunctionalTests/Query/CharacterQueryNpgsqlTest.cs b/test/EFCore.PG.FunctionalTests/Query/CharacterQueryNpgsqlTest.cs index cc248e83a..45258f953 100644 --- a/test/EFCore.PG.FunctionalTests/Query/CharacterQueryNpgsqlTest.cs +++ b/test/EFCore.PG.FunctionalTests/Query/CharacterQueryNpgsqlTest.cs @@ -41,10 +41,10 @@ public void Find_in_database() m2.Character6 = update; ctx.SaveChanges(); - var item0 = ctx.CharacterTestEntities.Find("12345678").Character6; + var item0 = ctx.CharacterTestEntities.Find("12345678")!.Character6; Assert.Equal(update, item0); - var item1 = ctx.CharacterTestEntities.Find("123456 ").Character6; + var item1 = ctx.CharacterTestEntities.Find("123456 ")!.Character6; Assert.Equal(update, item1); } } @@ -62,18 +62,18 @@ public void Find_locally_available() const string update = "update"; - var m1 = ctx.CharacterTestEntities.Find("12345678"); + var m1 = ctx.CharacterTestEntities.Find("12345678")!; m1.Character6 = update; ctx.SaveChanges(); - var m2 = ctx.CharacterTestEntities.Find("123456 "); + var m2 = ctx.CharacterTestEntities.Find("123456 ")!; m2.Character6 = update; ctx.SaveChanges(); - var item0 = ctx.CharacterTestEntities.Find("12345678").Character6; + var item0 = ctx.CharacterTestEntities.Find("12345678")!.Character6; Assert.Equal(update, item0); - var item1 = ctx.CharacterTestEntities.Find("123456 ").Character6; + var item1 = ctx.CharacterTestEntities.Find("123456 ")!.Character6; Assert.Equal(update, item1); } @@ -92,11 +92,11 @@ public void Test_change_tracking() ctx.CharacterTestEntities.Add(new CharacterTestEntity { Character8 = "123456 " }); ctx.SaveChanges(); - var m1 = ctx.CharacterTestEntities.Find("12345678"); + var m1 = ctx.CharacterTestEntities.Find("12345678")!; m1.Character6 = update; ctx.SaveChanges(); - var m2 = ctx.CharacterTestEntities.Find("123456 "); + var m2 = ctx.CharacterTestEntities.Find("123456 ")!; m2.Character6 = update; ctx.SaveChanges(); } @@ -178,8 +178,8 @@ public void ClearEntities() public class CharacterTestEntity { - public string Character8 { get; set; } - public string Character6 { get; set; } + public string Character8 { get; set; } = null!; + public string Character6 { get; set; } = null!; } public class CharacterContext : PoolableDbContext diff --git a/test/EFCore.PG.FunctionalTests/Query/CompatibilityQueryNpgsqlTest.cs b/test/EFCore.PG.FunctionalTests/Query/CompatibilityQueryNpgsqlTest.cs index 0e20d87fc..783644184 100644 --- a/test/EFCore.PG.FunctionalTests/Query/CompatibilityQueryNpgsqlTest.cs +++ b/test/EFCore.PG.FunctionalTests/Query/CompatibilityQueryNpgsqlTest.cs @@ -34,7 +34,7 @@ LIMIT 2 #region Support - private CompatibilityContext CreateContext(Version postgresVersion = null) + private CompatibilityContext CreateContext(Version? postgresVersion = null) => Fixture.CreateContext(postgresVersion); private CompatibilityContext CreateRedshiftContext() @@ -42,7 +42,7 @@ private CompatibilityContext CreateRedshiftContext() public class CompatibilityQueryNpgsqlFixture : FixtureBase, IDisposable, IAsyncLifetime { - private TestStore _testStore; + private TestStore _testStore = null!; private const string StoreName = "CompatibilityTest"; private readonly ListLoggerFactory _listLoggerFactory = NpgsqlTestStoreFactory.Instance.CreateListLoggerFactory(_ => false); @@ -53,7 +53,7 @@ public TestSqlLoggerFactory TestSqlLoggerFactory public virtual CompatibilityContext CreateContext() => CreateContext(null); - public virtual CompatibilityContext CreateContext(Version postgresVersion) + public virtual CompatibilityContext CreateContext(Version? postgresVersion) { var builder = new DbContextOptionsBuilder(); _testStore.AddProviderOptions(builder); diff --git a/test/EFCore.PG.FunctionalTests/Query/FunkyDataQueryNpgsqlTest.cs b/test/EFCore.PG.FunctionalTests/Query/FunkyDataQueryNpgsqlTest.cs index fb7483f05..324c42bbe 100644 --- a/test/EFCore.PG.FunctionalTests/Query/FunkyDataQueryNpgsqlTest.cs +++ b/test/EFCore.PG.FunctionalTests/Query/FunkyDataQueryNpgsqlTest.cs @@ -40,7 +40,7 @@ private void AssertSql(params string[] expected) public class FunkyDataQueryNpgsqlFixture : FunkyDataQueryFixtureBase, ITestSqlLoggerFactory { - private FunkyDataData _expectedData; + private FunkyDataData? _expectedData; public TestSqlLoggerFactory TestSqlLoggerFactory => (TestSqlLoggerFactory)ListLoggerFactory; diff --git a/test/EFCore.PG.FunctionalTests/Query/FuzzyStringMatchQueryNpgsqlTest.cs b/test/EFCore.PG.FunctionalTests/Query/FuzzyStringMatchQueryNpgsqlTest.cs index fd76749d3..70fda57a9 100644 --- a/test/EFCore.PG.FunctionalTests/Query/FuzzyStringMatchQueryNpgsqlTest.cs +++ b/test/EFCore.PG.FunctionalTests/Query/FuzzyStringMatchQueryNpgsqlTest.cs @@ -159,7 +159,7 @@ public class FuzzyStringMatchTestEntity /// /// Some text. /// - public string Text { get; set; } + public string Text { get; set; } = null!; } /// diff --git a/test/EFCore.PG.FunctionalTests/Query/GearsOfWarQueryNpgsqlFixture.cs b/test/EFCore.PG.FunctionalTests/Query/GearsOfWarQueryNpgsqlFixture.cs index 19f6da3ea..3b7987625 100644 --- a/test/EFCore.PG.FunctionalTests/Query/GearsOfWarQueryNpgsqlFixture.cs +++ b/test/EFCore.PG.FunctionalTests/Query/GearsOfWarQueryNpgsqlFixture.cs @@ -3,6 +3,7 @@ namespace Npgsql.EntityFrameworkCore.PostgreSQL.Query; + public class GearsOfWarQueryNpgsqlFixture : GearsOfWarQueryRelationalFixture { protected override string StoreName @@ -11,7 +12,7 @@ protected override string StoreName protected override ITestStoreFactory TestStoreFactory => NpgsqlTestStoreFactory.Instance; - private GearsOfWarData _expectedData; + private GearsOfWarData? _expectedData; static GearsOfWarQueryNpgsqlFixture() { diff --git a/test/EFCore.PG.FunctionalTests/Query/JsonDomQueryTest.cs b/test/EFCore.PG.FunctionalTests/Query/JsonDomQueryTest.cs index 00132db3a..5def3a621 100644 --- a/test/EFCore.PG.FunctionalTests/Query/JsonDomQueryTest.cs +++ b/test/EFCore.PG.FunctionalTests/Query/JsonDomQueryTest.cs @@ -73,7 +73,7 @@ public void Parameter_document() { using var ctx = CreateContext(); - var expected = ctx.JsonbEntities.Find(1).CustomerDocument; + var expected = ctx.JsonbEntities.Find(1)!.CustomerDocument; var actual = ctx.JsonbEntities.Single(e => e.CustomerDocument == expected).CustomerDocument; Assert.Equal(actual, expected); @@ -103,7 +103,7 @@ public void Parameter_element() { using var ctx = CreateContext(); - var expected = ctx.JsonbEntities.Find(1).CustomerElement; + var expected = ctx.JsonbEntities.Find(1)!.CustomerElement; var actual = ctx.JsonbEntities.Single(e => e.CustomerElement.Equals(expected)).CustomerElement; Assert.Equal(actual, expected); @@ -374,7 +374,7 @@ public void Like() { using var ctx = CreateContext(); - var x = ctx.JsonbEntities.Single(e => e.CustomerElement.GetProperty("Name").GetString().StartsWith("J")); + var x = ctx.JsonbEntities.Single(e => e.CustomerElement.GetProperty("Name").GetString()!.StartsWith("J")); Assert.Equal("Joe", x.CustomerElement.GetProperty("Name").GetString()); @@ -744,7 +744,7 @@ public class JsonbEntity { public int Id { get; set; } - public JsonDocument CustomerDocument { get; set; } + public JsonDocument CustomerDocument { get; set; } = null!; public JsonElement CustomerElement { get; set; } } @@ -753,7 +753,7 @@ public class JsonEntity public int Id { get; set; } [Column(TypeName = "json")] - public JsonDocument CustomerDocument { get; set; } + public JsonDocument CustomerDocument { get; set; } = null!; [Column(TypeName = "json")] public JsonElement CustomerElement { get; set; } diff --git a/test/EFCore.PG.FunctionalTests/Query/JsonPocoQueryTest.cs b/test/EFCore.PG.FunctionalTests/Query/JsonPocoQueryTest.cs index 5011584ed..34cd1d173 100644 --- a/test/EFCore.PG.FunctionalTests/Query/JsonPocoQueryTest.cs +++ b/test/EFCore.PG.FunctionalTests/Query/JsonPocoQueryTest.cs @@ -57,7 +57,7 @@ public void Parameter() { using var ctx = CreateContext(); - var expected = ctx.JsonbEntities.Find(1).Customer; + var expected = ctx.JsonbEntities.Find(1)!.Customer; var actual = ctx.JsonbEntities.Single(e => e.Customer == expected).Customer; Assert.Equal(actual.Name, expected.Name); @@ -718,7 +718,7 @@ public static async Task SeedAsync(JsonPocoQueryContext context) Customer = CreateCustomer1(), ToplevelArray = ["one", "two", "three"] }, - new JsonbEntity { Id = 2, Customer = CreateCustomer2() }); + new JsonbEntity { Id = 2, Customer = CreateCustomer2(), ToplevelArray = [] }); context.JsonEntities.AddRange( new JsonEntity { @@ -726,7 +726,7 @@ public static async Task SeedAsync(JsonPocoQueryContext context) Customer = CreateCustomer1(), ToplevelArray = ["one", "two", "three"] }, - new JsonEntity { Id = 2, Customer = CreateCustomer2() }); + new JsonEntity { Id = 2, Customer = CreateCustomer2(), ToplevelArray = [] }); await context.SaveChangesAsync(); @@ -826,10 +826,10 @@ public class JsonbEntity public int Id { get; set; } [Column(TypeName = "jsonb")] - public Customer Customer { get; set; } + public required Customer Customer { get; set; } [Column(TypeName = "jsonb")] - public string[] ToplevelArray { get; set; } + public required string[] ToplevelArray { get; set; } } public class JsonEntity @@ -837,10 +837,10 @@ public class JsonEntity public int Id { get; set; } [Column(TypeName = "json")] - public Customer Customer { get; set; } + public required Customer Customer { get; set; } [Column(TypeName = "json")] - public string[] ToplevelArray { get; set; } + public required string[] ToplevelArray { get; set; } } public class JsonPocoQueryFixture : SharedStoreFixtureBase @@ -868,43 +868,43 @@ protected override Task SeedAsync(JsonPocoQueryContext context) public class Customer { - public string Name { get; set; } + public required string Name { get; set; } public int Age { get; set; } public Guid ID { get; set; } [JsonPropertyName("is_vip")] public bool IsVip { get; set; } - public Statistics Statistics { get; set; } - public Order[] Orders { get; set; } - public VariousTypes VariousTypes { get; set; } + public Statistics Statistics { get; set; } = null!; + public Order[] Orders { get; set; } = null!; + public VariousTypes VariousTypes { get; set; } = null!; } public class Statistics { public long Visits { get; set; } public int Purchases { get; set; } - public NestedStatistics Nested { get; set; } + public required NestedStatistics Nested { get; set; } } public class NestedStatistics { public int SomeProperty { get; set; } public int? SomeNullableInt { get; set; } - public int[] IntArray { get; set; } - public List IntList { get; set; } + public int[] IntArray { get; set; } = null!; + public List IntList { get; set; } = null!; public Guid? SomeNullableGuid { get; set; } } public class Order { public decimal Price { get; set; } - public string ShippingAddress { get; set; } + public string ShippingAddress { get; set; } = null!; } public class VariousTypes { - public string String { get; set; } + public string String { get; set; } = null!; public int Int16 { get; set; } public int Int32 { get; set; } public int Int64 { get; set; } diff --git a/test/EFCore.PG.FunctionalTests/Query/JsonQueryNpgsqlTest.cs b/test/EFCore.PG.FunctionalTests/Query/JsonQueryNpgsqlTest.cs index 1f7d6cdb1..f9fb47da7 100644 --- a/test/EFCore.PG.FunctionalTests/Query/JsonQueryNpgsqlTest.cs +++ b/test/EFCore.PG.FunctionalTests/Query/JsonQueryNpgsqlTest.cs @@ -3398,7 +3398,7 @@ public class JsonQueryNpgsqlFixture : JsonQueryRelationalFixture, IQueryFixtureB protected override ITestStoreFactory TestStoreFactory => NpgsqlTestStoreFactory.Instance; - private JsonQueryData _expectedData; + private JsonQueryData? _expectedData; private readonly IReadOnlyDictionary _entityAsserters; public JsonQueryNpgsqlFixture() @@ -3407,8 +3407,9 @@ public JsonQueryNpgsqlFixture() entityAsserters[typeof(JsonEntityAllTypes)] = (object e, object a) => { - Assert.Equal(e == null, a == null); - if (a != null) + Assert.Equal(e is null, a is null); + + if (e is not null && a is not null) { var ee = (JsonEntityAllTypes)e; var aa = (JsonEntityAllTypes)a; @@ -3418,17 +3419,18 @@ public JsonQueryNpgsqlFixture() AssertAllTypes(ee.Reference, aa.Reference); Assert.Equal(ee.Collection?.Count ?? 0, aa.Collection?.Count ?? 0); - for (var i = 0; i < ee.Collection.Count; i++) + for (var i = 0; i < ee.Collection!.Count; i++) { - AssertAllTypes(ee.Collection[i], aa.Collection[i]); + AssertAllTypes(ee.Collection[i], aa.Collection![i]); } } }; entityAsserters[typeof(JsonOwnedAllTypes)] = (object e, object a) => { - Assert.Equal(e == null, a == null); - if (a != null) + Assert.Equal(e is null, a is null); + + if (e is not null && a is not null) { var ee = (JsonOwnedAllTypes)e; var aa = (JsonOwnedAllTypes)a; diff --git a/test/EFCore.PG.FunctionalTests/Query/JsonStringQueryTest.cs b/test/EFCore.PG.FunctionalTests/Query/JsonStringQueryTest.cs index 03be46212..6df9c8608 100644 --- a/test/EFCore.PG.FunctionalTests/Query/JsonStringQueryTest.cs +++ b/test/EFCore.PG.FunctionalTests/Query/JsonStringQueryTest.cs @@ -67,7 +67,7 @@ public void Parameter() { using var ctx = CreateContext(); - var expected = ctx.JsonEntities.Find(1).CustomerJsonb; + var expected = ctx.JsonEntities.Find(1)!.CustomerJsonb; var actual = ctx.JsonEntities.Single(e => e.CustomerJsonb == expected).CustomerJsonb; Assert.Equal(actual, expected); @@ -349,12 +349,12 @@ public class JsonEntity public int Id { get; set; } [Column(TypeName = "jsonb")] - public string CustomerJsonb { get; set; } + public string CustomerJsonb { get; set; } = null!; [Column(TypeName = "json")] - public string CustomerJson { get; set; } + public string CustomerJson { get; set; } = null!; - public string SomeString { get; set; } + public string SomeString { get; set; } = null!; } public class JsonStringQueryFixture : SharedStoreFixtureBase diff --git a/test/EFCore.PG.FunctionalTests/Query/LegacyNpgsqlNodaTimeTypeMappingTest.cs b/test/EFCore.PG.FunctionalTests/Query/LegacyNpgsqlNodaTimeTypeMappingTest.cs index e2a5bb1f0..2a99bbcd5 100644 --- a/test/EFCore.PG.FunctionalTests/Query/LegacyNpgsqlNodaTimeTypeMappingTest.cs +++ b/test/EFCore.PG.FunctionalTests/Query/LegacyNpgsqlNodaTimeTypeMappingTest.cs @@ -14,11 +14,11 @@ public class LegacyNpgsqlNodaTimeTypeMappingTest { [Fact] public void Timestamp_maps_to_Instant_by_default() - => Assert.Same(typeof(Instant), GetMapping("timestamp without time zone").ClrType); + => Assert.Same(typeof(Instant), GetMapping("timestamp without time zone")!.ClrType); [Fact] public void Timestamptz_maps_to_Instant_by_default() - => Assert.Same(typeof(Instant), GetMapping("timestamp with time zone").ClrType); + => Assert.Same(typeof(Instant), GetMapping("timestamp with time zone")!.ClrType); [Fact] public void LocalDateTime_does_not_map_to_timestamptz() @@ -27,7 +27,7 @@ public void LocalDateTime_does_not_map_to_timestamptz() [Fact] public void GenerateSqlLiteral_returns_instant_literal() { - var mapping = GetMapping(typeof(Instant)); + var mapping = GetMapping(typeof(Instant))!; Assert.Equal("timestamp without time zone", mapping.StoreType); var instant = (new LocalDateTime(2018, 4, 20, 10, 31, 33, 666) + Period.FromTicks(6660)).InUtc().ToInstant(); @@ -37,7 +37,7 @@ public void GenerateSqlLiteral_returns_instant_literal() [Fact] public void GenerateSqlLiteral_returns_instant_infinity_literal() { - var mapping = GetMapping(typeof(Instant)); + var mapping = GetMapping(typeof(Instant))!; Assert.Equal(typeof(Instant), mapping.ClrType); Assert.Equal("timestamp without time zone", mapping.StoreType); @@ -48,7 +48,7 @@ public void GenerateSqlLiteral_returns_instant_infinity_literal() [Fact] public void GenerateSqlLiteral_returns_instant_range_in_legacy_mode() { - var mapping = (NpgsqlRangeTypeMapping)GetMapping(typeof(NpgsqlRange)); + var mapping = (NpgsqlRangeTypeMapping)GetMapping(typeof(NpgsqlRange))!; Assert.Equal("tsrange", mapping.StoreType); Assert.Equal("timestamp without time zone", mapping.SubtypeMapping.StoreType); @@ -74,13 +74,13 @@ public void GenerateSqlLiteral_returns_instant_range_in_legacy_mode() new NpgsqlSingletonOptions() ); - private static RelationalTypeMapping GetMapping(string storeType) + private static RelationalTypeMapping? GetMapping(string storeType) => Mapper.FindMapping(storeType); - private static RelationalTypeMapping GetMapping(Type clrType) + private static RelationalTypeMapping? GetMapping(Type clrType) => Mapper.FindMapping(clrType); - private static RelationalTypeMapping GetMapping(Type clrType, string storeType) + private static RelationalTypeMapping? GetMapping(Type clrType, string storeType) => Mapper.FindMapping(clrType, storeType); private class LegacyNpgsqlNodaTimeTypeMappingFixture : IDisposable diff --git a/test/EFCore.PG.FunctionalTests/Query/NavigationTest.cs b/test/EFCore.PG.FunctionalTests/Query/NavigationTest.cs index bb9e565e5..eadfaf07c 100644 --- a/test/EFCore.PG.FunctionalTests/Query/NavigationTest.cs +++ b/test/EFCore.PG.FunctionalTests/Query/NavigationTest.cs @@ -2,6 +2,8 @@ namespace Npgsql.EntityFrameworkCore.PostgreSQL.Query; +#nullable disable + public class NavigationTest(NavigationTestFixture fixture) : IClassFixture { [Fact] diff --git a/test/EFCore.PG.FunctionalTests/Query/NorthwindDbFunctionsQueryNpgsqlTest.cs b/test/EFCore.PG.FunctionalTests/Query/NorthwindDbFunctionsQueryNpgsqlTest.cs index 425b5782e..2a3f2d613 100644 --- a/test/EFCore.PG.FunctionalTests/Query/NorthwindDbFunctionsQueryNpgsqlTest.cs +++ b/test/EFCore.PG.FunctionalTests/Query/NorthwindDbFunctionsQueryNpgsqlTest.cs @@ -3,6 +3,8 @@ namespace Npgsql.EntityFrameworkCore.PostgreSQL.Query; +#nullable disable + public class NorthwindDbFunctionsQueryNpgsqlTest : NorthwindDbFunctionsQueryRelationalTestBase< NorthwindQueryNpgsqlFixture> { diff --git a/test/EFCore.PG.FunctionalTests/Query/NorthwindFunctionsQueryNpgsqlTest.cs b/test/EFCore.PG.FunctionalTests/Query/NorthwindFunctionsQueryNpgsqlTest.cs index fc6ecc4a5..25d15646d 100644 --- a/test/EFCore.PG.FunctionalTests/Query/NorthwindFunctionsQueryNpgsqlTest.cs +++ b/test/EFCore.PG.FunctionalTests/Query/NorthwindFunctionsQueryNpgsqlTest.cs @@ -5,6 +5,8 @@ namespace Npgsql.EntityFrameworkCore.PostgreSQL.Query; +#nullable disable + public class NorthwindFunctionsQueryNpgsqlTest : NorthwindFunctionsQueryRelationalTestBase> { // ReSharper disable once UnusedParameter.Local diff --git a/test/EFCore.PG.FunctionalTests/Query/NorthwindMiscellaneousQueryNpgsqlTest.cs b/test/EFCore.PG.FunctionalTests/Query/NorthwindMiscellaneousQueryNpgsqlTest.cs index 0374ac3b4..08dcc031e 100644 --- a/test/EFCore.PG.FunctionalTests/Query/NorthwindMiscellaneousQueryNpgsqlTest.cs +++ b/test/EFCore.PG.FunctionalTests/Query/NorthwindMiscellaneousQueryNpgsqlTest.cs @@ -3,6 +3,8 @@ namespace Npgsql.EntityFrameworkCore.PostgreSQL.Query; +#nullable disable + public class NorthwindMiscellaneousQueryNpgsqlTest : NorthwindMiscellaneousQueryRelationalTestBase< NorthwindQueryNpgsqlFixture> { diff --git a/test/EFCore.PG.FunctionalTests/Query/QueryBugTest.cs b/test/EFCore.PG.FunctionalTests/Query/QueryBugTest.cs index 3dd78fa0d..118c30c85 100644 --- a/test/EFCore.PG.FunctionalTests/Query/QueryBugTest.cs +++ b/test/EFCore.PG.FunctionalTests/Query/QueryBugTest.cs @@ -5,6 +5,8 @@ namespace Npgsql.EntityFrameworkCore.PostgreSQL.Query; +#nullable disable + public class QueryBugsTest : IClassFixture { // ReSharper disable once UnusedParameter.Local diff --git a/test/EFCore.PG.FunctionalTests/Query/SpatialQueryNpgsqlGeographyTest.cs b/test/EFCore.PG.FunctionalTests/Query/SpatialQueryNpgsqlGeographyTest.cs index e7f0505e5..db42449b4 100644 --- a/test/EFCore.PG.FunctionalTests/Query/SpatialQueryNpgsqlGeographyTest.cs +++ b/test/EFCore.PG.FunctionalTests/Query/SpatialQueryNpgsqlGeographyTest.cs @@ -6,6 +6,8 @@ namespace Npgsql.EntityFrameworkCore.PostgreSQL.Query; +#nullable disable + // ReSharper disable once UnusedMember.Global [RequiresPostgis] public class SpatialQueryNpgsqlGeographyTest diff --git a/test/EFCore.PG.FunctionalTests/Query/SpatialQueryNpgsqlGeometryTest.cs b/test/EFCore.PG.FunctionalTests/Query/SpatialQueryNpgsqlGeometryTest.cs index 03cc231b7..8d3c10557 100644 --- a/test/EFCore.PG.FunctionalTests/Query/SpatialQueryNpgsqlGeometryTest.cs +++ b/test/EFCore.PG.FunctionalTests/Query/SpatialQueryNpgsqlGeometryTest.cs @@ -5,6 +5,8 @@ namespace Npgsql.EntityFrameworkCore.PostgreSQL.Query; +#nullable disable + [RequiresPostgis] public class SpatialQueryNpgsqlGeometryTest : SpatialQueryRelationalTestBase diff --git a/test/EFCore.PG.FunctionalTests/Query/SqlQueryNpgsqlTest.cs b/test/EFCore.PG.FunctionalTests/Query/SqlQueryNpgsqlTest.cs index 692771726..21a766ae9 100644 --- a/test/EFCore.PG.FunctionalTests/Query/SqlQueryNpgsqlTest.cs +++ b/test/EFCore.PG.FunctionalTests/Query/SqlQueryNpgsqlTest.cs @@ -3,6 +3,8 @@ namespace Npgsql.EntityFrameworkCore.PostgreSQL.Query; +#nullable disable + public class SqlQueryNpgsqlTest : SqlQueryTestBase> { public SqlQueryNpgsqlTest(NorthwindQueryNpgsqlFixture fixture, ITestOutputHelper testOutputHelper) @@ -70,7 +72,7 @@ public override async Task SqlQueryRaw_queryable_composed_after_removing_whitesp SELECT m."Address", m."City", m."CompanyName", m."ContactName", m."ContactTitle", m."Country", m."CustomerID", m."Fax", m."Phone", m."Region", m."PostalCode" FROM ( - + SELECT diff --git a/test/EFCore.PG.FunctionalTests/Query/TPCGearsOfWarQueryNpgsqlFixture.cs b/test/EFCore.PG.FunctionalTests/Query/TPCGearsOfWarQueryNpgsqlFixture.cs index 1e5de06b5..d59268cc3 100644 --- a/test/EFCore.PG.FunctionalTests/Query/TPCGearsOfWarQueryNpgsqlFixture.cs +++ b/test/EFCore.PG.FunctionalTests/Query/TPCGearsOfWarQueryNpgsqlFixture.cs @@ -26,7 +26,7 @@ protected override void OnModelCreating(ModelBuilder modelBuilder, DbContext con modelBuilder.Entity().Property(g => g.Location).HasColumnType("varchar(100)"); } - private GearsOfWarData _expectedData; + private GearsOfWarData? _expectedData; public override ISetSource GetExpectedData() { diff --git a/test/EFCore.PG.FunctionalTests/Query/TPTGearsOfWarQueryNpgsqlFixture.cs b/test/EFCore.PG.FunctionalTests/Query/TPTGearsOfWarQueryNpgsqlFixture.cs index 1011a5061..a55022b0a 100644 --- a/test/EFCore.PG.FunctionalTests/Query/TPTGearsOfWarQueryNpgsqlFixture.cs +++ b/test/EFCore.PG.FunctionalTests/Query/TPTGearsOfWarQueryNpgsqlFixture.cs @@ -26,7 +26,7 @@ protected override void OnModelCreating(ModelBuilder modelBuilder, DbContext con modelBuilder.Entity().Property(g => g.Location).HasColumnType("varchar(100)"); } - private GearsOfWarData _expectedData; + private GearsOfWarData? _expectedData; public override ISetSource GetExpectedData() { diff --git a/test/EFCore.PG.FunctionalTests/Query/Translations/BasicTypesQueryNpgsqlFixture.cs b/test/EFCore.PG.FunctionalTests/Query/Translations/BasicTypesQueryNpgsqlFixture.cs index 03140627c..ae2b49f1e 100644 --- a/test/EFCore.PG.FunctionalTests/Query/Translations/BasicTypesQueryNpgsqlFixture.cs +++ b/test/EFCore.PG.FunctionalTests/Query/Translations/BasicTypesQueryNpgsqlFixture.cs @@ -2,8 +2,6 @@ using Npgsql.EntityFrameworkCore.PostgreSQL.Infrastructure; using Npgsql.EntityFrameworkCore.PostgreSQL.TestUtilities; -#nullable enable - namespace Microsoft.EntityFrameworkCore.Query.Translations; public class BasicTypesQueryNpgsqlFixture : BasicTypesQueryFixtureBase, ITestSqlLoggerFactory diff --git a/test/EFCore.PG.FunctionalTests/Query/Translations/BigIntegerTranslationsTest.cs b/test/EFCore.PG.FunctionalTests/Query/Translations/BigIntegerTranslationsTest.cs index 550ab373f..820436f63 100644 --- a/test/EFCore.PG.FunctionalTests/Query/Translations/BigIntegerTranslationsTest.cs +++ b/test/EFCore.PG.FunctionalTests/Query/Translations/BigIntegerTranslationsTest.cs @@ -147,7 +147,7 @@ public class Entity public class BigIntegerQueryFixture : SharedStoreFixtureBase, IQueryFixtureBase, ITestSqlLoggerFactory { - private BigIntegerData _expectedData; + private BigIntegerData? _expectedData; protected override string StoreName => "BigIntegerQueryTest"; @@ -168,7 +168,7 @@ public ISetSource GetExpectedData() => _expectedData ??= new BigIntegerData(); public IReadOnlyDictionary EntitySorters - => new Dictionary> { { typeof(Entity), e => ((Entity)e)?.Id } } + => new Dictionary> { { typeof(Entity), e => ((Entity)e).Id } } .ToDictionary(e => e.Key, e => (object)e.Value); public IReadOnlyDictionary EntityAsserters @@ -178,9 +178,10 @@ public IReadOnlyDictionary EntityAsserters typeof(Entity), (e, a) => { Assert.Equal(e is null, a is null); + if (a is not null) { - var ee = (Entity)e; + var ee = (Entity)e!; var aa = (Entity)a; Assert.Equal(ee.Id, aa.Id); diff --git a/test/EFCore.PG.FunctionalTests/Query/Translations/CitextTranslationsTest.cs b/test/EFCore.PG.FunctionalTests/Query/Translations/CitextTranslationsTest.cs index 48b5bac58..019516933 100644 --- a/test/EFCore.PG.FunctionalTests/Query/Translations/CitextTranslationsTest.cs +++ b/test/EFCore.PG.FunctionalTests/Query/Translations/CitextTranslationsTest.cs @@ -312,7 +312,7 @@ public class SomeArrayEntity public int Id { get; set; } [Column(TypeName = "citext")] - public string CaseInsensitiveText { get; set; } + public string CaseInsensitiveText { get; set; } = null!; } public class CitextQueryFixture : SharedStoreFixtureBase diff --git a/test/EFCore.PG.FunctionalTests/Query/Translations/EnumTranslationsNpgsqlTest.cs b/test/EFCore.PG.FunctionalTests/Query/Translations/EnumTranslationsNpgsqlTest.cs index 807b6e767..a0956799a 100644 --- a/test/EFCore.PG.FunctionalTests/Query/Translations/EnumTranslationsNpgsqlTest.cs +++ b/test/EFCore.PG.FunctionalTests/Query/Translations/EnumTranslationsNpgsqlTest.cs @@ -1,7 +1,5 @@ namespace Microsoft.EntityFrameworkCore.Query.Translations; -#nullable enable - public class EnumTranslationsNpgsqlTest : EnumTranslationsTestBase { public EnumTranslationsNpgsqlTest(BasicTypesQueryNpgsqlFixture fixture, ITestOutputHelper testOutputHelper) diff --git a/test/EFCore.PG.FunctionalTests/Query/Translations/EnumTranslationsTest.cs b/test/EFCore.PG.FunctionalTests/Query/Translations/EnumTranslationsTest.cs index af5555c19..9df854389 100644 --- a/test/EFCore.PG.FunctionalTests/Query/Translations/EnumTranslationsTest.cs +++ b/test/EFCore.PG.FunctionalTests/Query/Translations/EnumTranslationsTest.cs @@ -309,7 +309,7 @@ public override DbContextOptionsBuilder AddOptions(DbContextOptionsBuilder build return optionsBuilder; } - private EnumData _expectedData; + private EnumData? _expectedData; protected override Task SeedAsync(EnumContext context) => EnumContext.SeedAsync(context); @@ -321,7 +321,7 @@ public ISetSource GetExpectedData() => _expectedData ??= new EnumData(); public IReadOnlyDictionary EntitySorters - => new Dictionary> { { typeof(SomeEnumEntity), e => ((SomeEnumEntity)e)?.Id } } + => new Dictionary> { { typeof(SomeEnumEntity), e => ((SomeEnumEntity)e)?.Id } } .ToDictionary(e => e.Key, e => (object)e.Value); public IReadOnlyDictionary EntityAsserters @@ -331,7 +331,8 @@ public IReadOnlyDictionary EntityAsserters typeof(SomeEnumEntity), (e, a) => { Assert.Equal(e is null, a is null); - if (a is not null) + + if (e is not null && a is not null) { var ee = (SomeEnumEntity)e; var aa = (SomeEnumEntity)a; diff --git a/test/EFCore.PG.FunctionalTests/Query/Translations/LTreeTranslationsTest.cs b/test/EFCore.PG.FunctionalTests/Query/Translations/LTreeTranslationsTest.cs index f8a41fd21..6645ef768 100644 --- a/test/EFCore.PG.FunctionalTests/Query/Translations/LTreeTranslationsTest.cs +++ b/test/EFCore.PG.FunctionalTests/Query/Translations/LTreeTranslationsTest.cs @@ -539,14 +539,14 @@ public class LTreeEntity public LTree LTree { get; set; } [Required] - public LTree[] LTrees { get; set; } + public LTree[] LTrees { get; set; } = null!; [Required] [Column(TypeName = "ltree")] - public string LTreeAsString { get; set; } + public string LTreeAsString { get; set; } = null!; [Required] - public string SomeString { get; set; } + public string SomeString { get; set; } = null!; } public class LTreeQueryFixture : SharedStoreFixtureBase diff --git a/test/EFCore.PG.FunctionalTests/Query/Translations/MathTranslationsNpgsqlTest.cs b/test/EFCore.PG.FunctionalTests/Query/Translations/MathTranslationsNpgsqlTest.cs index 3f7fade26..ddcae5fa7 100644 --- a/test/EFCore.PG.FunctionalTests/Query/Translations/MathTranslationsNpgsqlTest.cs +++ b/test/EFCore.PG.FunctionalTests/Query/Translations/MathTranslationsNpgsqlTest.cs @@ -1,7 +1,5 @@ namespace Microsoft.EntityFrameworkCore.Query.Translations; -#nullable enable - public class MathTranslationsNpgsqlTest : MathTranslationsTestBase { public MathTranslationsNpgsqlTest(BasicTypesQueryNpgsqlFixture fixture, ITestOutputHelper testOutputHelper) diff --git a/test/EFCore.PG.FunctionalTests/Query/Translations/MultirangeTranslationsTest.cs b/test/EFCore.PG.FunctionalTests/Query/Translations/MultirangeTranslationsTest.cs index b6db39283..33ed28771 100644 --- a/test/EFCore.PG.FunctionalTests/Query/Translations/MultirangeTranslationsTest.cs +++ b/test/EFCore.PG.FunctionalTests/Query/Translations/MultirangeTranslationsTest.cs @@ -737,13 +737,13 @@ protected override Task SeedAsync(MultirangeContext context) public class MultirangeTestEntity { public int Id { get; set; } - public NpgsqlRange[] IntMultirange { get; set; } - public NpgsqlRange[] LongMultirange { get; set; } - public NpgsqlRange[] DecimalMultirange { get; set; } - public NpgsqlRange[] DateOnlyDateMultirange { get; set; } + public NpgsqlRange[] IntMultirange { get; set; } = null!; + public NpgsqlRange[] LongMultirange { get; set; } = null!; + public NpgsqlRange[] DecimalMultirange { get; set; } = null!; + public NpgsqlRange[] DateOnlyDateMultirange { get; set; } = null!; [Column(TypeName = "datemultirange")] - public NpgsqlRange[] DateTimeDateMultirange { get; set; } + public NpgsqlRange[] DateTimeDateMultirange { get; set; } = null!; } private void AssertSql(params string[] expected) diff --git a/test/EFCore.PG.FunctionalTests/Query/Translations/NetworkTranslationsNpgsqlTest.cs b/test/EFCore.PG.FunctionalTests/Query/Translations/NetworkTranslationsNpgsqlTest.cs index 06bbb3373..68519b178 100644 --- a/test/EFCore.PG.FunctionalTests/Query/Translations/NetworkTranslationsNpgsqlTest.cs +++ b/test/EFCore.PG.FunctionalTests/Query/Translations/NetworkTranslationsNpgsqlTest.cs @@ -1477,7 +1477,7 @@ public class NetTestEntity /// /// The network address. /// - public IPAddress Inet { get; set; } + public IPAddress Inet { get; set; } = null!; /// /// The network address. @@ -1487,23 +1487,23 @@ public class NetTestEntity /// /// The MAC address. /// - public PhysicalAddress Macaddr { get; set; } + public PhysicalAddress Macaddr { get; set; } = null!; /// /// The MAC address. /// [Column(TypeName = "macaddr8")] - public PhysicalAddress Macaddr8 { get; set; } + public PhysicalAddress Macaddr8 { get; set; } = null!; /// /// The text form of . /// - public string TextInet { get; set; } + public string TextInet { get; set; } = null!; /// /// The text form of . /// - public string TextMacaddr { get; set; } + public string TextMacaddr { get; set; } = null!; } /// diff --git a/test/EFCore.PG.FunctionalTests/Query/Translations/NodaTime/NodaTimeQueryNpgsqlFixture.cs b/test/EFCore.PG.FunctionalTests/Query/Translations/NodaTime/NodaTimeQueryNpgsqlFixture.cs index cb4a2edf6..5930b34e4 100644 --- a/test/EFCore.PG.FunctionalTests/Query/Translations/NodaTime/NodaTimeQueryNpgsqlFixture.cs +++ b/test/EFCore.PG.FunctionalTests/Query/Translations/NodaTime/NodaTimeQueryNpgsqlFixture.cs @@ -21,7 +21,7 @@ protected override ITestStoreFactory TestStoreFactory public TestSqlLoggerFactory TestSqlLoggerFactory => (TestSqlLoggerFactory)ListLoggerFactory; - private NodaTimeData _expectedData; + private NodaTimeData? _expectedData; protected override IServiceCollection AddServices(IServiceCollection serviceCollection) => base.AddServices(serviceCollection).AddEntityFrameworkNpgsqlNodaTime(); @@ -44,7 +44,7 @@ public ISetSource GetExpectedData() => _expectedData ??= new NodaTimeData(); public IReadOnlyDictionary EntitySorters - => new Dictionary> { { typeof(NodaTimeTypes), e => ((NodaTimeTypes)e)?.Id } } + => new Dictionary> { { typeof(NodaTimeTypes), e => ((NodaTimeTypes)e).Id } } .ToDictionary(e => e.Key, e => (object)e.Value); public IReadOnlyDictionary EntityAsserters @@ -54,7 +54,7 @@ public IReadOnlyDictionary EntityAsserters typeof(NodaTimeTypes), (e, a) => { Assert.Equal(e is null, a is null); - if (a is not null) + if (e is not null && a is not null) { var ee = (NodaTimeTypes)e; var aa = (NodaTimeTypes)a; diff --git a/test/EFCore.PG.FunctionalTests/Query/Translations/StringTranslationsNpgsqlTest.cs b/test/EFCore.PG.FunctionalTests/Query/Translations/StringTranslationsNpgsqlTest.cs index 1b8e1d801..77a3ccd11 100644 --- a/test/EFCore.PG.FunctionalTests/Query/Translations/StringTranslationsNpgsqlTest.cs +++ b/test/EFCore.PG.FunctionalTests/Query/Translations/StringTranslationsNpgsqlTest.cs @@ -2,8 +2,6 @@ namespace Microsoft.EntityFrameworkCore.Query.Translations; -#nullable enable - public class StringTranslationsNpgsqlTest : StringTranslationsRelationalTestBase { public StringTranslationsNpgsqlTest(BasicTypesQueryNpgsqlFixture fixture, ITestOutputHelper testOutputHelper) diff --git a/test/EFCore.PG.FunctionalTests/Query/Translations/TemporalTranslationsNpgsqlTimestampWithoutTimeZoneTest.cs b/test/EFCore.PG.FunctionalTests/Query/Translations/TemporalTranslationsNpgsqlTimestampWithoutTimeZoneTest.cs index 1717c417c..3a9d64072 100644 --- a/test/EFCore.PG.FunctionalTests/Query/Translations/TemporalTranslationsNpgsqlTimestampWithoutTimeZoneTest.cs +++ b/test/EFCore.PG.FunctionalTests/Query/Translations/TemporalTranslationsNpgsqlTimestampWithoutTimeZoneTest.cs @@ -1,8 +1,6 @@ using Microsoft.EntityFrameworkCore.TestModels.BasicTypesModel; using Xunit.Sdk; -#nullable enable - namespace Microsoft.EntityFrameworkCore.Query.Translations; /// diff --git a/test/EFCore.PG.FunctionalTests/Query/Translations/TimestampTranslationsTest.cs b/test/EFCore.PG.FunctionalTests/Query/Translations/TimestampTranslationsTest.cs index 83392d987..13ac7272c 100644 --- a/test/EFCore.PG.FunctionalTests/Query/Translations/TimestampTranslationsTest.cs +++ b/test/EFCore.PG.FunctionalTests/Query/Translations/TimestampTranslationsTest.cs @@ -897,12 +897,12 @@ public class Entity public DateTimeOffset TimestampDateTimeOffset { get; set; } - public DateTime[] TimestamptzDateTimeArray { get; set; } + public DateTime[] TimestamptzDateTimeArray { get; set; } = null!; [Column(TypeName = "timestamp without time zone[]")] - public DateTime[] TimestampDateTimeArray { get; set; } + public DateTime[] TimestampDateTimeArray { get; set; } = null!; - public DateTimeOffset[] TimestampDateTimeOffsetArray { get; set; } + public DateTimeOffset[] TimestampDateTimeOffsetArray { get; set; } = null!; public NpgsqlRange TimestamptzDateTimeRange { get; set; } @@ -924,7 +924,7 @@ protected override ITestStoreFactory TestStoreFactory public TestSqlLoggerFactory TestSqlLoggerFactory => (TestSqlLoggerFactory)ListLoggerFactory; - private TimestampData _expectedData; + private TimestampData? _expectedData; protected override Task SeedAsync(TimestampQueryContext context) => TimestampQueryContext.SeedAsync(context); @@ -936,7 +936,7 @@ public ISetSource GetExpectedData() => _expectedData ??= new TimestampData(); public IReadOnlyDictionary EntitySorters - => new Dictionary> { { typeof(Entity), e => ((Entity)e)?.Id } } + => new Dictionary> { { typeof(Entity), e => ((Entity)e)?.Id } } .ToDictionary(e => e.Key, e => (object)e.Value); public IReadOnlyDictionary EntityAsserters @@ -948,7 +948,7 @@ public IReadOnlyDictionary EntityAsserters Assert.Equal(e is null, a is null); if (a is not null) { - var ee = (Entity)e; + var ee = (Entity)e!; var aa = (Entity)a; Assert.Equal(ee.Id, aa.Id); diff --git a/test/EFCore.PG.FunctionalTests/Query/Translations/TrigramsTranslationsTest.cs b/test/EFCore.PG.FunctionalTests/Query/Translations/TrigramsTranslationsTest.cs index 64d2591d5..e1d1da1aa 100644 --- a/test/EFCore.PG.FunctionalTests/Query/Translations/TrigramsTranslationsTest.cs +++ b/test/EFCore.PG.FunctionalTests/Query/Translations/TrigramsTranslationsTest.cs @@ -247,7 +247,7 @@ public class TrigramsTestEntity /// /// Some text. /// - public string Text { get; set; } + public string Text { get; set; } = null!; } /// diff --git a/test/EFCore.PG.FunctionalTests/Query/UdfDbFunctionNpgsqlTests.cs b/test/EFCore.PG.FunctionalTests/Query/UdfDbFunctionNpgsqlTests.cs index a1652ec85..38f70731e 100644 --- a/test/EFCore.PG.FunctionalTests/Query/UdfDbFunctionNpgsqlTests.cs +++ b/test/EFCore.PG.FunctionalTests/Query/UdfDbFunctionNpgsqlTests.cs @@ -2,6 +2,8 @@ namespace Npgsql.EntityFrameworkCore.PostgreSQL.Query; +#nullable disable + public class UdfDbFunctionNpgsqlTests : UdfDbFunctionTestBase { // ReSharper disable once UnusedParameter.Local diff --git a/test/EFCore.PG.FunctionalTests/Scaffolding/NpgsqlDatabaseModelFactoryTest.cs b/test/EFCore.PG.FunctionalTests/Scaffolding/NpgsqlDatabaseModelFactoryTest.cs index 6357a3676..79b6062cf 100644 --- a/test/EFCore.PG.FunctionalTests/Scaffolding/NpgsqlDatabaseModelFactoryTest.cs +++ b/test/EFCore.PG.FunctionalTests/Scaffolding/NpgsqlDatabaseModelFactoryTest.cs @@ -555,9 +555,9 @@ public void Create_primary_key() [], dbModel => { - var pk = dbModel.Tables.Single().PrimaryKey; + var pk = dbModel.Tables.Single().PrimaryKey!; - Assert.Equal("public", pk.Table.Schema); + Assert.Equal("public", pk.Table!.Schema); Assert.Equal("PrimaryKeyTable", pk.Table.Name); Assert.StartsWith("PrimaryKeyTable_pkey", pk.Name); Assert.Equal(["Id"], pk.Columns.Select(ic => ic.Name).ToList()); @@ -629,7 +629,7 @@ public void Create_indexes() Assert.All( table.Indexes, c => { - Assert.Equal("public", c.Table.Schema); + Assert.Equal("public", c.Table!.Schema); Assert.Equal("IndexTable", c.Table.Name); }); @@ -1133,9 +1133,9 @@ PRIMARY KEY ("Id2", "Id1") [], dbModel => { - var pk = dbModel.Tables.Single().PrimaryKey; + var pk = dbModel.Tables.Single().PrimaryKey!; - Assert.Equal("public", pk.Table.Schema); + Assert.Equal("public", pk.Table!.Schema); Assert.Equal("CompositePrimaryKeyTable", pk.Table.Name); Assert.Equal(["Id2", "Id1"], pk.Columns.Select(ic => ic.Name).ToList()); }, @@ -1157,9 +1157,9 @@ public void Set_primary_key_name_from_index() [], dbModel => { - var pk = dbModel.Tables.Single().PrimaryKey; + var pk = dbModel.Tables.Single().PrimaryKey!; - Assert.Equal("public", pk.Table.Schema); + Assert.Equal("public", pk.Table!.Schema); Assert.Equal("PrimaryKeyName", pk.Table.Name); Assert.StartsWith("MyPK", pk.Name); Assert.Equal(["Id2"], pk.Columns.Select(ic => ic.Name).ToList()); @@ -1248,7 +1248,7 @@ public void Create_composite_index() var index = Assert.Single(dbModel.Tables.Single().Indexes); // ReSharper disable once PossibleNullReferenceException - Assert.Equal("public", index.Table.Schema); + Assert.Equal("public", index.Table!.Schema); Assert.Equal("CompositeIndexTable", index.Table.Name); Assert.Equal("IX_COMPOSITE", index.Name); Assert.Equal(["Id2", "Id1"], index.Columns.Select(ic => ic.Name).ToList()); @@ -1275,7 +1275,7 @@ public void Set_unique_true_for_unique_index() var index = Assert.Single(dbModel.Tables.Single().Indexes); // ReSharper disable once PossibleNullReferenceException - Assert.Equal("public", index.Table.Schema); + Assert.Equal("public", index.Table!.Schema); Assert.Equal("UniqueIndexTable", index.Table.Name); Assert.Equal("IX_UNIQUE", index.Name); Assert.True(index.IsUnique); @@ -1304,7 +1304,7 @@ public void Set_filter_for_filtered_index() var index = Assert.Single(dbModel.Tables.Single().Indexes); // ReSharper disable once PossibleNullReferenceException - Assert.Equal("public", index.Table.Schema); + Assert.Equal("public", index.Table!.Schema); Assert.Equal("FilteredIndexTable", index.Table.Name); Assert.Equal("IX_UNIQUE", index.Name); Assert.Equal("""("Id2" > 10)""", index.Filter); @@ -1644,7 +1644,7 @@ public void SequenceSerial() Assert.Null(column.DefaultValueSql); Assert.Equal( NpgsqlValueGenerationStrategy.SerialColumn, - (NpgsqlValueGenerationStrategy)column[NpgsqlAnnotationNames.ValueGenerationStrategy]); + (NpgsqlValueGenerationStrategy?)column[NpgsqlAnnotationNames.ValueGenerationStrategy]); } }, """ @@ -1698,21 +1698,21 @@ b int GENERATED BY DEFAULT AS IDENTITY Assert.Null(idIdentityAlways.DefaultValueSql); Assert.Equal( NpgsqlValueGenerationStrategy.IdentityAlwaysColumn, - (NpgsqlValueGenerationStrategy)idIdentityAlways[NpgsqlAnnotationNames.ValueGenerationStrategy]); + (NpgsqlValueGenerationStrategy?)idIdentityAlways[NpgsqlAnnotationNames.ValueGenerationStrategy]); var identityAlways = dbModel.Tables.Single().Columns.Single(c => c.Name == "a"); Assert.Equal(ValueGenerated.OnAdd, identityAlways.ValueGenerated); Assert.Null(identityAlways.DefaultValueSql); Assert.Equal( NpgsqlValueGenerationStrategy.IdentityAlwaysColumn, - (NpgsqlValueGenerationStrategy)identityAlways[NpgsqlAnnotationNames.ValueGenerationStrategy]); + (NpgsqlValueGenerationStrategy?)identityAlways[NpgsqlAnnotationNames.ValueGenerationStrategy]); var identityByDefault = dbModel.Tables.Single().Columns.Single(c => c.Name == "b"); Assert.Equal(ValueGenerated.OnAdd, identityByDefault.ValueGenerated); Assert.Null(identityByDefault.DefaultValueSql); Assert.Equal( NpgsqlValueGenerationStrategy.IdentityByDefaultColumn, - (NpgsqlValueGenerationStrategy)identityByDefault[NpgsqlAnnotationNames.ValueGenerationStrategy]); + (NpgsqlValueGenerationStrategy?)identityByDefault[NpgsqlAnnotationNames.ValueGenerationStrategy]); }, "DROP TABLE identity"); @@ -1735,7 +1735,7 @@ smallint_without_options smallint GENERATED BY DEFAULT AS IDENTITY var withOptions = dbModel.Tables.Single().Columns.Single(c => c.Name == "with_options"); Assert.Equal( NpgsqlValueGenerationStrategy.IdentityByDefaultColumn, - (NpgsqlValueGenerationStrategy)withOptions[NpgsqlAnnotationNames.ValueGenerationStrategy]); + (NpgsqlValueGenerationStrategy?)withOptions[NpgsqlAnnotationNames.ValueGenerationStrategy]); Assert.Equal( new IdentitySequenceOptionsData { @@ -1751,21 +1751,21 @@ smallint_without_options smallint GENERATED BY DEFAULT AS IDENTITY Assert.Equal("integer", withOptions.StoreType); Assert.Equal( NpgsqlValueGenerationStrategy.IdentityByDefaultColumn, - (NpgsqlValueGenerationStrategy)withoutOptions[NpgsqlAnnotationNames.ValueGenerationStrategy]); + (NpgsqlValueGenerationStrategy?)withoutOptions[NpgsqlAnnotationNames.ValueGenerationStrategy]); Assert.Null(withoutOptions[NpgsqlAnnotationNames.IdentityOptions]); var bigintWithoutOptions = dbModel.Tables.Single().Columns.Single(c => c.Name == "bigint_without_options"); Assert.Equal("bigint", bigintWithoutOptions.StoreType); Assert.Equal( NpgsqlValueGenerationStrategy.IdentityByDefaultColumn, - (NpgsqlValueGenerationStrategy)bigintWithoutOptions[NpgsqlAnnotationNames.ValueGenerationStrategy]); + (NpgsqlValueGenerationStrategy?)bigintWithoutOptions[NpgsqlAnnotationNames.ValueGenerationStrategy]); Assert.Null(bigintWithoutOptions[NpgsqlAnnotationNames.IdentityOptions]); var smallintWithoutOptions = dbModel.Tables.Single().Columns.Single(c => c.Name == "smallint_without_options"); Assert.Equal("smallint", smallintWithoutOptions.StoreType); Assert.Equal( NpgsqlValueGenerationStrategy.IdentityByDefaultColumn, - (NpgsqlValueGenerationStrategy)smallintWithoutOptions[NpgsqlAnnotationNames.ValueGenerationStrategy]); + (NpgsqlValueGenerationStrategy?)smallintWithoutOptions[NpgsqlAnnotationNames.ValueGenerationStrategy]); Assert.Null(smallintWithoutOptions[NpgsqlAnnotationNames.IdentityOptions]); }, "DROP TABLE identity"); @@ -1816,7 +1816,7 @@ public void Index_method() Assert.Equal(2, table.Indexes.Count); var methodIndex = table.Indexes.Single(i => i.Name == "ix_a"); - Assert.Equal("hash", methodIndex.FindAnnotation(NpgsqlAnnotationNames.IndexMethod).Value); + Assert.Equal("hash", methodIndex[NpgsqlAnnotationNames.IndexMethod]); // It's cleaner to always output the index method on the database model, // even when it's btree (the default); @@ -1846,7 +1846,7 @@ public void Index_operators() var table = dbModel.Tables.Single(); var indexWith = table.Indexes.Single(i => i.Name == "ix_with"); - Assert.Equal(new[] { null, "varchar_pattern_ops" }, indexWith.FindAnnotation(NpgsqlAnnotationNames.IndexOperators).Value); + Assert.Equal(new[] { null, "varchar_pattern_ops" }, indexWith[NpgsqlAnnotationNames.IndexOperators]); var indexWithout = table.Indexes.Single(i => i.Name == "ix_without"); Assert.Null(indexWithout.FindAnnotation(NpgsqlAnnotationNames.IndexOperators)); @@ -1870,7 +1870,7 @@ public void Index_collation() var table = dbModel.Tables.Single(); var indexWith = table.Indexes.Single(i => i.Name == "ix_with"); - Assert.Equal(new[] { null, "POSIX" }, indexWith.FindAnnotation(RelationalAnnotationNames.Collation).Value); + Assert.Equal(new[] { null, "POSIX" }, indexWith[RelationalAnnotationNames.Collation]); var indexWithout = table.Indexes.Single(i => i.Name == "ix_without"); Assert.Null(indexWithout.FindAnnotation(RelationalAnnotationNames.Collation)); @@ -1930,7 +1930,7 @@ public void Index_null_sort_order() var indexWith = table.Indexes.Single(i => i.Name == "ix_with"); Assert.Equal( new[] { NullSortOrder.NullsFirst, NullSortOrder.NullsLast }, - indexWith.FindAnnotation(NpgsqlAnnotationNames.IndexNullSortOrder).Value); + indexWith[NpgsqlAnnotationNames.IndexNullSortOrder]); var indexWithout = table.Indexes.Single(i => i.Name == "ix_without"); Assert.Null(indexWithout.FindAnnotation(NpgsqlAnnotationNames.IndexNullSortOrder)); @@ -2194,7 +2194,7 @@ line line Assert.Equal(column.Name, column.StoreType); Assert.Equal( column.StoreType, - typeMappingSource.FindMapping(column.StoreType).StoreType + typeMappingSource.FindMapping(column.StoreType!)!.StoreType ); } }, @@ -2220,7 +2220,7 @@ private void Test( IEnumerable tables, IEnumerable schemas, Action asserter, - string cleanupSql) + string? cleanupSql) { Fixture.TestStore.ExecuteNonQuery(createSql); diff --git a/test/EFCore.PG.FunctionalTests/SequenceEndToEndTest.cs b/test/EFCore.PG.FunctionalTests/SequenceEndToEndTest.cs index 715fa78fa..bc6147a55 100644 --- a/test/EFCore.PG.FunctionalTests/SequenceEndToEndTest.cs +++ b/test/EFCore.PG.FunctionalTests/SequenceEndToEndTest.cs @@ -2,6 +2,8 @@ namespace Npgsql.EntityFrameworkCore.PostgreSQL; +#nullable disable + public class SequenceEndToEndTest : IAsyncLifetime { [ConditionalFact] @@ -386,10 +388,10 @@ protected override void OnModelCreating(ModelBuilder modelBuilder) private class Unicon { public int? Identifier { get; set; } - public string Name { get; set; } + public string Name { get; set; } = null!; } - protected NpgsqlTestStore TestStore { get; private set; } + protected NpgsqlTestStore TestStore { get; private set; } = null!; public async Task InitializeAsync() => TestStore = await NpgsqlTestStore.CreateInitializedAsync("SequenceEndToEndTest"); diff --git a/test/EFCore.PG.FunctionalTests/SystemColumnTest.cs b/test/EFCore.PG.FunctionalTests/SystemColumnTest.cs index cd7150436..d8e949688 100644 --- a/test/EFCore.PG.FunctionalTests/SystemColumnTest.cs +++ b/test/EFCore.PG.FunctionalTests/SystemColumnTest.cs @@ -49,7 +49,7 @@ public class SomeEntity // ReSharper disable UnusedMember.Global // ReSharper disable UnusedAutoPropertyAccessor.Global public int Id { get; set; } - public string Name { get; set; } + public string Name { get; set; } = null!; public uint Version { get; set; } // ReSharper restore UnusedMember.Global diff --git a/test/EFCore.PG.FunctionalTests/TestModels/Array/ArrayContainerEntity.cs b/test/EFCore.PG.FunctionalTests/TestModels/Array/ArrayContainerEntity.cs index 53049b0c6..7d65701f1 100644 --- a/test/EFCore.PG.FunctionalTests/TestModels/Array/ArrayContainerEntity.cs +++ b/test/EFCore.PG.FunctionalTests/TestModels/Array/ArrayContainerEntity.cs @@ -1,5 +1,3 @@ -#nullable enable - namespace Npgsql.EntityFrameworkCore.PostgreSQL.TestModels.Array; public class ArrayContainerEntity diff --git a/test/EFCore.PG.FunctionalTests/TestModels/Array/ArrayEntity.cs b/test/EFCore.PG.FunctionalTests/TestModels/Array/ArrayEntity.cs index c7dde4960..1a79914d8 100644 --- a/test/EFCore.PG.FunctionalTests/TestModels/Array/ArrayEntity.cs +++ b/test/EFCore.PG.FunctionalTests/TestModels/Array/ArrayEntity.cs @@ -1,5 +1,3 @@ -#nullable enable - namespace Npgsql.EntityFrameworkCore.PostgreSQL.TestModels.Array; public class ArrayEntity diff --git a/test/EFCore.PG.FunctionalTests/TestModels/Array/ArrayQueryContext.cs b/test/EFCore.PG.FunctionalTests/TestModels/Array/ArrayQueryContext.cs index 389023fd6..68b02923d 100644 --- a/test/EFCore.PG.FunctionalTests/TestModels/Array/ArrayQueryContext.cs +++ b/test/EFCore.PG.FunctionalTests/TestModels/Array/ArrayQueryContext.cs @@ -32,7 +32,7 @@ protected override void OnModelCreating(ModelBuilder modelBuilder) v => string.Join(",", v), v => v.Split(',', StringSplitOptions.None).ToList(), new ValueComparer>( - (c1, c2) => c1.SequenceEqual(c2), + (c1, c2) => c1 == null && c2 == null || (c1 != null && c2 != null && c1.SequenceEqual(c2)), c => c.Aggregate(0, (a, v) => HashCode.Combine(a, v.GetHashCode())), c => c.ToList())); @@ -41,7 +41,7 @@ protected override void OnModelCreating(ModelBuilder modelBuilder) v => string.Join(",", v), v => v.Split(',', StringSplitOptions.None).ToArray(), new ValueComparer( - (c1, c2) => c1.SequenceEqual(c2), + (c1, c2) => c1 == null && c2 == null || (c1 != null && c2 != null && c1.SequenceEqual(c2)), c => c.Aggregate(0, (a, v) => HashCode.Combine(a, v.GetHashCode())), c => c.ToArray())); diff --git a/test/EFCore.PG.FunctionalTests/TestModels/NodaTime/NodaTimeTypes.cs b/test/EFCore.PG.FunctionalTests/TestModels/NodaTime/NodaTimeTypes.cs index 2a1087d8a..fa1faddc4 100644 --- a/test/EFCore.PG.FunctionalTests/TestModels/NodaTime/NodaTimeTypes.cs +++ b/test/EFCore.PG.FunctionalTests/TestModels/NodaTime/NodaTimeTypes.cs @@ -13,15 +13,15 @@ public class NodaTimeTypes public LocalDate LocalDate2 { get; set; } public LocalTime LocalTime { get; set; } public OffsetTime OffsetTime { get; set; } - public Period Period { get; set; } + public Period Period { get; set; } = null!; public Duration Duration { get; set; } - public DateInterval DateInterval { get; set; } + public DateInterval DateInterval { get; set; } = null!; public NpgsqlRange LocalDateRange { get; set; } public Interval Interval { get; set; } public NpgsqlRange InstantRange { get; set; } public long Long { get; set; } - public string TimeZoneId { get; set; } + public string TimeZoneId { get; set; } = null!; // ReSharper restore UnusedAutoPropertyAccessor.Global } diff --git a/test/EFCore.PG.FunctionalTests/TestUtilities/NpgsqlTestStore.cs b/test/EFCore.PG.FunctionalTests/TestUtilities/NpgsqlTestStore.cs index 8b4ba0381..2831aa598 100644 --- a/test/EFCore.PG.FunctionalTests/TestUtilities/NpgsqlTestStore.cs +++ b/test/EFCore.PG.FunctionalTests/TestUtilities/NpgsqlTestStore.cs @@ -5,8 +5,6 @@ namespace Npgsql.EntityFrameworkCore.PostgreSQL.TestUtilities; -#nullable enable - public class NpgsqlTestStore : RelationalTestStore { private readonly string? _scriptPath; diff --git a/test/EFCore.PG.FunctionalTests/TestUtilities/NpgsqlTestStoreFactory.cs b/test/EFCore.PG.FunctionalTests/TestUtilities/NpgsqlTestStoreFactory.cs index 06de22f29..3b3c5667b 100644 --- a/test/EFCore.PG.FunctionalTests/TestUtilities/NpgsqlTestStoreFactory.cs +++ b/test/EFCore.PG.FunctionalTests/TestUtilities/NpgsqlTestStoreFactory.cs @@ -1,7 +1,5 @@ namespace Npgsql.EntityFrameworkCore.PostgreSQL.TestUtilities; -#nullable enable - public class NpgsqlTestStoreFactory( string? scriptPath = null, string? additionalSql = null, diff --git a/test/EFCore.PG.FunctionalTests/TestUtilities/TestEnvironment.cs b/test/EFCore.PG.FunctionalTests/TestUtilities/TestEnvironment.cs index 43ac5e3fe..f11ffb509 100644 --- a/test/EFCore.PG.FunctionalTests/TestUtilities/TestEnvironment.cs +++ b/test/EFCore.PG.FunctionalTests/TestUtilities/TestEnvironment.cs @@ -26,7 +26,7 @@ static TestEnvironment() public static string DefaultConnection => Config["DefaultConnection"] ?? DefaultConnectionString; - private static Version _postgresVersion; + private static Version? _postgresVersion; public static Version PostgresVersion { @@ -59,7 +59,7 @@ public static bool IsPostgisAvailable using var cmd = conn.CreateCommand(); cmd.CommandText = "SELECT EXISTS (SELECT 1 FROM pg_available_extensions WHERE \"name\" = 'postgis' LIMIT 1)"; - _isPostgisAvailable = (bool)cmd.ExecuteScalar(); + _isPostgisAvailable = (bool)cmd.ExecuteScalar()!; return _isPostgisAvailable.Value; } } diff --git a/test/EFCore.PG.FunctionalTests/TestUtilities/TestNpgsqlConnection.cs b/test/EFCore.PG.FunctionalTests/TestUtilities/TestNpgsqlConnection.cs index 15ef578c7..737b8bd33 100644 --- a/test/EFCore.PG.FunctionalTests/TestUtilities/TestNpgsqlConnection.cs +++ b/test/EFCore.PG.FunctionalTests/TestUtilities/TestNpgsqlConnection.cs @@ -4,7 +4,7 @@ namespace Npgsql.EntityFrameworkCore.PostgreSQL.TestUtilities; -public class TestNpgsqlConnection(RelationalConnectionDependencies dependencies, DbDataSource dataSource = null) +public class TestNpgsqlConnection(RelationalConnectionDependencies dependencies, DbDataSource? dataSource = null) : NpgsqlRelationalConnection(dependencies, dataSource) { public string ErrorCode { get; set; } = "XX000"; diff --git a/test/EFCore.PG.FunctionalTests/TestUtilities/TestNpgsqlRetryingExecutionStrategy.cs b/test/EFCore.PG.FunctionalTests/TestUtilities/TestNpgsqlRetryingExecutionStrategy.cs index c443ccdc8..f1448bfd1 100644 --- a/test/EFCore.PG.FunctionalTests/TestUtilities/TestNpgsqlRetryingExecutionStrategy.cs +++ b/test/EFCore.PG.FunctionalTests/TestUtilities/TestNpgsqlRetryingExecutionStrategy.cs @@ -32,7 +32,7 @@ public TestNpgsqlRetryingExecutionStrategy(ExecutionStrategyDependencies depende { } - protected override bool ShouldRetryOn(Exception exception) + protected override bool ShouldRetryOn(Exception? exception) { if (base.ShouldRetryOn(exception)) { diff --git a/test/EFCore.PG.FunctionalTests/TestUtilities/TestRelationalCommandBuilderFactory.cs b/test/EFCore.PG.FunctionalTests/TestUtilities/TestRelationalCommandBuilderFactory.cs index 38d349250..16a678ae1 100644 --- a/test/EFCore.PG.FunctionalTests/TestUtilities/TestRelationalCommandBuilderFactory.cs +++ b/test/EFCore.PG.FunctionalTests/TestUtilities/TestRelationalCommandBuilderFactory.cs @@ -129,7 +129,7 @@ public Task ExecuteNonQueryAsync( return result; } - public object ExecuteScalar(RelationalCommandParameterObject parameterObject) + public object? ExecuteScalar(RelationalCommandParameterObject parameterObject) { var connection = parameterObject.Connection; var errorNumber = PreExecution(connection); @@ -144,7 +144,7 @@ public object ExecuteScalar(RelationalCommandParameterObject parameterObject) return result; } - public async Task ExecuteScalarAsync( + public async Task ExecuteScalarAsync( RelationalCommandParameterObject parameterObject, CancellationToken cancellationToken = default) { @@ -198,9 +198,9 @@ public async Task ExecuteReaderAsync( public DbCommand CreateDbCommand(RelationalCommandParameterObject parameterObject, Guid commandId, DbCommandMethod commandMethod) => throw new NotImplementedException(); - private string PreExecution(IRelationalConnection connection) + private string? PreExecution(IRelationalConnection connection) { - string errorNumber = null; + string? errorNumber = null; var testConnection = (TestNpgsqlConnection)connection; testConnection.ExecutionCount++; diff --git a/test/EFCore.PG.FunctionalTests/TwoDatabasesNpgsqlTest.cs b/test/EFCore.PG.FunctionalTests/TwoDatabasesNpgsqlTest.cs index 9a6ab976a..8e6f77417 100644 --- a/test/EFCore.PG.FunctionalTests/TwoDatabasesNpgsqlTest.cs +++ b/test/EFCore.PG.FunctionalTests/TwoDatabasesNpgsqlTest.cs @@ -13,7 +13,7 @@ protected override DbContextOptionsBuilder CreateTestOptions( bool withNullConnectionString = false) => withConnectionString ? withNullConnectionString - ? optionsBuilder.UseNpgsql((string)null) + ? optionsBuilder.UseNpgsql((string?)null) : optionsBuilder.UseNpgsql(DummyConnectionString) : optionsBuilder.UseNpgsql(); diff --git a/test/EFCore.PG.FunctionalTests/Update/StoreValueGenerationNpgsqlTest.cs b/test/EFCore.PG.FunctionalTests/Update/StoreValueGenerationNpgsqlTest.cs index 7da79e4b6..041b72d95 100644 --- a/test/EFCore.PG.FunctionalTests/Update/StoreValueGenerationNpgsqlTest.cs +++ b/test/EFCore.PG.FunctionalTests/Update/StoreValueGenerationNpgsqlTest.cs @@ -4,8 +4,6 @@ namespace Npgsql.EntityFrameworkCore.PostgreSQL.Update; -#nullable enable - public class StoreValueGenerationNpgsqlTest : StoreValueGenerationTestBase< StoreValueGenerationNpgsqlTest.StoreValueGenerationNpgsqlFixture> { diff --git a/test/EFCore.PG.FunctionalTests/Update/StoredProcedureUpdateNpgsqlTest.cs b/test/EFCore.PG.FunctionalTests/Update/StoredProcedureUpdateNpgsqlTest.cs index 4e78b3c8a..4785309a4 100644 --- a/test/EFCore.PG.FunctionalTests/Update/StoredProcedureUpdateNpgsqlTest.cs +++ b/test/EFCore.PG.FunctionalTests/Update/StoredProcedureUpdateNpgsqlTest.cs @@ -3,8 +3,6 @@ namespace Npgsql.EntityFrameworkCore.PostgreSQL.Update; -#nullable enable - [MinimumPostgresVersion(14, 0)] public class StoredProcedureUpdateNpgsqlTest : StoredProcedureUpdateTestBase { diff --git a/test/EFCore.PG.FunctionalTests/UpdatesNpgsqlTest.cs b/test/EFCore.PG.FunctionalTests/UpdatesNpgsqlTest.cs index b44952233..e49c76252 100644 --- a/test/EFCore.PG.FunctionalTests/UpdatesNpgsqlTest.cs +++ b/test/EFCore.PG.FunctionalTests/UpdatesNpgsqlTest.cs @@ -19,7 +19,7 @@ public override void Identifiers_are_generated_correctly() var entityType = context.Model.FindEntityType( typeof( LoginEntityTypeWithAnExtremelyLongAndOverlyConvolutedNameThatIsUsedToVerifyThatTheStoreIdentifierGenerationLengthLimitIsWorkingCorrectly - )); + ))!; Assert.Equal( "LoginEntityTypeWithAnExtremelyLongAndOverlyConvolutedNameThatI~", entityType.GetTableName()); @@ -36,7 +36,7 @@ public override void Identifiers_are_generated_correctly() var entityType2 = context.Model.FindEntityType( typeof( LoginEntityTypeWithAnExtremelyLongAndOverlyConvolutedNameThatIsUsedToVerifyThatTheStoreIdentifierGenerationLengthLimitIsWorkingCorrectlyDetails - )); + ))!; Assert.Equal( "LoginEntityTypeWithAnExtremelyLongAndOverlyConvolutedNameThat~1", @@ -46,10 +46,10 @@ public override void Identifiers_are_generated_correctly() entityType2.GetKeys().Single().GetName()); Assert.Equal( "ExtraPropertyWithAnExtremelyLongAndOverlyConvolutedNameThatIsU~", - entityType2.GetProperties().ElementAt(1).GetColumnName(StoreObjectIdentifier.Table(entityType2.GetTableName()))); + entityType2.GetProperties().ElementAt(1).GetColumnName(StoreObjectIdentifier.Table(entityType2.GetTableName()!))); Assert.Equal( "ExtraPropertyWithAnExtremelyLongAndOverlyConvolutedNameThatIs~1", - entityType2.GetProperties().ElementAt(2).GetColumnName(StoreObjectIdentifier.Table(entityType2.GetTableName()))); + entityType2.GetProperties().ElementAt(2).GetColumnName(StoreObjectIdentifier.Table(entityType2.GetTableName()!))); Assert.Equal( "IX_LoginEntityTypeWithAnExtremelyLongAndOverlyConvolutedNameT~1", entityType2.GetIndexes().Single().GetDatabaseName()); diff --git a/test/EFCore.PG.FunctionalTests/ValueConvertersEndToEndNpgsqlTest.cs b/test/EFCore.PG.FunctionalTests/ValueConvertersEndToEndNpgsqlTest.cs index 56ea743cf..89de83460 100644 --- a/test/EFCore.PG.FunctionalTests/ValueConvertersEndToEndNpgsqlTest.cs +++ b/test/EFCore.PG.FunctionalTests/ValueConvertersEndToEndNpgsqlTest.cs @@ -199,7 +199,6 @@ protected override void OnModelCreating(ModelBuilder modelBuilder, DbContext con private class IntWrapperConverter() : ValueConverter(iw => iw.Value, i => new IntWrapper(i)); } -#nullable enable public class ValueConvertedArrayEntity { public int Id { get; set; } diff --git a/test/EFCore.PG.Tests/EFCore.PG.Tests.csproj b/test/EFCore.PG.Tests/EFCore.PG.Tests.csproj index 7f23750d4..201184440 100644 --- a/test/EFCore.PG.Tests/EFCore.PG.Tests.csproj +++ b/test/EFCore.PG.Tests/EFCore.PG.Tests.csproj @@ -3,10 +3,7 @@ Npgsql.EntityFrameworkCore.PostgreSQL.Tests Npgsql.EntityFrameworkCore.PostgreSQL - - $(NoWarn);NU1903 - false - critical + disable diff --git a/test/EFCore.PG.Tests/TestUtilities/FakeDiagnosticsLogger.cs b/test/EFCore.PG.Tests/TestUtilities/FakeDiagnosticsLogger.cs index baab9c467..c55131ba9 100644 --- a/test/EFCore.PG.Tests/TestUtilities/FakeDiagnosticsLogger.cs +++ b/test/EFCore.PG.Tests/TestUtilities/FakeDiagnosticsLogger.cs @@ -33,7 +33,7 @@ public bool IsEnabled(EventId eventId, LogLevel logLevel) => true; public IDisposable BeginScope(TState state) - => null; + => null!; public virtual LoggingDefinitions Definitions { get; } = new TestRelationalLoggingDefinitions(); diff --git a/test/EFCore.PG.Tests/TestUtilities/FakeRelationalCommandDiagnosticsLogger.cs b/test/EFCore.PG.Tests/TestUtilities/FakeRelationalCommandDiagnosticsLogger.cs index d66214d83..a7573b37e 100644 --- a/test/EFCore.PG.Tests/TestUtilities/FakeRelationalCommandDiagnosticsLogger.cs +++ b/test/EFCore.PG.Tests/TestUtilities/FakeRelationalCommandDiagnosticsLogger.cs @@ -1,9 +1,9 @@ -#nullable enable - using System.Data.Common; namespace Npgsql.EntityFrameworkCore.PostgreSQL.TestUtilities; +#nullable enable + public class FakeRelationalCommandDiagnosticsLogger : FakeDiagnosticsLogger, IRelationalCommandDiagnosticsLogger {