public void CreateAndCallComparsison()
        {
            var mocks = new Mock <IComparer <string> >();

            mocks.Setup(x => x.Compare("hello", "there")).Returns(5).Verifiable();
            mocks.Setup(x => x.Compare("x", "y")).Returns(-3).Verifiable();
            Exception exception = new Exception();

            mocks.Setup(x => x.Compare("throw", "exception")).Throws(exception).Verifiable();


            Comparison <string> comparison = ComparisonComparer <string> .CreateComparison(mocks.Object);

            Assert.AreEqual(5, comparison("hello", "there"));
            Assert.AreEqual(-3, comparison("x", "y"));
            try
            {
                comparison("throw", "exception");
                Assert.Fail("Expected exception");
            }
            catch (Exception e)
            {
                Assert.AreSame(exception, e);
            }
            mocks.VerifyAll();
        }
예제 #2
0
        public void CreateAndCallComparsison()
        {
            MockRepository     mocks    = new MockRepository();
            IComparer <string> comparer = mocks.CreateMock <IComparer <string> >();

            Expect.Call(comparer.Compare("hello", "there")).Return(5);
            Expect.Call(comparer.Compare("x", "y")).Return(-3);
            Exception exception = new Exception();

            Expect.Call(comparer.Compare("throw", "exception")).Throw(exception);

            mocks.ReplayAll();
            Comparison <string> comparison = ComparisonComparer <string> .CreateComparison(comparer);

            Assert.AreEqual(5, comparison("hello", "there"));
            Assert.AreEqual(-3, comparison("x", "y"));
            try
            {
                comparison("throw", "exception");
                Assert.Fail("Expected exception");
            }
            catch (Exception e)
            {
                Assert.AreSame(exception, e);
            }
            mocks.VerifyAll();
        }
 public void CreateComparisonWithNull()
 {
     Assert.Throws <ArgumentNullException>(() =>
     {
         ComparisonComparer <string> .CreateComparison(null);
     });
 }
예제 #4
0
 public void CreateComparisonWithNull()
 {
     ComparisonComparer <string> .CreateComparison(null);
 }