Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Annotate functional tests for nullability #3418

Merged
merged 1 commit into from
Dec 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
<VersionPrefix>10.0.0</VersionPrefix>
<TargetFramework>net10.0</TargetFramework>
<LangVersion>latest</LangVersion>
<Nullable>enable</Nullable>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
<AnalysisLevel>latest</AnalysisLevel>
<NoWarn>NU5105</NoWarn>
Expand Down
1 change: 0 additions & 1 deletion src/Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
<IncludeSymbols>true</IncludeSymbols>
<SymbolPackageFormat>snupkg</SymbolPackageFormat>
<EmbedUntrackedSources>true</EmbedUntrackedSources>
<Nullable>enable</Nullable>
<Feature>nullablePublicOnly</Feature>
</PropertyGroup>

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
#nullable enable

namespace Npgsql.EntityFrameworkCore.PostgreSQL;

public class BadDataJsonDeserializationSqlServerTest : BadDataJsonDeserializationTestBase
Expand Down
2 changes: 2 additions & 0 deletions test/EFCore.PG.FunctionalTests/BatchingTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
// ReSharper disable InconsistentNaming
namespace Npgsql.EntityFrameworkCore.PostgreSQL;

#nullable disable

public class BatchingTest(BatchingTest.BatchingTestFixture fixture) : IClassFixture<BatchingTest.BatchingTestFixture>
{
protected BatchingTestFixture Fixture { get; } = fixture;
Expand Down
2 changes: 2 additions & 0 deletions test/EFCore.PG.FunctionalTests/BuiltInDataTypesNpgsqlTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@

namespace Npgsql.EntityFrameworkCore.PostgreSQL;

#nullable disable

public class BuiltInDataTypesNpgsqlTest : BuiltInDataTypesTestBase<BuiltInDataTypesNpgsqlTest.BuiltInDataTypesNpgsqlFixture>
{
// ReSharper disable once UnusedParameter.Local
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ protected class Context3001(DbContextOptions options) : DbContext(options)
protected class EntityWithPrimitiveCollection
{
public int Id { get; set; }
public List<string> Tags { get; set; }
public List<string> Tags { get; set; } = null!;
}

public override async Task Delete_with_view_mapping(bool async)
Expand Down
2 changes: 1 addition & 1 deletion test/EFCore.PG.FunctionalTests/ComputedColumnTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
2 changes: 2 additions & 0 deletions test/EFCore.PG.FunctionalTests/ConferencePlannerNpgsqlTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

namespace Npgsql.EntityFrameworkCore.PostgreSQL;

#nullable disable

public class ConferencePlannerNpgsqlTest(ConferencePlannerNpgsqlTest.ConferencePlannerNpgsqlFixture fixture)
: ConferencePlannerTestBase<ConferencePlannerNpgsqlTest.ConferencePlannerNpgsqlFixture>(fixture)
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System.Data;
using System.Data.Common;
using System.Diagnostics.CodeAnalysis;
using Npgsql.EntityFrameworkCore.PostgreSQL.TestUtilities;

namespace Npgsql.EntityFrameworkCore.PostgreSQL;
Expand Down Expand Up @@ -45,6 +46,7 @@ protected override BadUniverseContext CreateBadUniverse(DbContextOptionsBuilder

public class FakeDbConnection : DbConnection
{
[AllowNull]
public override string ConnectionString { get; set; }

public override string Database
Expand Down
2 changes: 2 additions & 0 deletions test/EFCore.PG.FunctionalTests/ConnectionSpecificationTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
// ReSharper disable StringLiteralTypo
namespace Npgsql.EntityFrameworkCore.PostgreSQL;

#nullable disable

public class ConnectionSpecificationTest
{
[Fact]
Expand Down
2 changes: 1 addition & 1 deletion test/EFCore.PG.FunctionalTests/DefaultValuesTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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; }
}
}
2 changes: 2 additions & 0 deletions test/EFCore.PG.FunctionalTests/ExecutionStrategyTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
// ReSharper disable AccessToDisposedClosure
namespace Npgsql.EntityFrameworkCore.PostgreSQL;

#nullable disable

public class ExecutionStrategyTest : IClassFixture<ExecutionStrategyTest.ExecutionStrategyFixture>
{
public ExecutionStrategyTest(ExecutionStrategyFixture fixture)
Expand Down
6 changes: 3 additions & 3 deletions test/EFCore.PG.FunctionalTests/ExistingConnectionTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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!;
}
}
10 changes: 5 additions & 5 deletions test/EFCore.PG.FunctionalTests/F1NpgsqlFixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Chassis>().Property<uint>("Version").HasConversion((ValueConverter)null);
modelBuilder.Entity<Driver>().Property<uint>("Version").HasConversion((ValueConverter)null);
modelBuilder.Entity<Team>().Property<uint>("Version").HasConversion((ValueConverter)null);
modelBuilder.Entity<Sponsor>().Property<uint>("Version").HasConversion((ValueConverter)null);
modelBuilder.Entity<Chassis>().Property<uint>("Version").HasConversion((ValueConverter?)null);
modelBuilder.Entity<Driver>().Property<uint>("Version").HasConversion((ValueConverter?)null);
modelBuilder.Entity<Team>().Property<uint>("Version").HasConversion((ValueConverter?)null);
modelBuilder.Entity<Sponsor>().Property<uint>("Version").HasConversion((ValueConverter?)null);
modelBuilder.Entity<TitleSponsor>()
.OwnsOne(
s => s.Details, eb =>
{
eb.Property<uint>("Version").IsRowVersion().HasConversion((ValueConverter)null);
eb.Property<uint>("Version").IsRowVersion().HasConversion((ValueConverter?)null);
});
}
}
Expand Down
2 changes: 0 additions & 2 deletions test/EFCore.PG.FunctionalTests/JsonTypesNpgsqlTest.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
#nullable enable

using System.Collections;
using System.Globalization;
using System.Numerics;
Expand Down
2 changes: 1 addition & 1 deletion test/EFCore.PG.FunctionalTests/LazyLoadProxyNpgsqlTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion test/EFCore.PG.FunctionalTests/LoadNpgsqlTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down
2 changes: 1 addition & 1 deletion test/EFCore.PG.FunctionalTests/LoggingNpgsqlTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -72,5 +72,5 @@ protected override string ProviderName

protected override string ProviderVersion
=> typeof(NpgsqlOptionsExtension).Assembly
.GetCustomAttribute<AssemblyInformationalVersionAttribute>()?.InformationalVersion;
.GetCustomAttribute<AssemblyInformationalVersionAttribute>()?.InformationalVersion!;
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
#nullable enable

using Npgsql.EntityFrameworkCore.PostgreSQL.TestUtilities;

namespace Npgsql.EntityFrameworkCore.PostgreSQL;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

namespace Npgsql.EntityFrameworkCore.PostgreSQL.ModelBuilding;

#nullable enable

public class NpgsqlModelBuilderGenericTest : NpgsqlModelBuilderTestBase
{
public class NpgsqlGenericNonRelationship(NpgsqlModelBuilderFixture fixture) : NpgsqlNonRelationship(fixture)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
#nullable enable

using Microsoft.EntityFrameworkCore.ModelBuilding;
using Npgsql.EntityFrameworkCore.PostgreSQL.TestUtilities;

Expand Down
2 changes: 2 additions & 0 deletions test/EFCore.PG.FunctionalTests/NpgsqlApiConsistencyTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@

namespace Npgsql.EntityFrameworkCore.PostgreSQL;

#nullable disable

public class NpgsqlApiConsistencyTest(NpgsqlApiConsistencyTest.NpgsqlApiConsistencyFixture fixture)
: ApiConsistencyTestBase<NpgsqlApiConsistencyTest.NpgsqlApiConsistencyFixture>(fixture)
{
Expand Down
2 changes: 2 additions & 0 deletions test/EFCore.PG.FunctionalTests/NpgsqlDatabaseCreatorTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@

namespace Npgsql.EntityFrameworkCore.PostgreSQL;

#nullable disable

public class NpgsqlDatabaseCreatorExistsTest : NpgsqlDatabaseCreatorTest
{
[ConditionalTheory]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@

namespace Npgsql.EntityFrameworkCore.PostgreSQL;

#nullable disable

public class NpgsqlValueGenerationScenariosTest
{
private static readonly string DatabaseName = "NpgsqlValueGenerationScenariosTest";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

namespace Npgsql.EntityFrameworkCore.PostgreSQL;

#nullable disable

public class OptimisticConcurrencyBytesNpgsqlTest(F1BytesNpgsqlFixture fixture)
: OptimisticConcurrencyNpgsqlTestBase<F1BytesNpgsqlFixture, byte[]>(fixture);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

namespace Npgsql.EntityFrameworkCore.PostgreSQL.Query;

#nullable disable

public class AdHocJsonQueryNpgsqlTest : AdHocJsonQueryTestBase
{
protected override ITestStoreFactory TestStoreFactory
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

namespace Npgsql.EntityFrameworkCore.PostgreSQL.Query;

#nullable disable

public class AdHocQuerySplittingQueryNpgsqlTest : AdHocQuerySplittingQueryTestBase
{
protected override DbContextOptionsBuilder SetQuerySplittingBehavior(
Expand Down
16 changes: 8 additions & 8 deletions test/EFCore.PG.FunctionalTests/Query/ArrayArrayQueryTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -642,7 +642,7 @@ await AssertQuery(
ss => ss.Set<ArrayEntity>()
.Where(e => new[] { "a%", "b%", "c%" }.Any(p => EF.Functions.Like(e.NullableText, p))),
ss => ss.Set<ArrayEntity>()
.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(
"""
Expand All @@ -657,9 +657,9 @@ public override async Task Any_ilike(bool async)
await AssertQuery(
async,
ss => ss.Set<ArrayEntity>()
.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<ArrayEntity>()
.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(
"""
Expand All @@ -681,7 +681,7 @@ await AssertQuery(
ss => ss.Set<ArrayEntity>()
.Where(e => patternsActual.Any(p => EF.Functions.Like(e.NullableText, p))),
ss => ss.Set<ArrayEntity>()
.Where(e => patternsExpected.Any(p => e.NullableText.StartsWith(p, StringComparison.Ordinal))));
.Where(e => patternsExpected.Any(p => e.NullableText!.StartsWith(p, StringComparison.Ordinal))));

AssertSql(
"""
Expand All @@ -700,7 +700,7 @@ await AssertQuery(
ss => ss.Set<ArrayEntity>()
.Where(e => new[] { "b%", "ba%" }.All(p => EF.Functions.Like(e.NullableText, p))),
ss => ss.Set<ArrayEntity>()
.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(
"""
Expand All @@ -715,9 +715,9 @@ public override async Task All_ilike(bool async)
await AssertQuery(
async,
ss => ss.Set<ArrayEntity>()
.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<ArrayEntity>()
.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(
"""
Expand Down
Loading
Loading