コード例 #1
0
        public void IndexPropertyWhenRefTypeAndNotFoundReturnNull()
        {
            IWithIndexers with = MockRepository.Mock <IWithIndexers>();

            with.SetUnexpectedBehavior(UnexpectedCallBehaviors.BaseOrDefault);

            with.ExpectProperty(x => x["", 3]);
            Assert.Null(with["", 2]);
        }
コード例 #2
0
        public void IndexPropertyWhenValueTypeAndNotFoundThrows()
        {
            IWithIndexers with = MockRepository.Mock <IWithIndexers>();

            with.SetUnexpectedBehavior(UnexpectedCallBehaviors.BaseOrDefault);

            with.ExpectProperty(x => x[1]);

            Assert.Throws <InvalidOperationException>(
                () => GC.KeepAlive(with[1]));
        }
コード例 #3
0
        public void IndexedPropertiesSupported()
        {
            IWithIndexers with = MockRepository.Mock <IWithIndexers>();

            with.SetUnexpectedBehavior(UnexpectedCallBehaviors.BaseOrDefault);

            //with.Expect(x => x[1])
            //    .PropertyBehavior();

            //with.Expect(x => x["", 1])
            //    .PropertyBehavior();

            with[1]  = 10;
            with[10] = 100;
            Assert.Equal(10, with[1]);
            Assert.Equal(100, with[10]);

            with["1", 2] = "3";
            with["2", 3] = "5";
            Assert.Equal("3", with["1", 2]);
            Assert.Equal("5", with["2", 3]);

            with.VerifyAllExpectations();
        }