コード例 #1
0
        public void MockStringDelegateWithParams()
        {
            StringDelegateWithParams d = (StringDelegateWithParams)mocks.StrictMock(typeof(StringDelegateWithParams));

            Expect.On(d).Call(
                d(
                    Arg <int> .Is.Equal(1),
                    Arg <string> .Is.Equal("111")))
            .Return("abc");
            Expect.On(d).Call(
                d(
                    Arg <int> .Is.Equal(2),
                    Arg <string> .Is.Equal("222")))
            .Return("def");

            mocks.Replay(d);

            Assert.Equal("abc", d(1, "111"));
            Assert.Equal("def", d(2, "222"));

            try
            {
                d(3, "333");
                Assert.False(true, "Expected an expectation violation to occur.");
            }
            catch (ExpectationViolationException)
            {
                // Expected.
            }
        }
コード例 #2
0
        public void MockStringDelegateWithParams()
        {
            StringDelegateWithParams d = MockRepository.Mock <StringDelegateWithParams>();

            d.Expect(x => x(1, "111"))
            .Return("abc");

            d.Expect(x => x(2, "222"))
            .Return("def");

            Assert.Equal("abc", d(1, "111"));
            Assert.Equal("def", d(2, "222"));
            d(3, "333");

            Assert.Throws <ExpectationViolationException>(
                () => d.VerifyExpectations(true));
        }
コード例 #3
0
        public void MockStringDelegateWithParams()
        {
            StringDelegateWithParams d = MockRepository.Mock <StringDelegateWithParams>(null);

            d.SetUnexpectedBehavior(UnexpectedCallBehaviors.BaseOrDefault);

            d.Expect(x => x(Arg <int> .Is.Equal(1), Arg <string> .Is.Equal("111")))
            .Return("abc");

            d.Expect(x => x(Arg <int> .Is.Equal(2), Arg <string> .Is.Equal("222")))
            .Return("def");

            Assert.Equal("abc", d(1, "111"));
            Assert.Equal("def", d(2, "222"));

            d(3, "333");

            Assert.Throws <ExpectationViolationException>(() => d.VerifyExpectations(true));
        }