forked from aljones/EFCore.SqlServer.HierarchyId
-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Consider null values during comparison operations
Resolves #11
- Loading branch information
Showing
2 changed files
with
117 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
using System.Linq; | ||
using Xunit; | ||
|
||
namespace Microsoft.EntityFrameworkCore.SqlServer | ||
{ | ||
public class NullabilityTests | ||
{ | ||
[Fact] | ||
public void Null_against_null() | ||
{ | ||
Assert.True((HierarchyId)null == (HierarchyId)null); | ||
Assert.False((HierarchyId)null != (HierarchyId)null); | ||
Assert.False((HierarchyId)null > (HierarchyId)null); | ||
Assert.False((HierarchyId)null >= (HierarchyId)null); | ||
Assert.False((HierarchyId)null < (HierarchyId)null); | ||
Assert.False((HierarchyId)null <= (HierarchyId)null); | ||
} | ||
|
||
[Fact] | ||
public void Null_against_nonNull() | ||
{ | ||
var hid = HierarchyId.GetRoot(); | ||
Assert.False(hid == (HierarchyId)null); | ||
Assert.False((HierarchyId)null == hid); | ||
|
||
Assert.True(hid != (HierarchyId)null); | ||
Assert.True((HierarchyId)null != hid); | ||
|
||
Assert.False(hid > (HierarchyId)null); | ||
Assert.False((HierarchyId)null > hid); | ||
|
||
Assert.False(hid >= (HierarchyId)null); | ||
Assert.False((HierarchyId)null >= hid); | ||
|
||
Assert.False(hid < (HierarchyId)null); | ||
Assert.False((HierarchyId)null < hid); | ||
|
||
Assert.False(hid <= (HierarchyId)null); | ||
Assert.False((HierarchyId)null <= hid); | ||
} | ||
|
||
[Fact] | ||
public void NullOnly_aggregates_equalTo_null() | ||
{ | ||
var hid = (HierarchyId)null; | ||
var collection = new[] { (HierarchyId)null, (HierarchyId)null, }; | ||
var min = collection.Min(); | ||
var max = collection.Max(); | ||
|
||
Assert.True(hid == min); | ||
Assert.True(min == hid); | ||
Assert.False(hid != min); | ||
Assert.False(min != hid); | ||
|
||
Assert.True(hid == max); | ||
Assert.True(max == hid); | ||
Assert.False(hid != max); | ||
Assert.False(max != hid); | ||
} | ||
|
||
[Fact] | ||
public void Aggregates_including_nulls_equalTo_nonNull() | ||
{ | ||
var hid = HierarchyId.GetRoot(); | ||
var collection = new[] { (HierarchyId)null, (HierarchyId)null, HierarchyId.GetRoot(), HierarchyId.GetRoot(), }; | ||
var min = collection.Min(); | ||
var max = collection.Max(); | ||
|
||
Assert.True(hid == min); | ||
Assert.True(min == hid); | ||
Assert.False(hid != min); | ||
Assert.False(min != hid); | ||
|
||
Assert.True(hid == max); | ||
Assert.True(max == hid); | ||
Assert.False(hid != max); | ||
Assert.False(max != hid); | ||
} | ||
} | ||
} |