コード例 #1
0
ファイル: MockTests.cs プロジェクト: joefallon/QuickMock
        public void Test_GetMethodArgs_Returns_Correct_Args()
        {
            ArrayList args = new ArrayList();
            args.Add(1);
            args.Add(2);

            Mock mock = new Mock();
            mock.MethodCalled("TestMethod", args);
            ArrayList argsOut = mock.GetMethodArgs("TestMethod", 1);

            Assert.AreEqual(1, argsOut[0]);
            Assert.AreEqual(2, argsOut[1]);

            args = new ArrayList();
            args.Add(3);
            args.Add(4);

            mock.MethodCalled("TestMethod", args);
            argsOut = mock.GetMethodArgs("TestMethod", 2);

            Assert.AreEqual(3, argsOut[0]);
            Assert.AreEqual(4, argsOut[1]);

            args = new ArrayList();
            args.Add(5);
            args.Add(6);

            mock.MethodCalled("TestMethod", args);
            argsOut = mock.GetMethodArgs("TestMethod", 3);

            Assert.AreEqual(5, argsOut[0]);
            Assert.AreEqual(6, argsOut[1]);
        }
コード例 #2
0
ファイル: MockTests.cs プロジェクト: joefallon/QuickMock
        public void Test_GetMethodCallCount_Returns_Correct_Count()
        {
            Mock mock = new Mock();
            int count = mock.GetMethodCallCount("TestMethod");

            Assert.AreEqual(0, count);

            mock.MethodCalled("TestMethod", null);
            count = mock.GetMethodCallCount("TestMethod");

            Assert.AreEqual(1, count);

            mock.MethodCalled("TestMethod", null);
            count = mock.GetMethodCallCount("TestMethod");

            Assert.AreEqual(2, count);

            ArrayList args = new ArrayList();
            args.Add(1);
            args.Add(2);

            mock.MethodCalled("OtherMethod", args);
            count = mock.GetMethodCallCount("TestMethod");
            int otherCount = mock.GetMethodCallCount("OtherMethod");

            Assert.AreEqual(2, count);
            Assert.AreEqual(1, otherCount);

            mock.MethodCalled("ThirdMethod", null);
            count = mock.GetMethodCallCount("TestMethod");
            otherCount = mock.GetMethodCallCount("OtherMethod");
            int thirdCount = mock.GetMethodCallCount("ThirdMethod");

            Assert.AreEqual(2, count);
            Assert.AreEqual(1, otherCount);
            Assert.AreEqual(1, thirdCount);
        }
コード例 #3
0
ファイル: MockTests.cs プロジェクト: joefallon/QuickMock
 public void Test_GetMethodArgs_Throws_Exception_If_CallCount_Too_High()
 {
     Mock mock = new Mock();
     mock.MethodCalled("TestMethod", null);
     mock.GetMethodArgs("TestMethod", 2);
 }
コード例 #4
0
ファイル: MockTests.cs プロジェクト: joefallon/QuickMock
        public void Test_SetMethodReturnValue_Properly_Overwrites_Previous_Sets()
        {
            Mock mock = new Mock();
            mock.SetMethodReturnValue("TestMethod", "a", 1);
            mock.SetMethodReturnValue("TestMethod", "b", 2);
            mock.SetMethodReturnValue("TestMethod", "c", 1);

            ArrayList args = new ArrayList();
            args.Add(1);
            args.Add(2);

            string retval = (string)mock.MethodCalled("TestMethod", args);

            Assert.AreEqual("c", retval, "with call count");

            mock = new Mock();
            mock.SetMethodReturnValue("TestMethod", "a");
            mock.SetMethodReturnValue("TestMethod", "b");

            args = new ArrayList();
            args.Add(1);
            args.Add(2);

            retval = (string)mock.MethodCalled("TestMethod", args);

            Assert.AreEqual("b", retval, "without call count");
        }
コード例 #5
0
ファイル: MockTests.cs プロジェクト: joefallon/QuickMock
        public void Test_MethodReturnValue_Getter_And_Setter()
        {
            Mock mock = new Mock();
            mock.SetMethodReturnValue("TestMethod", "a", 1);
            mock.SetMethodReturnValue("TestMethod", "b", 2);
            mock.SetMethodReturnValue("TestMethod", "c", 3);
            mock.SetMethodReturnValue("TestMethod", "d", 4);

            ArrayList args = new ArrayList();
            args.Add(1);
            args.Add(2);

            Assert.AreEqual("a", mock.MethodCalled("TestMethod", args));
            Assert.AreEqual("b", mock.MethodCalled("TestMethod", args));
            Assert.AreEqual("c", mock.MethodCalled("TestMethod", args));
            Assert.AreEqual("d", mock.MethodCalled("TestMethod", args));

            mock.SetMethodReturnValue("OtherMethod", "z");
            Assert.AreEqual("z", mock.MethodCalled("OtherMethod", args));
            Assert.AreEqual("z", mock.MethodCalled("OtherMethod", args));
            Assert.AreEqual("z", mock.MethodCalled("OtherMethod", args));
        }
コード例 #6
0
ファイル: MockTests.cs プロジェクト: joefallon/QuickMock
 public void Test_MethodCalled_Throws_ArgumentException_On_Null_MethodName()
 {
     Mock mock = new Mock();
     mock.MethodCalled(null, null);
 }