示例#1
0
 private static void ConfigureOrderedTimesMin0WithNestedUnordered(MockRepository mocks, I1 mockObject)
 {
     using (mocks.Ordered())
     {
         mockObject.A();
         LastCall.Repeat.Times(0, 1);
         using (mocks.Unordered())
         {
             mockObject.B();
             mockObject.C();
         }
         mockObject.A();
         LastCall.Repeat.Times(0, 1);
     }
 }
示例#2
0
 private static void ConfigureOrderedTimesMinNonZeroMaxHigherThanMin(MockRepository mocks, I1 mockObject)
 {
     using (mocks.Ordered())
     {
         mockObject.A();
         mockObject.B();
         LastCall.Repeat.Times(1, 3);
         mockObject.C();
     }
 }
示例#3
0
 private static void ConfigureOrderedAtLeastOnce(MockRepository mocks, I1 mockObject)
 {
     using (mocks.Ordered())
     {
         mockObject.A();
         mockObject.B();
         LastCall.Repeat.AtLeastOnce();
         mockObject.C();
     }
 }
示例#4
0
        /// <summary>
        /// Sets up a mock, and runs through methods as specified by characters in <paramref name="methodOrder"/>.
        /// </summary>
        /// <param name="mockConfigurer">A delegate to use to configure the mock.</param>
        /// <param name="isValid">Whether the order should be valid or not.</param>
        /// <param name="methodOrder">The method order (e.g. "ABC", "ABBC").</param>
        private static void AssertOrderValidity(ConfigureMockDelegate mockConfigurer, bool isValid,
                                                string methodOrder)
        {
            MockRepository mocks = new MockRepository();

            I1 i = mocks.StrictMock(typeof(I1)) as I1;

            mockConfigurer(mocks, i);

            mocks.ReplayAll();

            try
            {
                foreach (char c in methodOrder)
                {
                    switch (c)
                    {
                    case 'A':
                        i.A();
                        break;

                    case 'B':
                        i.B();
                        break;

                    case 'C':
                        i.C();
                        break;

                    default:
                        throw new NotSupportedException();
                    }
                }
                mocks.VerifyAll();
            }
            catch (Exceptions.ExpectationViolationException ex)
            {
                if (isValid)
                {
                    Assert.False(true, string.Format("Order {0} was supposed to be ok, but got error: {1}", methodOrder, ex.Message));
                }
                else
                {
                    return;
                }
            }

            if (!isValid)
            {
                Assert.False(true, string.Format("Order {0} was supposed to fail, but did not.", methodOrder));
            }
        }
示例#5
0
文件: Program.cs 项目: hgouw/Test
        static void Main(string[] args)
        {
            C  c  = new C();
            I1 i1 = (I1)c;
            I2 i2 = (I2)c;

            i1.A();
            i2.A();
            c.A();
            Console.ReadLine();

            D d = new D();

            i1 = (I1)d;
            i2 = (I2)d;
            i1.A();
            i2.A();
            d.A();
            Console.ReadLine();

            E e = new E();

            i1 = (I1)e;
            i2 = (I2)e;
            i1.A();
            i2.A();
            e.A();
            Console.ReadLine();

            F f = new F();

            //f.A(); --- COMPILE ERROR
            i1 = (I1)f;
            //i2 = (I2)f; --- RUNTIME ERROR
            i1.A();
            Console.ReadLine();
        }
示例#6
0
 private static void ConfigureOrderedTimesMinNonZeroMaxHigherThanMin(MockRepository mocks, I1 mockObject)
 {
     using (mocks.Ordered())
     {
         mockObject.A();
         mockObject.B();
         LastCall.Repeat.Times(1, 3);
         mockObject.C();
     }
 }
示例#7
0
 private static void ConfigureOrderedTimesMin0WithNestedUnordered(MockRepository mocks, I1 mockObject)
 {
     using (mocks.Ordered())
     {
         mockObject.A();
         LastCall.Repeat.Times(0, 1);
         using (mocks.Unordered())
         {
             mockObject.B();
             mockObject.C();
         }
         mockObject.A();
         LastCall.Repeat.Times(0, 1);
     }
 }
示例#8
0
 private static void ConfigureOrderedAtLeastOnce(MockRepository mocks, I1 mockObject)
 {
     using (mocks.Ordered())
     {
         mockObject.A();
         mockObject.B();
         LastCall.Repeat.AtLeastOnce();
         mockObject.C();
     }
 }