public void SelectSingleProperty() { var properties = new[] { CreatePropertyStub("Property1", accessors: new[] { CreateMethodStub() }), CreatePropertyStub("Property2", accessors: new[] { CreateMethodStub(attributes: MethodAttributes.Assembly) }), CreatePropertyStub("Property2", accessors: new[] { CreateMethodStub(attributes: MethodAttributes.Public) }) }; var bindingFlags = (BindingFlags)1; var propertyType = ReflectionObjectMother.GetSomeType(); var indexerTypes = new[] { ReflectionObjectMother.GetSomeOtherType() }; var modifiers = new[] { new ParameterModifier(2) }; _bindingFlagsEvaluatorMock.Expect(mock => mock.HasRightAttributes(MethodAttributes.Assembly, bindingFlags)).Return(true); _bindingFlagsEvaluatorMock.Expect(mock => mock.HasRightAttributes(MethodAttributes.Public, bindingFlags)).Return(true); var binderMock = MockRepository.GenerateStrictMock <Binder>(); var fakeResult = ReflectionObjectMother.GetSomeProperty(); binderMock.Expect(mock => mock.SelectProperty(bindingFlags, new[] { properties[1], properties[2] }, propertyType, indexerTypes, modifiers)) .Return(fakeResult); var result = _selector.SelectSingleProperty( properties, binderMock, bindingFlags, "Property2", _someDeclaringType, propertyType, indexerTypes, modifiers); _bindingFlagsEvaluatorMock.VerifyAllExpectations(); binderMock.VerifyAllExpectations(); Assert.That(result, Is.SameAs(fakeResult)); }
public void SelectSingleProperty() { var properties = new[] { CreatePropertyStub("Property1", accessors: new[] { CreateMethodStub() }), CreatePropertyStub("Property2", accessors: new[] { CreateMethodStub(attributes: MethodAttributes.Assembly) }), CreatePropertyStub("Property2", accessors: new[] { CreateMethodStub(attributes: MethodAttributes.Public) }) }; var bindingFlags = (BindingFlags)1; var propertyType = ReflectionObjectMother.GetSomeType(); var indexerTypes = new[] { ReflectionObjectMother.GetSomeOtherType() }; var modifiers = new[] { new ParameterModifier(2) }; _bindingFlagsEvaluatorMock.Setup(mock => mock.HasRightAttributes(MethodAttributes.Assembly, bindingFlags)).Returns(true).Verifiable(); _bindingFlagsEvaluatorMock.Setup(mock => mock.HasRightAttributes(MethodAttributes.Public, bindingFlags)).Returns(true).Verifiable(); var binderMock = new Mock <Binder> (MockBehavior.Strict); var fakeResult = ReflectionObjectMother.GetSomeProperty(); binderMock .Setup( mock => mock.SelectProperty( bindingFlags, It.Is <PropertyInfo[]> (param => param.SequenceEqual(new[] { properties[1], properties[2] })), propertyType, indexerTypes, modifiers)) .Returns(fakeResult) .Verifiable(); var result = _selector.SelectSingleProperty( properties, binderMock.Object, bindingFlags, "Property2", _someDeclaringType, propertyType, indexerTypes, modifiers); _bindingFlagsEvaluatorMock.Verify(); binderMock.Verify(); Assert.That(result, Is.SameAs(fakeResult)); }