Exemple #1
0
 //合并操作符用于多级比较
 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);
 }
Exemple #2
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();
        }
Exemple #3
0
 public void DefaultGreaterThanReturnsGreaterThanZero()
 {
     Assert.IsTrue(PartialComparer.Compare(5, 3) > 0);
 }
Exemple #4
0
 public void DefaultEqualReturnsNull()
 {
     Assert.IsNull(PartialComparer.Compare(4, 4));
 }
Exemple #5
0
 public void DefaultLessThanReturnsLessThanZero()
 {
     Assert.IsTrue(PartialComparer.Compare(3, 5) < 0);
 }