//合并操作符用于多级比较 public int Compare(Product first, Product second) { return(PartialComparer.Compare(first, second) ?? PartialComparer.Compare(first.Price, second.Price) ?? PartialComparer.Compare(first.SupplierID, second.SupplierID) ?? PartialComparer.Compare(first.Name, second.Name) ?? 0); }
public void CompareReturnsNullWhenSpecifiedComparerReturnsZero() { MockRepository factory = new MockRepository(); IComparer <string> comparer = factory.CreateMock <IComparer <string> >(); Expect.Call(comparer.Compare("first", "second")).Return(0); factory.ReplayAll(); Assert.IsNull(PartialComparer.Compare(comparer, "first", "second")); factory.VerifyAll(); }
public void DefaultGreaterThanReturnsGreaterThanZero() { Assert.IsTrue(PartialComparer.Compare(5, 3) > 0); }
public void DefaultEqualReturnsNull() { Assert.IsNull(PartialComparer.Compare(4, 4)); }
public void DefaultLessThanReturnsLessThanZero() { Assert.IsTrue(PartialComparer.Compare(3, 5) < 0); }