Skip to content

Commit 35bc9f0

Browse files
author
Tomas Lukac
committed
additional fix of object equality used in tests
1 parent 39bd7e5 commit 35bc9f0

File tree

2 files changed

+5
-72
lines changed

2 files changed

+5
-72
lines changed

src/NHibernate.Test/Async/NHSpecificTest/GH1879/ExpansionRegressionTests.cs

+1-30
Original file line numberDiff line numberDiff line change
@@ -40,36 +40,7 @@ protected override void OnSetUp()
4040
session.Flush();
4141
transaction.Commit();
4242
}
43-
}
44-
45-
protected override void Configure(Configuration configuration)
46-
{
47-
configuration.LinqToHqlGeneratorsRegistry<TestLinqToHqlGeneratorsRegistry>();
48-
}
49-
50-
private class TestLinqToHqlGeneratorsRegistry : DefaultLinqToHqlGeneratorsRegistry
51-
{
52-
public TestLinqToHqlGeneratorsRegistry()
53-
{
54-
this.Merge(new ObjectEquality());
55-
}
56-
}
57-
58-
private class ObjectEquality : IHqlGeneratorForMethod
59-
{
60-
public HqlTreeNode BuildHql(MethodInfo method, Expression targetObject, ReadOnlyCollection<Expression> arguments, HqlTreeBuilder treeBuilder, IHqlExpressionVisitor visitor)
61-
{
62-
return treeBuilder.Equality(visitor.Visit(targetObject).AsExpression(), visitor.Visit(arguments[0]).AsExpression());
63-
}
64-
65-
public IEnumerable<MethodInfo> SupportedMethods
66-
{
67-
get
68-
{
69-
yield return ReflectHelper.GetMethodDefinition<object>(x => x.Equals(x));
70-
}
71-
}
72-
}
43+
}
7344

7445
[Test]
7546
public async Task MethodShouldNotExpandForNonConditionalOrCoalesceAsync()

src/NHibernate.Test/NHSpecificTest/GH1879/ExpansionRegressionTests.cs

+4-42
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,4 @@
1-
using System.Collections.Generic;
2-
using System.Collections.ObjectModel;
3-
using System.Linq;
4-
using System.Linq.Expressions;
5-
using System.Reflection;
6-
using NHibernate.Cfg;
7-
using NHibernate.Hql.Ast;
8-
using NHibernate.Linq.Functions;
9-
using NHibernate.Linq.Visitors;
10-
using NHibernate.Util;
1+
using System.Linq;
112
using NUnit.Framework;
123

134
namespace NHibernate.Test.NHSpecificTest.GH1879
@@ -30,41 +21,12 @@ protected override void OnSetUp()
3021
}
3122
}
3223

33-
protected override void Configure(Configuration configuration)
34-
{
35-
configuration.LinqToHqlGeneratorsRegistry<TestLinqToHqlGeneratorsRegistry>();
36-
}
37-
38-
private class TestLinqToHqlGeneratorsRegistry : DefaultLinqToHqlGeneratorsRegistry
39-
{
40-
public TestLinqToHqlGeneratorsRegistry()
41-
{
42-
this.Merge(new ObjectEquality());
43-
}
44-
}
45-
46-
private class ObjectEquality : IHqlGeneratorForMethod
47-
{
48-
public HqlTreeNode BuildHql(MethodInfo method, Expression targetObject, ReadOnlyCollection<Expression> arguments, HqlTreeBuilder treeBuilder, IHqlExpressionVisitor visitor)
49-
{
50-
return treeBuilder.Equality(visitor.Visit(targetObject).AsExpression(), visitor.Visit(arguments[0]).AsExpression());
51-
}
52-
53-
public IEnumerable<MethodInfo> SupportedMethods
54-
{
55-
get
56-
{
57-
yield return ReflectHelper.GetMethodDefinition<object>(x => x.Equals(x));
58-
}
59-
}
60-
}
61-
6224
[Test]
6325
public void MethodShouldNotExpandForNonConditionalOrCoalesce()
6426
{
6527
using (var session = OpenSession())
6628
{
67-
Assert.That(session.Query<Invoice>().Count(e => ((object)(e.Amount + e.SpecialAmount)).Equals(110)), Is.EqualTo(2));
29+
Assert.That(session.Query<Invoice>().Count(e => ((object) (e.Amount + e.SpecialAmount)).Equals(110)), Is.EqualTo(2));
6830
}
6931
}
7032

@@ -73,7 +35,7 @@ public void MethodShouldNotExpandForConditionalWithPropertyAccessor()
7335
{
7436
using (var session = OpenSession())
7537
{
76-
Assert.That(session.Query<Invoice>().Count(e => ((object)(e.Paid ? e.Amount : e.SpecialAmount)).Equals(10)), Is.EqualTo(2));
38+
Assert.That(session.Query<Invoice>().Count(e => ((object) (e.Paid ? e.Amount : e.SpecialAmount)).Equals(10)), Is.EqualTo(2));
7739
}
7840
}
7941

@@ -82,7 +44,7 @@ public void MethodShouldNotExpandForCoalesceWithPropertyAccessor()
8244
{
8345
using (var session = OpenSession())
8446
{
85-
Assert.That(session.Query<Invoice>().Count(e => ((object)(e.SpecialAmount ?? e.Amount)).Equals(100)), Is.EqualTo(2));
47+
Assert.That(session.Query<Invoice>().Count(e => ((object) (e.SpecialAmount ?? e.Amount)).Equals(100)), Is.EqualTo(2));
8648
}
8749
}
8850
}

0 commit comments

Comments
 (0)