Esempio n. 1
0
        public void SelectProperties()
        {
            var candidates =
                new[]
            {
                CreatePropertyStub(accessors: new[] { CreateMethodStub(attributes: MethodAttributes.Final) }),
                // Visbility is encoded in the lower 3 bits.
                CreatePropertyStub(
                    accessors: new[] { CreateMethodStub(attributes: (MethodAttributes)1), CreateMethodStub(attributes: (MethodAttributes)2) }),
                // The 4-th bit (value 8) does not contribute to the visibility and should be masked out.
                CreatePropertyStub(
                    accessors: new[] { CreateMethodStub(attributes: (MethodAttributes)3), CreateMethodStub(attributes: (MethodAttributes)4) })
            };
            var bindingFlags = (BindingFlags)1;

            _bindingFlagsEvaluatorMock.Expect(mock => mock.HasRightAttributes(MethodAttributes.Final, bindingFlags)).Return(false);
            _bindingFlagsEvaluatorMock.Expect(mock => mock.HasRightAttributes(((MethodAttributes)1), bindingFlags)).Return(false);
            _bindingFlagsEvaluatorMock.Expect(mock => mock.HasRightAttributes(((MethodAttributes)2), bindingFlags)).Return(true);
            _bindingFlagsEvaluatorMock.Expect(mock => mock.HasRightAttributes((MethodAttributes)3, bindingFlags)).Return(true);

            var result = _selector.SelectProperties(candidates, bindingFlags, _someDeclaringType).ForceEnumeration();

            _bindingFlagsEvaluatorMock.VerifyAllExpectations();
            Assert.That(result, Is.EqualTo(new[] { candidates[1], candidates[2] }));
        }