diff --git a/xUnitStudy.Model/xUnitStudy/Person.cs b/xUnitStudy.Model/xUnitStudy/Person.cs index 3a38985..bac478e 100644 --- a/xUnitStudy.Model/xUnitStudy/Person.cs +++ b/xUnitStudy.Model/xUnitStudy/Person.cs @@ -6,7 +6,7 @@ using System.Threading.Tasks; namespace xUnitStudy.Model { - public class Person:IPerson,IEqualityComparer + public class Person:IPerson,IEqualityComparer,IComparer { public int Id { get; set; } @@ -27,5 +27,27 @@ namespace xUnitStudy.Model { return obj.Id; } + + /// + /// IComparer接口实现 + /// + /// 比较对象1 + /// 比较对象2 + /// x小于y则返回负整数;x大于y则返回正整数;x等于y则返回0 + public int Compare(Person x, Person y) + { + if (x.Id < y.Id) + { + return -1; + } + else if (x.Id == y.Id) + { + return 0; + } + else + { + return 1; + } + } } } diff --git a/xUnitStudy.WebApi.Test/UseXUnitAssertTest.cs b/xUnitStudy.WebApi.Test/UseXUnitAssertTest.cs index 52c1627..03a6086 100644 --- a/xUnitStudy.WebApi.Test/UseXUnitAssertTest.cs +++ b/xUnitStudy.WebApi.Test/UseXUnitAssertTest.cs @@ -1042,6 +1042,28 @@ namespace xUnitStudy.WebApi.Test } #endregion + #region InRange + + [Fact] + public void InRange_Test() + { + Assert.InRange(5, 1, 10); + Assert.InRange("b", "a", "d"); + } + + [Fact] + public void InRange_IComparable_Test() + { + IComparer comparer = new Person(); + + Person person1 = new Person() { Id = 1}; + Person person2 = new Person() { Id = 2}; + Person person3 = new Person() { Id = 3}; + + Assert.InRange(person2, person1, person3, comparer); + } + #endregion + [Fact] public void All_Test() {