Skip to content
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
6 changes: 3 additions & 3 deletions test/EFCore.Design.Tests/Design/DesignTimeServicesTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ public MethodCallCodeFragment GenerateContextOptions()
public MethodCallCodeFragment GenerateProviderOptions()
=> throw new NotImplementedException();

public MethodCallCodeFragment GenerateUseProvider(string connectionString, MethodCallCodeFragment providerOptions)
public MethodCallCodeFragment GenerateUseProvider(string connectionString, MethodCallCodeFragment? providerOptions)
=> throw new NotImplementedException();
}

Expand Down Expand Up @@ -413,8 +413,8 @@ public class MyContext(DbContextOptions<MyContext> options) : DbContext(options)

private ServiceProvider CreateDesignServiceProvider(
string assemblyCode,
string startupAssemblyCode = null,
DbContext context = null)
string? startupAssemblyCode = null,
DbContext? context = null)
{
var assembly = Compile(assemblyCode);
var startupAssembly = startupAssemblyCode == null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@

namespace Microsoft.EntityFrameworkCore.Design.Internal;

#nullable enable

public class CSharpHelperTest
{
private static readonly string EOL = Environment.NewLine;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ private void ValidateContextNameInReverseEngineerGenerator(string contextName)
"",
"",
dbContextClassName: contextName,
null,
null,
null!,
null!,
"FakeNamespace",
contextNamespace: null,
useDataAnnotations: false,
Expand All @@ -56,7 +56,7 @@ public void ScaffoldContext_sets_environment()
"",
dbContextClassName: nameof(TestContext),
schemas: ["Empty"],
null,
null!,
null,
contextNamespace: null,
useDataAnnotations: false,
Expand All @@ -69,7 +69,7 @@ public void ScaffoldContext_sets_environment()
Assert.Equal("Development", Environment.GetEnvironmentVariable("DOTNET_ENVIRONMENT"));
}

private static DatabaseOperations CreateOperations(string[] args)
private static DatabaseOperations CreateOperations(string[]? args)
{
var assembly = MockAssembly.Create(typeof(TestContext));
var operations = new DatabaseOperations(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ public class DbContextOperationsTest
{
[Fact]
public void CreateContext_gets_service()
=> CreateOperations(typeof(TestProgram), includeContext: false).CreateContext(typeof(TestContext).FullName.ToLower());
=> CreateOperations(typeof(TestProgram), includeContext: false).CreateContext(typeof(TestContext).FullName!.ToLower());

[Fact]
public void CreateContext_gets_service_without_name()
Expand Down Expand Up @@ -54,8 +54,8 @@ public void CreateContext_throws_if_ambiguous_context_type_by_case()
new TestAppServiceProviderFactory(assembly, reporter));

Assert.Equal(
DesignStrings.MultipleContextsWithName(typeof(TestContext).FullName.ToLower()),
Assert.Throws<OperationException>(() => operations.CreateContext(typeof(TestContext).FullName.ToLower())).Message);
DesignStrings.MultipleContextsWithName(typeof(TestContext).FullName!.ToLower()),
Assert.Throws<OperationException>(() => operations.CreateContext(typeof(TestContext).FullName!.ToLower())).Message);

Assert.DoesNotContain(reporter.Messages, m => m.Level == LogLevel.Critical);
Assert.DoesNotContain(reporter.Messages, m => m.Level == LogLevel.Error);
Expand Down Expand Up @@ -289,7 +289,7 @@ public void GetContextInfo_returns_correct_info()
[Fact]
public void GetContextInfo_does_not_throw_if_DbConnection_cannot_be_created()
{
Exception expected = null;
Exception? expected = null;
try
{
new SqlConnection("Cake=None");
Expand All @@ -299,6 +299,8 @@ public void GetContextInfo_does_not_throw_if_DbConnection_cannot_be_created()
expected = e;
}

Assert.NotNull(expected);

var info = CreateOperations(typeof(TestProgramRelationalBad)).GetContextInfo(nameof(TestContext));

Assert.Equal(DesignStrings.BadConnection(expected.Message), info.DatabaseName);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,8 @@ public void Select_uses_last_when_multiple_services()
private class TestLanguageBasedSelector(params TestLanguageBasedService[] services)
: LanguageBasedSelector<TestLanguageBasedService>(services);

private class TestLanguageBasedService(string language) : ILanguageBasedService
private class TestLanguageBasedService(string? language) : ILanguageBasedService
{
public string Language { get; } = language;
public string? Language { get; } = language;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ private class TestContext : DbContext;

private class AssemblyTestContext : DbContext
{
public static Assembly MigrationsAssembly { get; set; }
public static Assembly MigrationsAssembly { get; set; } = null!;

protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
=> optionsBuilder.UseSqlServer(o => o.MigrationsAssembly(MigrationsAssembly));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public void Log_dampens_logLevel_when_CommandExecuted()
logger.Log<object>(
LogLevel.Information,
RelationalEventId.CommandExecuted,
null,
null!,
null,
(_, __) => "-- Can't stop the SQL");

Expand Down
2 changes: 0 additions & 2 deletions test/EFCore.Design.Tests/Design/OperationExecutorTest.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

#nullable enable

using System.Collections;
using Microsoft.Data.Sqlite;
using Microsoft.EntityFrameworkCore.Internal;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public void On_methods_are_noops_when_null()
[Fact]
public void OnWarning_works()
{
string result = null;
string? result = null;
var handler = new OperationReportHandler(warningHandler: m => result = m);
var message = "Princess Celestia is in danger.";

Expand All @@ -34,7 +34,7 @@ public void OnWarning_works()
[Fact]
public void OnInformation_works()
{
string result = null;
string? result = null;
var handler = new OperationReportHandler(informationHandler: m => result = m);
var message = "Princess Celestia is on her way.";

Expand All @@ -46,7 +46,7 @@ public void OnInformation_works()
[Fact]
public void OnVerbose_works()
{
string result = null;
string? result = null;
var handler = new OperationReportHandler(verboseHandler: m => result = m);
var message = "Princess Celestia is an alicorn.";

Expand Down
12 changes: 6 additions & 6 deletions test/EFCore.Design.Tests/DesignApiConsistencyTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,17 @@ public class DesignApiConsistencyFixture : ApiConsistencyFixtureBase
public override HashSet<MethodInfo> VirtualMethodExceptions { get; } =
[
typeof(CSharpEntityTypeGeneratorBase.ToStringInstanceHelper)
.GetProperty(nameof(CSharpEntityTypeGeneratorBase.ToStringInstanceHelper.FormatProvider)).GetMethod,
.GetProperty(nameof(CSharpEntityTypeGeneratorBase.ToStringInstanceHelper.FormatProvider))!.GetMethod!,
typeof(CSharpEntityTypeGeneratorBase.ToStringInstanceHelper)
.GetProperty(nameof(CSharpEntityTypeGeneratorBase.ToStringInstanceHelper.FormatProvider)).SetMethod,
.GetProperty(nameof(CSharpEntityTypeGeneratorBase.ToStringInstanceHelper.FormatProvider))!.SetMethod!,
typeof(CSharpEntityTypeGeneratorBase.ToStringInstanceHelper).GetMethod(
nameof(CSharpEntityTypeGeneratorBase.ToStringInstanceHelper.ToStringWithCulture)),
nameof(CSharpEntityTypeGeneratorBase.ToStringInstanceHelper.ToStringWithCulture))!,
typeof(CSharpDbContextGeneratorBase.ToStringInstanceHelper)
.GetProperty(nameof(CSharpDbContextGeneratorBase.ToStringInstanceHelper.FormatProvider)).GetMethod,
.GetProperty(nameof(CSharpDbContextGeneratorBase.ToStringInstanceHelper.FormatProvider))!.GetMethod!,
typeof(CSharpDbContextGeneratorBase.ToStringInstanceHelper)
.GetProperty(nameof(CSharpDbContextGeneratorBase.ToStringInstanceHelper.FormatProvider)).SetMethod,
.GetProperty(nameof(CSharpDbContextGeneratorBase.ToStringInstanceHelper.FormatProvider))!.SetMethod!,
typeof(CSharpDbContextGeneratorBase.ToStringInstanceHelper).GetMethod(
nameof(CSharpDbContextGeneratorBase.ToStringInstanceHelper.ToStringWithCulture))
nameof(CSharpDbContextGeneratorBase.ToStringInstanceHelper.ToStringWithCulture))!
];
}
}
1 change: 0 additions & 1 deletion test/EFCore.Design.Tests/EFCore.Design.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
<PreserveCompilationContext>true</PreserveCompilationContext>
<AssemblyName>Microsoft.EntityFrameworkCore.Design.Tests</AssemblyName>
<RootNamespace>Microsoft.EntityFrameworkCore</RootNamespace>
<Nullable>disable</Nullable>
<ImplicitUsings>true</ImplicitUsings>
</PropertyGroup>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@ public void GetRequiredUsings_works()
typeof(TestExtensions1)
.GetRuntimeMethod(
nameof(TestExtensions1.Extension1),
[typeof(MethodCallCodeFragmentExtensionsTest), typeof(Action<MethodCallCodeFragmentExtensionsTest>)]),
[typeof(MethodCallCodeFragmentExtensionsTest), typeof(Action<MethodCallCodeFragmentExtensionsTest>)])!,
new NestedClosureCodeFragment(
"x",
new MethodCallCodeFragment(
typeof(TestExtensions2)
.GetRuntimeMethod(
nameof(TestExtensions2.Extension2),
[typeof(MethodCallCodeFragmentExtensionsTest), typeof(TestArgument)]),
[typeof(MethodCallCodeFragmentExtensionsTest), typeof(TestArgument)])!,
new TestArgument())));

var usings = methodCall.GetRequiredUsings();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2386,7 +2386,7 @@ public void InsertDataOperation_all_args()
Columns = ["Id", "Full Name", "Geometry"],
Values = new object[,]
{
{ 0, null, null },
{ 0, null!, null! },
{ 1, "Daenerys Targaryen", _point1 },
{ 2, "John Snow", _polygon1 },
{ 3, "Arya Stark", _lineString1 },
Expand Down Expand Up @@ -2475,7 +2475,7 @@ public void InsertDataOperation_required_empty_array()
Assert.Single(o.Columns);
Assert.Equal(1, o.Values.GetLength(0));
Assert.Equal(1, o.Values.GetLength(1));
Assert.Equal(new string[0], (string[])o.Values[0, 0]);
Assert.Equal(new string[0], (string[])o.Values[0, 0]!);
});

[Fact]
Expand All @@ -2485,7 +2485,7 @@ public void InsertDataOperation_required_empty_array_composite()
{
Table = "People",
Columns = ["First Name", "Last Name", "Geometry"],
Values = new object[,] { { "John", null, Array.Empty<string>() } }
Values = new object[,] { { "John", null!, Array.Empty<string>() } }
},
"""
mb.InsertData(
Expand All @@ -2500,7 +2500,7 @@ public void InsertDataOperation_required_empty_array_composite()
Assert.Equal(1, o.Values.GetLength(0));
Assert.Equal(3, o.Values.GetLength(1));
Assert.Null(o.Values[0, 1]);
Assert.Equal(new string[0], (string[])o.Values[0, 2]);
Assert.Equal(new string[0], (string[])o.Values[0, 2]!);
});

[Fact]
Expand Down Expand Up @@ -2642,7 +2642,7 @@ public void DeleteDataOperation_all_args_composite()
KeyColumnTypes = ["string", "string"],
KeyValues = new object[,]
{
{ "Hodor", null }, { "Daenerys", "Targaryen" }, { "John", "Snow" }, { "Arya", "Stark" }, { "Harry", "Strickland" }
{ "Hodor", null! }, { "Daenerys", "Targaryen" }, { "John", "Snow" }, { "Arya", "Stark" }, { "Harry", "Strickland" }
}
},
"""
Expand Down Expand Up @@ -2802,7 +2802,7 @@ public void UpdateDataOperation_all_args_composite()
{
Table = "People",
KeyColumns = ["First Name", "Last Name"],
KeyValues = new object[,] { { "Hodor", null }, { "Daenerys", "Targaryen" } },
KeyValues = new object[,] { { "Hodor", null! }, { "Daenerys", "Targaryen" } },
Columns = ["House Allegiance"],
Values = new object[,] { { "Stark" }, { "Targaryen" } }
},
Expand Down Expand Up @@ -2842,7 +2842,7 @@ public void UpdateDataOperation_all_args_composite_multi()
{
Table = "People",
KeyColumns = ["First Name", "Last Name"],
KeyValues = new object[,] { { "Hodor", null }, { "Daenerys", "Targaryen" } },
KeyValues = new object[,] { { "Hodor", null! }, { "Daenerys", "Targaryen" } },
Columns = ["Birthplace", "House Allegiance", "Culture"],
Values = new object[,] { { "Winterfell", "Stark", "Northmen" }, { "Dragonstone", "Targaryen", "Valyrian" } }
},
Expand Down Expand Up @@ -3203,9 +3203,9 @@ public static void Create(MigrationBuilder mb)

var assembly = build.BuildInMemory();
var factoryType = assembly.GetType("OperationsFactory");
var createMethod = factoryType.GetTypeInfo().GetDeclaredMethod("Create");
var createMethod = factoryType!.GetTypeInfo().GetDeclaredMethod("Create");
var mb = new MigrationBuilder(activeProvider: null);
createMethod.Invoke(null, [mb]);
createMethod!.Invoke(null, [mb]);
var result = mb.Operations.Cast<T>().Single();

assert(result);
Expand Down
Loading
Loading