public void SetExpectationOnNullableValue()
        {
            IFoo foo = MockRepository.Mock <IFoo>();

            foo.SetUnexpectedBehavior(UnexpectedCallBehaviors.BaseOrDefault);

            int?id = 2;

            foo.Expect(x => x.Id)
            .Return(id)
            .Repeat.Twice();

            foo.Expect(x => x.Id)
            .Return(null);

            foo.Expect(x => x.Id)
            .Return(1);

            Assert.True(foo.Id.HasValue);
            Assert.Equal(2, foo.Id.Value);
            Assert.False(foo.Id.HasValue);
            Assert.Equal(1, foo.Id.Value);

            foo.VerifyExpectations(true);
        }
示例#2
0
        //[Test]
        public void TestMethodWithALocalStubUsedAsAMock()
        {
            // We need the locals to generate the various stfld instructions.
            int    x          = 4;
            int    y          = 5;
            int    z          = 6;
            string someString = "foo";

            IFoo fooStub = MockRepository.GenerateStub <IFoo>();

            fooStub.Expect(s => s.DoSomethingFooRelated());
        }
示例#3
0
            public void ThisDoesnt()
            {
                IFoo mockFoo = MockRepository.Mock <IFoo>();

                int junk = 3;

                mockFoo.Expect(x => x.foo(ref Arg <int> .Ref(junk).Dummy))
                .IgnoreArguments()
                .Repeat.Once()
                .Return(true);

                ClassUnderTest cut = new ClassUnderTest();

                Assert.Equal(3, cut.doit(mockFoo));
            }
示例#4
0
        public void IgnoreArguments()
        {
            IFoo       myFoo = MockRepository.Mock <IFoo>();
            IBar <int> myBar = MockRepository.Mock <IBar <int> >();

            myFoo.Expect(x => x.RunBar(myBar))
            .IgnoreArguments()
            .Return(true);

            Example <int> myExample = new Example <int>(myFoo, myBar);
            bool          success   = myExample.ExampleMethod();

            Assert.True(success);

            myFoo.VerifyExpectations();
        }
            public void ThisWorks()
            {
                IFoo mockFoo = MockRepository.Mock <IFoo>();

                mockFoo.SetUnexpectedBehavior(UnexpectedCallBehaviors.BaseOrDefault);

                int junk = 3;

                mockFoo.Expect(x => x.foo(ref Arg <int> .Ref(junk).Dummy))
                .IgnoreArguments()
                .Repeat.Once()
                .Return(true);

                ClassUnderTest cut = new ClassUnderTest();

                Assert.Equal(3, cut.doit(mockFoo));
            }