コード例 #1
0
        private void AssertCanMockGenericMethodWithUnspecifiedTypeParameter(IGenericSpeaker speaker)
        {
            const int iValue = 3;

            Stub.On(speaker).Message("Find").Will(Return.Value(iValue));

            var i = speaker.Find<int>();

            Assert.AreEqual(iValue, i);
        }
コード例 #2
0
        private void AssertHasCorrectErrorMessageOnUnexpectedInvocation(IGenericSpeaker speaker)
        {
            SkipVerificationForThisTest();

            try
            {
                speaker.Find<int, bool>();

                Assert.Fail("An ExpectationException should have been thrown");
            }
            catch (ExpectationException ex)
            {
                Assert.AreEqual(
                    "unexpected invocation of genericSpeaker.Find<System.Int32, System.Boolean>()\r\nexpectations:\r\n",
                    ex.Message);
            }
        }
コード例 #3
0
        private void AssertCanMockGenericMethodWithSpecifiedTypeParameter(IGenericSpeaker genericSpeaker)
        {
            const int iValue = 3;
            const string sValue = "test";

            Stub.On(genericSpeaker).Message("Find", typeof (int)).With().Will(Return.Value(iValue));
            Stub.On(genericSpeaker).Message("Find", typeof (string)).Will(Return.Value(sValue));
            Stub.On(genericSpeaker).Message("Find", typeof (ISpeaker), typeof (bool)).Will(
                Return.Value(Mockery.NewInstanceOfRole<ISpeaker>()));

            var s = genericSpeaker.Find<string>();
            var i = genericSpeaker.Find<int>();
            ISpeaker speaker = genericSpeaker.Find<ISpeaker, bool>();

            Assert.AreEqual(iValue, i);
            Assert.AreEqual(sValue, s);
            Assert.IsNotNull(speaker);
        }