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

Enable testing of compiled models in CI #34111

Merged
merged 4 commits into from
Jul 2, 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
Original file line number Diff line number Diff line change
Expand Up @@ -146,13 +146,13 @@ public virtual Task Basic_cosmos_model()
Assert.Equal(new[] { id, partitionId, blob, storeId, jObject, eTag }, dataEntity.GetProperties());
});

// Primitive collections not supported yet
[ConditionalFact(Skip = "Primitive collections not supported yet")]
public override Task BigModel()
=> Task.CompletedTask;
=> base.BigModel();

// Primitive collections not supported yet
[ConditionalFact(Skip = "Primitive collections not supported yet")]
public override Task ComplexTypes()
=> Task.CompletedTask;
=> base.ComplexTypes();

protected override TestHelpers TestHelpers => CosmosTestHelpers.Instance;
protected override ITestStoreFactory TestStoreFactory => CosmosTestStoreFactory.Instance;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -494,9 +494,9 @@ protected virtual void AssertCyclesModel(IModel model)
TestHelpers.ModelAsserter.AssertEqual(principalBaseFk.PrincipalKey.Properties, dependentFk.Properties);
}

// Primitive collections not supported completely
[ConditionalFact(Skip = "Primitive collections not supported completely")]
public override Task BigModel()
=> Task.CompletedTask;
=> base.BigModel();

public class Scaffolding
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1465,7 +1465,8 @@ private IModel CompileModel(
{
var build = new BuildSource
{
Sources = scaffoldedFiles.ToDictionary(f => f.Path, f => f.Code), NullableReferenceTypes = options.UseNullableReferenceTypes
Sources = scaffoldedFiles.ToDictionary(f => f.Path, f => f.Code),
NullableReferenceTypes = options.UseNullableReferenceTypes
};
AddReferences(build);

Expand All @@ -1491,42 +1492,50 @@ private void AssertBaseline(
string testName)
{
var testDirectory = Path.GetDirectoryName(_filePath);
if (string.IsNullOrEmpty(testDirectory)
|| !Directory.Exists(testDirectory))
if (string.IsNullOrEmpty(testDirectory))
{
return;
return; // cannot look for the baseline
}

var baselinesDirectory = Path.Combine(testDirectory, "Baselines", testName);
try
var prefix = Path.DirectorySeparatorChar + "_" + Path.DirectorySeparatorChar;
if (testDirectory.StartsWith(prefix))
{
Directory.CreateDirectory(baselinesDirectory);
// assumes a current directory like /path/to/efcore/artifacts/bin/EFCore.Sqlite.FunctionalTests/Release/net9.0
// so that a path mangled by DeterministicSourcePaths such as /_/test/EFCore.Sqlite.FunctionalTests/Scaffolding becomes
// /path/to/efcore/test/EFCore.Sqlite.FunctionalTests/Scaffolding
testDirectory = string.Join(Path.DirectorySeparatorChar, Enumerable.Repeat("..", 5)) + testDirectory[2..];
}
catch
if (!Directory.Exists(testDirectory))
{
return;
throw new Exception($"Test directory '{testDirectory}' not found from '{Directory.GetCurrentDirectory()}'");
}

var baselinesDirectory = Path.Combine(testDirectory, "Baselines", testName);
Directory.CreateDirectory(baselinesDirectory);

var shouldRewrite = Environment.GetEnvironmentVariable("EF_TEST_REWRITE_BASELINES")?.ToUpper() is "1" or "TRUE";
List<Exception> exceptions = [];
foreach (var file in scaffoldedFiles)
{
var fullFilePath = Path.Combine(baselinesDirectory, file.Path);
if (!File.Exists(fullFilePath)
|| shouldRewrite)
try
{
File.WriteAllText(fullFilePath, file.Code);
Assert.Equal(File.ReadAllText(fullFilePath), file.Code, ignoreLineEndingDifferences: true);
}
else
catch (Exception ex)
{
try
{
Assert.Equal(File.ReadAllText(fullFilePath), file.Code, ignoreLineEndingDifferences: true);
}
catch (Exception ex)
if (shouldRewrite)
{
throw new Exception($"Difference found in {file.Path}", ex);
File.WriteAllText(fullFilePath, file.Code);
}

exceptions.Add(new Exception($"Difference found in {file.Path}", ex));
}
}

if (exceptions.Count > 0)
{
throw new AggregateException($"Differences found in {exceptions.Count} files", exceptions);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14933,11 +14933,11 @@ public static RuntimeEntityType Create(RuntimeModel model, RuntimeEntityType bas
storeGenerationIndex: -1);
nullableUri.TypeMapping = SqlServerStringTypeMapping.Default.Clone(
comparer: new ValueComparer<Uri>(
(Uri v1, Uri v2) => v1 == v2,
(Uri v1, Uri v2) => v1 == null && v2 == null || v1 != null && v2 != null && v1.Equals(v2),
(Uri v) => ((object)v).GetHashCode(),
(Uri v) => v),
keyComparer: new ValueComparer<Uri>(
(Uri v1, Uri v2) => v1 == v2,
(Uri v1, Uri v2) => v1 == null && v2 == null || v1 != null && v2 != null && v1.Equals(v2),
(Uri v) => ((object)v).GetHashCode(),
(Uri v) => v),
providerValueComparer: new ValueComparer<string>(
Expand Down Expand Up @@ -14988,11 +14988,11 @@ public static RuntimeEntityType Create(RuntimeModel model, RuntimeEntityType bas
storeGenerationIndex: -1);
nullableUriArray.TypeMapping = SqlServerStringTypeMapping.Default.Clone(
comparer: new ListOfReferenceTypesComparer<Uri[], Uri>(new ValueComparer<Uri>(
(Uri v1, Uri v2) => v1 == v2,
(Uri v1, Uri v2) => v1 == null && v2 == null || v1 != null && v2 != null && v1.Equals(v2),
(Uri v) => ((object)v).GetHashCode(),
(Uri v) => v)),
keyComparer: new ListOfReferenceTypesComparer<Uri[], Uri>(new ValueComparer<Uri>(
(Uri v1, Uri v2) => v1 == v2,
(Uri v1, Uri v2) => v1 == null && v2 == null || v1 != null && v2 != null && v1.Equals(v2),
(Uri v) => ((object)v).GetHashCode(),
(Uri v) => v)),
providerValueComparer: new ValueComparer<string>(
Expand All @@ -15018,11 +15018,11 @@ public static RuntimeEntityType Create(RuntimeModel model, RuntimeEntityType bas
(string v) => new Uri(v, UriKind.RelativeOrAbsolute)))),
elementMapping: SqlServerStringTypeMapping.Default.Clone(
comparer: new ValueComparer<Uri>(
(Uri v1, Uri v2) => v1 == v2,
(Uri v1, Uri v2) => v1 == null && v2 == null || v1 != null && v2 != null && v1.Equals(v2),
(Uri v) => ((object)v).GetHashCode(),
(Uri v) => v),
keyComparer: new ValueComparer<Uri>(
(Uri v1, Uri v2) => v1 == v2,
(Uri v1, Uri v2) => v1 == null && v2 == null || v1 != null && v2 != null && v1.Equals(v2),
(Uri v) => ((object)v).GetHashCode(),
(Uri v) => v),
providerValueComparer: new ValueComparer<string>(
Expand Down Expand Up @@ -17259,11 +17259,11 @@ public static RuntimeEntityType Create(RuntimeModel model, RuntimeEntityType bas
storeGenerationIndex: -1);
uri.TypeMapping = SqlServerStringTypeMapping.Default.Clone(
comparer: new ValueComparer<Uri>(
(Uri v1, Uri v2) => v1 == v2,
(Uri v1, Uri v2) => v1 == null && v2 == null || v1 != null && v2 != null && v1.Equals(v2),
(Uri v) => ((object)v).GetHashCode(),
(Uri v) => v),
keyComparer: new ValueComparer<Uri>(
(Uri v1, Uri v2) => v1 == v2,
(Uri v1, Uri v2) => v1 == null && v2 == null || v1 != null && v2 != null && v1.Equals(v2),
(Uri v) => ((object)v).GetHashCode(),
(Uri v) => v),
providerValueComparer: new ValueComparer<string>(
Expand Down Expand Up @@ -17314,11 +17314,11 @@ public static RuntimeEntityType Create(RuntimeModel model, RuntimeEntityType bas
storeGenerationIndex: -1);
uriArray.TypeMapping = SqlServerStringTypeMapping.Default.Clone(
comparer: new ListOfReferenceTypesComparer<Uri[], Uri>(new ValueComparer<Uri>(
(Uri v1, Uri v2) => v1 == v2,
(Uri v1, Uri v2) => v1 == null && v2 == null || v1 != null && v2 != null && v1.Equals(v2),
(Uri v) => ((object)v).GetHashCode(),
(Uri v) => v)),
keyComparer: new ListOfReferenceTypesComparer<Uri[], Uri>(new ValueComparer<Uri>(
(Uri v1, Uri v2) => v1 == v2,
(Uri v1, Uri v2) => v1 == null && v2 == null || v1 != null && v2 != null && v1.Equals(v2),
(Uri v) => ((object)v).GetHashCode(),
(Uri v) => v)),
providerValueComparer: new ValueComparer<string>(
Expand All @@ -17344,11 +17344,11 @@ public static RuntimeEntityType Create(RuntimeModel model, RuntimeEntityType bas
(string v) => new Uri(v, UriKind.RelativeOrAbsolute)))),
elementMapping: SqlServerStringTypeMapping.Default.Clone(
comparer: new ValueComparer<Uri>(
(Uri v1, Uri v2) => v1 == v2,
(Uri v1, Uri v2) => v1 == null && v2 == null || v1 != null && v2 != null && v1.Equals(v2),
(Uri v) => ((object)v).GetHashCode(),
(Uri v) => v),
keyComparer: new ValueComparer<Uri>(
(Uri v1, Uri v2) => v1 == v2,
(Uri v1, Uri v2) => v1 == null && v2 == null || v1 != null && v2 != null && v1.Equals(v2),
(Uri v) => ((object)v).GetHashCode(),
(Uri v) => v),
providerValueComparer: new ValueComparer<string>(
Expand Down Expand Up @@ -17400,11 +17400,11 @@ public static RuntimeEntityType Create(RuntimeModel model, RuntimeEntityType bas
storeGenerationIndex: -1);
uriToStringConverterProperty.TypeMapping = SqlServerStringTypeMapping.Default.Clone(
comparer: new ValueComparer<Uri>(
(Uri v1, Uri v2) => v1 == v2,
(Uri v1, Uri v2) => v1 == null && v2 == null || v1 != null && v2 != null && v1.Equals(v2),
(Uri v) => ((object)v).GetHashCode(),
(Uri v) => v),
keyComparer: new ValueComparer<Uri>(
(Uri v1, Uri v2) => v1 == v2,
(Uri v1, Uri v2) => v1 == null && v2 == null || v1 != null && v2 != null && v1.Equals(v2),
(Uri v) => ((object)v).GetHashCode(),
(Uri v) => v),
providerValueComparer: new ValueComparer<string>(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14933,11 +14933,11 @@ public static RuntimeEntityType Create(RuntimeModel model, RuntimeEntityType bas
storeGenerationIndex: -1);
nullableUri.TypeMapping = SqlServerStringTypeMapping.Default.Clone(
comparer: new ValueComparer<Uri>(
(Uri v1, Uri v2) => v1 == v2,
(Uri v1, Uri v2) => v1 == null && v2 == null || v1 != null && v2 != null && v1.Equals(v2),
(Uri v) => ((object)v).GetHashCode(),
(Uri v) => v),
keyComparer: new ValueComparer<Uri>(
(Uri v1, Uri v2) => v1 == v2,
(Uri v1, Uri v2) => v1 == null && v2 == null || v1 != null && v2 != null && v1.Equals(v2),
(Uri v) => ((object)v).GetHashCode(),
(Uri v) => v),
providerValueComparer: new ValueComparer<string>(
Expand Down Expand Up @@ -14988,11 +14988,11 @@ public static RuntimeEntityType Create(RuntimeModel model, RuntimeEntityType bas
storeGenerationIndex: -1);
nullableUriArray.TypeMapping = SqlServerStringTypeMapping.Default.Clone(
comparer: new ListOfReferenceTypesComparer<Uri[], Uri>(new ValueComparer<Uri>(
(Uri v1, Uri v2) => v1 == v2,
(Uri v1, Uri v2) => v1 == null && v2 == null || v1 != null && v2 != null && v1.Equals(v2),
(Uri v) => ((object)v).GetHashCode(),
(Uri v) => v)),
keyComparer: new ListOfReferenceTypesComparer<Uri[], Uri>(new ValueComparer<Uri>(
(Uri v1, Uri v2) => v1 == v2,
(Uri v1, Uri v2) => v1 == null && v2 == null || v1 != null && v2 != null && v1.Equals(v2),
(Uri v) => ((object)v).GetHashCode(),
(Uri v) => v)),
providerValueComparer: new ValueComparer<string>(
Expand All @@ -15018,11 +15018,11 @@ public static RuntimeEntityType Create(RuntimeModel model, RuntimeEntityType bas
(string v) => new Uri(v, UriKind.RelativeOrAbsolute)))),
elementMapping: SqlServerStringTypeMapping.Default.Clone(
comparer: new ValueComparer<Uri>(
(Uri v1, Uri v2) => v1 == v2,
(Uri v1, Uri v2) => v1 == null && v2 == null || v1 != null && v2 != null && v1.Equals(v2),
(Uri v) => ((object)v).GetHashCode(),
(Uri v) => v),
keyComparer: new ValueComparer<Uri>(
(Uri v1, Uri v2) => v1 == v2,
(Uri v1, Uri v2) => v1 == null && v2 == null || v1 != null && v2 != null && v1.Equals(v2),
(Uri v) => ((object)v).GetHashCode(),
(Uri v) => v),
providerValueComparer: new ValueComparer<string>(
Expand Down Expand Up @@ -17259,11 +17259,11 @@ public static RuntimeEntityType Create(RuntimeModel model, RuntimeEntityType bas
storeGenerationIndex: -1);
uri.TypeMapping = SqlServerStringTypeMapping.Default.Clone(
comparer: new ValueComparer<Uri>(
(Uri v1, Uri v2) => v1 == v2,
(Uri v1, Uri v2) => v1 == null && v2 == null || v1 != null && v2 != null && v1.Equals(v2),
(Uri v) => ((object)v).GetHashCode(),
(Uri v) => v),
keyComparer: new ValueComparer<Uri>(
(Uri v1, Uri v2) => v1 == v2,
(Uri v1, Uri v2) => v1 == null && v2 == null || v1 != null && v2 != null && v1.Equals(v2),
(Uri v) => ((object)v).GetHashCode(),
(Uri v) => v),
providerValueComparer: new ValueComparer<string>(
Expand Down Expand Up @@ -17314,11 +17314,11 @@ public static RuntimeEntityType Create(RuntimeModel model, RuntimeEntityType bas
storeGenerationIndex: -1);
uriArray.TypeMapping = SqlServerStringTypeMapping.Default.Clone(
comparer: new ListOfReferenceTypesComparer<Uri[], Uri>(new ValueComparer<Uri>(
(Uri v1, Uri v2) => v1 == v2,
(Uri v1, Uri v2) => v1 == null && v2 == null || v1 != null && v2 != null && v1.Equals(v2),
(Uri v) => ((object)v).GetHashCode(),
(Uri v) => v)),
keyComparer: new ListOfReferenceTypesComparer<Uri[], Uri>(new ValueComparer<Uri>(
(Uri v1, Uri v2) => v1 == v2,
(Uri v1, Uri v2) => v1 == null && v2 == null || v1 != null && v2 != null && v1.Equals(v2),
(Uri v) => ((object)v).GetHashCode(),
(Uri v) => v)),
providerValueComparer: new ValueComparer<string>(
Expand All @@ -17344,11 +17344,11 @@ public static RuntimeEntityType Create(RuntimeModel model, RuntimeEntityType bas
(string v) => new Uri(v, UriKind.RelativeOrAbsolute)))),
elementMapping: SqlServerStringTypeMapping.Default.Clone(
comparer: new ValueComparer<Uri>(
(Uri v1, Uri v2) => v1 == v2,
(Uri v1, Uri v2) => v1 == null && v2 == null || v1 != null && v2 != null && v1.Equals(v2),
(Uri v) => ((object)v).GetHashCode(),
(Uri v) => v),
keyComparer: new ValueComparer<Uri>(
(Uri v1, Uri v2) => v1 == v2,
(Uri v1, Uri v2) => v1 == null && v2 == null || v1 != null && v2 != null && v1.Equals(v2),
(Uri v) => ((object)v).GetHashCode(),
(Uri v) => v),
providerValueComparer: new ValueComparer<string>(
Expand Down Expand Up @@ -17400,11 +17400,11 @@ public static RuntimeEntityType Create(RuntimeModel model, RuntimeEntityType bas
storeGenerationIndex: -1);
uriToStringConverterProperty.TypeMapping = SqlServerStringTypeMapping.Default.Clone(
comparer: new ValueComparer<Uri>(
(Uri v1, Uri v2) => v1 == v2,
(Uri v1, Uri v2) => v1 == null && v2 == null || v1 != null && v2 != null && v1.Equals(v2),
(Uri v) => ((object)v).GetHashCode(),
(Uri v) => v),
keyComparer: new ValueComparer<Uri>(
(Uri v1, Uri v2) => v1 == v2,
(Uri v1, Uri v2) => v1 == null && v2 == null || v1 != null && v2 != null && v1.Equals(v2),
(Uri v) => ((object)v).GetHashCode(),
(Uri v) => v),
providerValueComparer: new ValueComparer<string>(
Expand Down
Loading