示例#1
0
 public void MockOutArgsTest()
 {
     using (RecorderManager.NewRecordingSession("test"))
     {
         Assert.AreEqual(RecorderState.Recording, RecorderManager.Action);
         // Scenario:
         Sample.FooBar fb = new Sample.FooBar();
         int           a = 1, b = 2, c, d = 4;
         object        result = fb.SomeMethodWithInsAndOuts(a, ref b, out c, d);
         // Check results:
         Assert.IsNotNull(result);
         Assert.AreEqual(3, b);
         Assert.AreEqual(7, c);
         // Check mocking records:
         Assert.IsTrue(CurrentRecorder[0].IsConstructorCall);
         Assert.IsFalse(CurrentRecorder[1].IsConstructorCall);
         Assert.IsTrue(CurrentRecorder[1].InArgs.Length == 3);
         Assert.AreEqual(1, CurrentRecorder[1].InArgs[0]);
         Assert.AreEqual(2, CurrentRecorder[1].InArgs[1]);
         Assert.AreEqual(4, CurrentRecorder[1].InArgs[2]);
         Assert.IsTrue(CurrentRecorder[1].OutArgs.Length == 2);
         Assert.AreEqual(3, CurrentRecorder[1].OutArgs[0]);
         Assert.AreEqual(7, CurrentRecorder[1].OutArgs[1]);
         Assert.AreEqual(result, CurrentRecorder[1].ReturnValue);
         Assert.AreEqual(1, CurrentRecorder[1].Args[0]);
         Assert.AreEqual(3, CurrentRecorder[1].Args[1]);
         Assert.AreEqual(7, CurrentRecorder[1].Args[2]);
         Assert.AreEqual(4, CurrentRecorder[1].Args[3]);
     }
 }
        public void ManualMockingOutArgTest()
        {
            ManualMockSession sess = new ManualMockSession();

            Sample.FooBar fb = (Sample.FooBar)sess.Mock(typeof(Sample.FooBar), "fb")
                               .ExpectAndReturn("SomeMethodWithInsAndOuts", "OK", new object[] { 10, 11 })
                               .Mock;
            int    a = 1, b = 2, c, d = 4;
            object result = fb.SomeMethodWithInsAndOuts(a, ref b, out c, d);

            Assert.AreEqual("OK", result);
            Assert.AreEqual(b, 10);
            Assert.AreEqual(c, 11);
        }
        public void ManualMockingValidate06Test()
        {
            ManualMockSession sess = new ManualMockSession();

            Sample.FooBar fb = (Sample.FooBar)sess.Mock(typeof(Sample.FooBar), "fb")
                               .ExpectAndReturn("SomeMethodWithInsAndOuts", null).WithArguments(ExpectedValue.Any, ExpectedValue.Any, null, 4)
                               .Mock;
            try
            {
                int a = 1, b = 2, c = 3, d = 0;
                fb.SomeMethodWithInsAndOuts(a, ref b, out c, d);
                Assert.Fail("Should have thrown exception.");
            }
            catch (ReplayMockException ex)
            {
                Assert.IsTrue(ex.Message.IndexOf("\"fourthin\"") >= 0, "Argument 'fourthin' should be marked to have an invalid value.");
            }
        }
		public void MockOutArgsTest()
		{
			using (RecorderManager.NewRecordingSession("test"))
			{
				Assert.AreEqual(RecorderState.Recording, RecorderManager.Action);
				// Scenario:
				Sample.FooBar fb = new Sample.FooBar();
				int a = 1, b = 2, c, d = 4;
				object result = fb.SomeMethodWithInsAndOuts(a, ref b, out c, d);
				// Check results:
				Assert.IsNotNull(result);
				Assert.AreEqual(3, b);
				Assert.AreEqual(7, c);
				// Check mocking records:
				Assert.IsTrue(CurrentRecorder[0].IsConstructorCall);
				Assert.IsFalse(CurrentRecorder[1].IsConstructorCall);
				Assert.IsTrue(CurrentRecorder[1].InArgs.Length == 3);
				Assert.AreEqual(1, CurrentRecorder[1].InArgs[0]);
				Assert.AreEqual(2, CurrentRecorder[1].InArgs[1]);
				Assert.AreEqual(4, CurrentRecorder[1].InArgs[2]);
				Assert.IsTrue(CurrentRecorder[1].OutArgs.Length == 2);
				Assert.AreEqual(3, CurrentRecorder[1].OutArgs[0]);
				Assert.AreEqual(7, CurrentRecorder[1].OutArgs[1]);
				Assert.AreEqual(result, CurrentRecorder[1].ReturnValue);
				Assert.AreEqual(1, CurrentRecorder[1].Args[0]);
				Assert.AreEqual(3, CurrentRecorder[1].Args[1]);
				Assert.AreEqual(7, CurrentRecorder[1].Args[2]);
				Assert.AreEqual(4, CurrentRecorder[1].Args[3]);
			}
		}