-
-
Notifications
You must be signed in to change notification settings - Fork 379
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #401 from ankurMalhotra/master
Compare Custom classes that don't implement IComparable (#364)
- Loading branch information
Showing
8 changed files
with
310 additions
and
0 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
48 changes: 48 additions & 0 deletions
48
src/Shouldly.Tests/ShouldBeGreaterOrEqualTo/CustomObjectScenario.cs
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,48 @@ | ||
using Shouldly.Tests.Strings; | ||
using Shouldly.Tests.TestHelpers; | ||
using Xunit; | ||
|
||
namespace Shouldly.Tests.ShouldBeGreaterOrEqualTo | ||
{ | ||
public class CustomObjectScenario | ||
{ | ||
[Fact] | ||
public void CustomObjectScenarioShouldFail() | ||
{ | ||
var customA = new Custom { Val = 1 }; | ||
var customB = new Custom { Val = 2 }; | ||
var comparer = new CustomComparer<Custom>(); | ||
Verify.ShouldFail(() => | ||
customA.ShouldBeGreaterThanOrEqualTo(customB, comparer, "Some additional context"), | ||
|
||
errorWithSource: | ||
@"customA | ||
should be greater than or equal to | ||
Shouldly.Tests.TestHelpers.Custom (000000) | ||
but was | ||
Shouldly.Tests.TestHelpers.Custom (000000) | ||
Additional Info: | ||
Some additional context", | ||
|
||
errorWithoutSource: | ||
@"Shouldly.Tests.TestHelpers.Custom (000000) | ||
should be greater than or equal to | ||
Shouldly.Tests.TestHelpers.Custom (000000) | ||
but was not | ||
Additional Info: | ||
Some additional context" | ||
); | ||
} | ||
|
||
[Fact] | ||
public void ShouldPass() | ||
{ | ||
var customA = new Custom { Val = 1 }; | ||
var customB = new Custom { Val = 1 }; | ||
var comparer = new CustomComparer<Custom>(); | ||
customA.ShouldBeGreaterThanOrEqualTo(customB, comparer); | ||
} | ||
} | ||
} |
49 changes: 49 additions & 0 deletions
49
src/Shouldly.Tests/ShouldBeGreaterThan/CustomObjectScenario.cs
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,49 @@ | ||
using Shouldly.Tests.Strings; | ||
using Shouldly.Tests.TestHelpers; | ||
using Xunit; | ||
|
||
namespace Shouldly.Tests.ShouldBeGreaterThan | ||
{ | ||
public class CustomObjectScenario | ||
{ | ||
|
||
[Fact] | ||
public void CustomObjectScenarioShouldFail() | ||
{ | ||
var customA = new Custom { Val = 1 }; | ||
var customB = new Custom { Val = 2 }; | ||
var comparer = new CustomComparer<Custom>(); | ||
Verify.ShouldFail(() => | ||
customA.ShouldBeGreaterThan(customB, comparer, "Some additional context"), | ||
|
||
errorWithSource: | ||
@"customA | ||
should be greater than | ||
Shouldly.Tests.TestHelpers.Custom (000000) | ||
but was | ||
Shouldly.Tests.TestHelpers.Custom (000000) | ||
Additional Info: | ||
Some additional context", | ||
|
||
errorWithoutSource: | ||
@"Shouldly.Tests.TestHelpers.Custom (000000) | ||
should be greater than | ||
Shouldly.Tests.TestHelpers.Custom (000000) | ||
but was not | ||
Additional Info: | ||
Some additional context" | ||
); | ||
} | ||
|
||
[Fact] | ||
public void ShouldPass() | ||
{ | ||
var customA = new Custom { Val = 2 }; | ||
var customB = new Custom { Val = 1 }; | ||
var comparer = new CustomComparer<Custom>(); | ||
customA.ShouldBeGreaterThan(customB, comparer); | ||
} | ||
} | ||
} |
48 changes: 48 additions & 0 deletions
48
src/Shouldly.Tests/ShouldBeLessThan/CustomObjectScenario.cs
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,48 @@ | ||
using Shouldly.Tests.Strings; | ||
using Shouldly.Tests.TestHelpers; | ||
using Xunit; | ||
|
||
namespace Shouldly.Tests.ShouldBeLessThan | ||
{ | ||
public class CustomObjectScenario | ||
{ | ||
[Fact] | ||
public void CustomObjectScenarioShouldFail() | ||
{ | ||
var customA = new Custom { Val = 1 }; | ||
var customB = new Custom { Val = 1 }; | ||
var comparer = new CustomComparer<Custom>(); | ||
Verify.ShouldFail(() => | ||
customA.ShouldBeLessThan(customB, comparer, "Some additional context"), | ||
|
||
errorWithSource: | ||
@"customA | ||
should be less than | ||
Shouldly.Tests.TestHelpers.Custom (000000) | ||
but was | ||
Shouldly.Tests.TestHelpers.Custom (000000) | ||
Additional Info: | ||
Some additional context", | ||
|
||
errorWithoutSource: | ||
@"Shouldly.Tests.TestHelpers.Custom (000000) | ||
should be less than | ||
Shouldly.Tests.TestHelpers.Custom (000000) | ||
but was not | ||
Additional Info: | ||
Some additional context" | ||
); | ||
} | ||
|
||
[Fact] | ||
public void ShouldPass() | ||
{ | ||
var customA = new Custom { Val = 2 }; | ||
var customB = new Custom { Val = 1 }; | ||
var comparer = new CustomComparer<Custom>(); | ||
customB.ShouldBeLessThan(customA, comparer); | ||
} | ||
} | ||
} |
48 changes: 48 additions & 0 deletions
48
src/Shouldly.Tests/ShouldBeLessThanOrEqualTo/CustomObjectScenario.cs
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,48 @@ | ||
using Shouldly.Tests.Strings; | ||
using Shouldly.Tests.TestHelpers; | ||
using Xunit; | ||
|
||
namespace Shouldly.Tests.ShouldBeLessThanOrEqualTo | ||
{ | ||
public class CustomObjectScenario | ||
{ | ||
[Fact] | ||
public void CustomObjectScenarioShouldFail() | ||
{ | ||
var customA = new Custom { Val = 2 }; | ||
var customB = new Custom { Val = 1 }; | ||
var comparer = new CustomComparer<Custom>(); | ||
Verify.ShouldFail(() => | ||
customA.ShouldBeLessThanOrEqualTo(customB, comparer, "Some additional context"), | ||
|
||
errorWithSource: | ||
@"customA | ||
should be less than or equal to | ||
Shouldly.Tests.TestHelpers.Custom (000000) | ||
but was | ||
Shouldly.Tests.TestHelpers.Custom (000000) | ||
Additional Info: | ||
Some additional context", | ||
|
||
errorWithoutSource: | ||
@"Shouldly.Tests.TestHelpers.Custom (000000) | ||
should be less than or equal to | ||
Shouldly.Tests.TestHelpers.Custom (000000) | ||
but was not | ||
Additional Info: | ||
Some additional context" | ||
); | ||
} | ||
|
||
[Fact] | ||
public void ShouldPass() | ||
{ | ||
Custom customA = new Custom { Val = 1 }; | ||
Custom customB = new Custom { Val = 1 }; | ||
var comparer = new CustomComparer<Custom>(); | ||
customA.ShouldBeLessThanOrEqualTo(customB, comparer); | ||
} | ||
} | ||
} |
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,21 @@ | ||
using System.Collections.Generic; | ||
|
||
namespace Shouldly.Tests.TestHelpers | ||
{ | ||
internal class CustomComparer<T> : IComparer<T> | ||
{ | ||
public int Compare(T x, T y) | ||
{ | ||
Custom x1 = x as Custom; | ||
Custom x2 = y as Custom; | ||
if (x1.Val == x2.Val) | ||
return 0; | ||
return x1.Val > x2.Val ? 1 : -1; | ||
} | ||
} | ||
|
||
internal class Custom | ||
{ | ||
public int Val { get; set; } | ||
} | ||
} |
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