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

Switch to using EqualsExact in geometry comparer #18946

Merged
merged 1 commit into from
Nov 16, 2019
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
2 changes: 1 addition & 1 deletion src/EFCore/ChangeTracking/GeometryValueComparer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ private static Expression<Func<TGeometry, TGeometry, bool>> GetEqualsExpression(
return Expression.Lambda<Func<TGeometry, TGeometry, bool>>(
Expression.Call(
left,
typeof(TGeometry).GetRuntimeMethod("EqualsTopologically", new[] { typeof(TGeometry) }),
typeof(TGeometry).GetRuntimeMethod("EqualsExact", new[] { typeof(TGeometry) }),
right),
left,
right);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.

using System;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
using NetTopologySuite.Geometries;
using Xunit;

namespace Microsoft.EntityFrameworkCore.Storage
{
public class RelationalGeometryTypeMappingTest
{
[ConditionalFact]
public void Comparer_uses_exact_comparison()
{
var geometry1 = new GeometryCollection(new[]
{
new Point(1, 2),
new Point(3, 4)
});
var geometry2 = new GeometryCollection(new[]
{
new Point(3, 4),
new Point(1, 2)
});

var comparer = new FakeRelationalGeometryTypeMapping<GeometryCollection>().Comparer;
Assert.False(comparer.Equals(geometry1, geometry2));
}

private class FakeRelationalGeometryTypeMapping<TGeometry> : RelationalGeometryTypeMapping<TGeometry, TGeometry>
{
public FakeRelationalGeometryTypeMapping()
: base(new NullValueConverter(), "geometry")
{
}

private FakeRelationalGeometryTypeMapping(RelationalTypeMappingParameters parameters)
: base(parameters, new NullValueConverter())
{
}

protected override RelationalTypeMapping Clone(RelationalTypeMappingParameters parameters)
=> new FakeRelationalGeometryTypeMapping<TGeometry>(parameters);

protected override Type WKTReaderType { get; }
protected override string AsText(object value) => throw new NotImplementedException();
protected override int GetSrid(object value) => throw new NotImplementedException();

class NullValueConverter : ValueConverter<TGeometry, TGeometry>
{
public NullValueConverter() : base(t => t, t => t) {}
}
}

}
}