Skip to content

Commit

Permalink
Query: Reenable tests
Browse files Browse the repository at this point in the history
Update test for #15889 to do client eval
Update test for #15964 to do client eval
Implement cast on InMemory
Fix bug when rewriting assignments to initonly fields
Fix literal generation for Point.Empty on SqlServer
Fix condition on when to materialize key less entityType
  • Loading branch information
smitpatel committed Jun 7, 2019
1 parent 68127d9 commit 9f20206
Show file tree
Hide file tree
Showing 39 changed files with 429 additions and 247 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,17 @@ protected override ShapedQueryExpression TranslateAny(ShapedQueryExpression sour
protected override ShapedQueryExpression TranslateAverage(ShapedQueryExpression source, LambdaExpression selector, Type resultType)
=> TranslateScalarAggregate(source, selector, nameof(Enumerable.Average));

protected override ShapedQueryExpression TranslateCast(ShapedQueryExpression source, Type resultType) => throw new NotImplementedException();
protected override ShapedQueryExpression TranslateCast(ShapedQueryExpression source, Type resultType)
{
if (source.ShaperExpression.Type == resultType)
{
return source;
}

source.ShaperExpression = Expression.Convert(source.ShaperExpression, resultType);

return source;
}

protected override ShapedQueryExpression TranslateConcat(ShapedQueryExpression source1, ShapedQueryExpression source2) => throw new NotImplementedException();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using System.Linq;
using System.Linq.Expressions;
using System.Reflection;
using Microsoft.EntityFrameworkCore.Internal;
using Microsoft.EntityFrameworkCore.Metadata;
using Microsoft.EntityFrameworkCore.Metadata.Internal;
using Microsoft.EntityFrameworkCore.Query.Pipeline;
Expand Down Expand Up @@ -49,6 +50,15 @@ protected override Expression VisitBinary(BinaryExpression binaryExpression)
return Expression.MakeBinary(ExpressionType.Assign, binaryExpression.Left, updatedExpression);
}

if (binaryExpression.NodeType == ExpressionType.Assign
&& binaryExpression.Left is MemberExpression memberExpression
&& memberExpression.Member is FieldInfo fieldInfo
&& fieldInfo.IsInitOnly)
{
return memberExpression.Assign(Visit(binaryExpression.Right));
}


return base.VisitBinary(binaryExpression);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
using Microsoft.EntityFrameworkCore.SqlServer.Storage.ValueConversion.Internal;
using Microsoft.EntityFrameworkCore.Storage;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
using NetTopologySuite.Geometries;
using NetTopologySuite.IO;

namespace Microsoft.EntityFrameworkCore.SqlServer.Storage.Internal
Expand Down Expand Up @@ -80,6 +81,10 @@ protected override string GenerateNonNullSqlLiteral(object value)
var builder = new StringBuilder();
var geometry = (IGeometry)value;
var defaultSrid = geometry.SRID == (_isGeography ? 4326 : 0);
if (geometry == Point.Empty)
{
defaultSrid = true;
}

builder
.Append(_isGeography ? "geography" : "geometry")
Expand Down
8 changes: 4 additions & 4 deletions src/EFCore/DbContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -391,7 +391,7 @@ protected internal virtual void OnModelCreating(ModelBuilder modelBuilder)
/// <summary>
/// <para>
/// Saves all changes made in this context to the database.
/// </para>
/// </para>
/// <para>
/// This method will automatically call <see cref="ChangeTracking.ChangeTracker.DetectChanges" /> to discover any
/// changes to entity instances before saving to the underlying database. This can be disabled via
Expand All @@ -414,7 +414,7 @@ protected internal virtual void OnModelCreating(ModelBuilder modelBuilder)
/// <summary>
/// <para>
/// Saves all changes made in this context to the database.
/// </para>
/// </para>
/// <para>
/// This method will automatically call <see cref="ChangeTracking.ChangeTracker.DetectChanges" /> to discover any
/// changes to entity instances before saving to the underlying database. This can be disabled via
Expand Down Expand Up @@ -485,7 +485,7 @@ private void TryDetectChanges(EntityEntry entry)
/// <summary>
/// <para>
/// Saves all changes made in this context to the database.
/// </para>
/// </para>
/// <para>
/// This method will automatically call <see cref="ChangeTracking.ChangeTracker.DetectChanges" /> to discover any
/// changes to entity instances before saving to the underlying database. This can be disabled via
Expand Down Expand Up @@ -515,7 +515,7 @@ public virtual Task<int> SaveChangesAsync(CancellationToken cancellationToken =
/// <summary>
/// <para>
/// Saves all changes made in this context to the database.
/// </para>
/// </para>
/// <para>
/// This method will automatically call <see cref="ChangeTracking.ChangeTracker.DetectChanges" /> to discover any
/// changes to entity instances before saving to the underlying database. This can be disabled via
Expand Down
52 changes: 0 additions & 52 deletions src/EFCore/Extensions/Internal/ExpressionExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -321,58 +321,6 @@ public static MemberExpression MakeMemberAccess(
return Expression.MakeMemberAccess(expression, member);
}

/// <summary>
/// This is an internal API that supports the Entity Framework Core infrastructure and not subject to
/// the same compatibility standards as public APIs. It may be changed or removed without notice in
/// any release. You should only use it directly in your code with extreme caution and knowing that
/// doing so can result in application failures when updating to a new Entity Framework Core release.
/// </summary>
public static bool IsNullPropagationCandidate(
[NotNull] this ConditionalExpression conditionalExpression,
out Expression testExpression,
out Expression resultExpression)
{
Check.NotNull(conditionalExpression, nameof(conditionalExpression));

testExpression = null;
resultExpression = null;

if (!(conditionalExpression.Test is BinaryExpression binaryTest)
|| !(binaryTest.NodeType == ExpressionType.Equal
|| binaryTest.NodeType == ExpressionType.NotEqual))
{
return false;
}

var isLeftNullConstant = binaryTest.Left.IsNullConstantExpression();
var isRightNullConstant = binaryTest.Right.IsNullConstantExpression();

if (isLeftNullConstant == isRightNullConstant)
{
return false;
}

if (binaryTest.NodeType == ExpressionType.Equal)
{
if (!conditionalExpression.IfTrue.IsNullConstantExpression())
{
return false;
}
}
else
{
if (!conditionalExpression.IfFalse.IsNullConstantExpression())
{
return false;
}
}

testExpression = isLeftNullConstant ? binaryTest.Right : binaryTest.Left;
resultExpression = binaryTest.NodeType == ExpressionType.Equal ? conditionalExpression.IfFalse : conditionalExpression.IfTrue;

return true;
}

/// <summary>
/// This is an internal API that supports the Entity Framework Core infrastructure and not subject to
/// the same compatibility standards as public APIs. It may be changed or removed without notice in
Expand Down
16 changes: 12 additions & 4 deletions src/EFCore/Query/Pipeline/ShapedQueryExpressionVisitor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -279,17 +279,25 @@ private Expression ProcessEntityShaper(EntityShaperExpression entityShaperExpres
{
expressions.Add(Expression.Condition(
(primaryKey != null
? primaryKey.Properties
: entityType.GetProperties())
.Select(p =>
? primaryKey.Properties.Select(p =>
Expression.Equal(
_entityMaterializerSource.CreateReadValueExpression(
entityShaperExpression.ValueBufferExpression,
typeof(object),
p.GetIndex(),
p),
Expression.Constant(null)))
.Aggregate((a, b) => Expression.OrElse(a, b)),
.Aggregate((a, b) => Expression.OrElse(a, b))
: entityType.GetProperties()
.Select(p =>
Expression.Equal(
_entityMaterializerSource.CreateReadValueExpression(
entityShaperExpression.ValueBufferExpression,
typeof(object),
p.GetIndex(),
p),
Expression.Constant(null)))
.Aggregate((a, b) => Expression.AndAlso(a, b))),
Expression.Constant(null, entityType.ClrType),
MaterializeEntity(entityType, valueBuffer)));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,12 @@ public override void Can_insert_and_read_back_with_string_key()
base.Can_insert_and_read_back_with_string_key();
}

[ConditionalFact(Skip = "Issue#15711")]
public override void Can_query_and_update_with_nullable_converter_on_primary_key()
{
base.Can_query_and_update_with_nullable_converter_on_primary_key();
}

public class CustomConvertersInMemoryFixture : CustomConvertersFixtureBase
{
public override bool StrictEquality => true;
Expand Down
127 changes: 127 additions & 0 deletions test/EFCore.InMemory.FunctionalTests/FieldMappingInMemoryTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

using Microsoft.EntityFrameworkCore.Diagnostics;
using Microsoft.EntityFrameworkCore.TestUtilities;
using Microsoft.EntityFrameworkCore.TestUtilities.Xunit;

namespace Microsoft.EntityFrameworkCore
{
Expand All @@ -13,6 +14,132 @@ public FieldMappingInMemoryTest(FieldMappingInMemoryFixture fixture)
{
}

[ConditionalFact(Skip = "Issue#15711")]
public override void Field_mapping_with_conversion_does_not_throw()
{
base.Field_mapping_with_conversion_does_not_throw();
}

[ConditionalTheory(Skip = "Issue#15711")]
public override void Include_collection_auto_props(bool tracking)
{
base.Include_collection_auto_props(tracking);
}

[ConditionalTheory(Skip = "Issue#15711")]
public override void Include_collection_fields_only(bool tracking)
{
base.Include_collection_fields_only(tracking);
}

[ConditionalTheory(Skip = "Issue#15711")]
public override void Include_collection_fields_only_for_navs_too(bool tracking)
{
base.Include_collection_fields_only_for_navs_too(tracking);
}

[ConditionalTheory(Skip = "Issue#15711")]
public override void Include_collection_full_props(bool tracking)
{
base.Include_collection_full_props(tracking);
}

[ConditionalTheory(Skip = "Issue#15711")]
public override void Include_collection_full_props_with_named_fields(bool tracking)
{
base.Include_collection_full_props_with_named_fields(tracking);
}

[ConditionalTheory(Skip = "Issue#15711")]
public override void Include_collection_hiding_props(bool tracking)
{
base.Include_collection_hiding_props(tracking);
}

[ConditionalTheory(Skip = "Issue#15711")]
public override void Include_collection_read_only_props(bool tracking)
{
base.Include_collection_read_only_props(tracking);
}

[ConditionalTheory(Skip = "Issue#15711")]
public override void Include_collection_read_only_props_with_named_fields(bool tracking)
{
base.Include_collection_read_only_props_with_named_fields(tracking);
}

[ConditionalTheory(Skip = "Issue#15711")]
public override void Include_collection_write_only_props(bool tracking)
{
base.Include_collection_write_only_props(tracking);
}

[ConditionalTheory(Skip = "Issue#15711")]
public override void Include_collection_write_only_props_with_named_fields(bool tracking)
{
base.Include_collection_write_only_props_with_named_fields(tracking);
}

[ConditionalTheory(Skip = "Issue#15711")]
public override void Include_reference_auto_props(bool tracking)
{
base.Include_reference_auto_props(tracking);
}

[ConditionalTheory(Skip = "Issue#15711")]
public override void Include_reference_fields_only(bool tracking)
{
base.Include_reference_fields_only(tracking);
}

[ConditionalTheory(Skip = "Issue#15711")]
public override void Include_reference_fields_only_only_for_navs_too(bool tracking)
{
base.Include_reference_fields_only_only_for_navs_too(tracking);
}

[ConditionalTheory(Skip = "Issue#15711")]
public override void Include_reference_full_props(bool tracking)
{
base.Include_reference_full_props(tracking);
}

[ConditionalTheory(Skip = "Issue#15711")]
public override void Include_reference_full_props_with_named_fields(bool tracking)
{
base.Include_reference_full_props_with_named_fields(tracking);
}

[ConditionalTheory(Skip = "Issue#15711")]
public override void Include_reference_hiding_props(bool tracking)
{
base.Include_reference_hiding_props(tracking);
}

[ConditionalTheory(Skip = "Issue#15711")]
public override void Include_reference_read_only_props(bool tracking)
{
base.Include_reference_read_only_props(tracking);
}

[ConditionalTheory(Skip = "Issue#15711")]
public override void Include_reference_read_only_props_with_named_fields(bool tracking)
{
base.Include_reference_read_only_props_with_named_fields(tracking);
}

[ConditionalTheory(Skip = "Issue#15711")]
public override void Include_reference_write_only_props(bool tracking)
{
base.Include_reference_write_only_props(tracking);
}

[ConditionalTheory(Skip = "Issue#15711")]
public override void Include_reference_write_only_props_with_named_fields(bool tracking)
{
base.Include_reference_write_only_props_with_named_fields(tracking);
}

protected override void Update<TBlog>(string navigation)
{
base.Update<TBlog>(navigation);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ public class InMemoryComplianceTest : ComplianceTestBase
typeof(SpatialQueryTestBase<>),
typeof(UpdatesTestBase<>),
typeof(FindTestBase<>),
typeof(NotificationEntitiesTestBase<>),
typeof(PropertyValuesTestBase<>),
};

protected override Assembly TargetAssembly { get; } = typeof(InMemoryComplianceTest).Assembly;
Expand Down
Loading

0 comments on commit 9f20206

Please sign in to comment.