public void GetParametersWrapsParameterInfos()
        {
            // Arrange
            ParameterInfo             pInfo0 = typeof(ConcatController).GetMethod("Concat").GetParameters()[0];
            ParameterInfo             pInfo1 = typeof(ConcatController).GetMethod("Concat").GetParameters()[1];
            ReflectedActionDescriptor ad     = GetActionDescriptor(typeof(ConcatController).GetMethod("Concat"));

            // Act
            ParameterDescriptor[] pDescsFirstCall  = ad.GetParameters();
            ParameterDescriptor[] pDescsSecondCall = ad.GetParameters();

            // Assert
            Assert.AreNotSame(pDescsFirstCall, pDescsSecondCall, "GetParameters() should return a new array on each invocation.");
            Assert.IsTrue(pDescsFirstCall.SequenceEqual(pDescsSecondCall), "Array elements were not equal.");
            Assert.AreEqual(2, pDescsFirstCall.Length);

            ReflectedParameterDescriptor pDesc0 = pDescsFirstCall[0] as ReflectedParameterDescriptor;
            ReflectedParameterDescriptor pDesc1 = pDescsFirstCall[1] as ReflectedParameterDescriptor;

            Assert.IsNotNull(pDesc0, "Parameter 0 should have been of type ReflectedParameterDescriptor.");
            Assert.AreSame(ad, pDesc0.ActionDescriptor, "Parameter 0 Action did not match.");
            Assert.AreSame(pInfo0, pDesc0.ParameterInfo, "Parameter 0 ParameterInfo did not match.");
            Assert.IsNotNull(pDesc1, "Parameter 1 should have been of type ReflectedParameterDescriptor.");
            Assert.AreSame(ad, pDesc1.ActionDescriptor, "Parameter 1 Action did not match.");
            Assert.AreSame(pInfo1, pDesc1.ParameterInfo, "Parameter 1 ParameterInfo did not match.");
        }
Exemplo n.º 2
0
        public void GetParametersWrapsParameterInfos()
        {
            // Arrange
            ParameterInfo             pInfo0 = typeof(ConcatController).GetMethod("Concat").GetParameters()[0];
            ParameterInfo             pInfo1 = typeof(ConcatController).GetMethod("Concat").GetParameters()[1];
            ReflectedActionDescriptor ad     = GetActionDescriptor(typeof(ConcatController).GetMethod("Concat"));

            // Act
            ParameterDescriptor[] pDescsFirstCall  = ad.GetParameters();
            ParameterDescriptor[] pDescsSecondCall = ad.GetParameters();

            // Assert
            Assert.NotSame(pDescsFirstCall, pDescsSecondCall);
            Assert.True(pDescsFirstCall.SequenceEqual(pDescsSecondCall));
            Assert.Equal(2, pDescsFirstCall.Length);

            ReflectedParameterDescriptor pDesc0 = pDescsFirstCall[0] as ReflectedParameterDescriptor;
            ReflectedParameterDescriptor pDesc1 = pDescsFirstCall[1] as ReflectedParameterDescriptor;

            Assert.NotNull(pDesc0);
            Assert.Same(ad, pDesc0.ActionDescriptor);
            Assert.Same(pInfo0, pDesc0.ParameterInfo);
            Assert.NotNull(pDesc1);
            Assert.Same(ad, pDesc1.ActionDescriptor);
            Assert.Same(pInfo1, pDesc1.ParameterInfo);
        }
        public void ConstructorSetsParameterInfo()
        {
            // Arrange
            ParameterInfo pInfo = typeof(MyController).GetMethod("Foo").GetParameters()[0];

            // Act
            ReflectedParameterDescriptor pd = new ReflectedParameterDescriptor(pInfo, new Mock <ActionDescriptor>().Object);

            // Assert
            Assert.AreSame(pInfo, pd.ParameterInfo);
        }
        public void ParameterTypeProperty()
        {
            // Arrange
            ParameterInfo pInfo = typeof(MyController).GetMethod("Foo").GetParameters()[0];

            // Act
            ReflectedParameterDescriptor pd = GetParameterDescriptor(pInfo);

            // Assert
            Assert.AreEqual(typeof(string), pd.ParameterType);
        }
        public void DefaultValuePropertyDefaultsToNull()
        {
            // Arrange
            ParameterInfo pInfo = typeof(MyController).GetMethod("DefaultValues").GetParameters()[0]; // noDefaultValue

            // Act
            ReflectedParameterDescriptor pd = GetParameterDescriptor(pInfo);

            // Assert
            Assert.Null(pd.DefaultValue);
        }
        public void ConstructorSetsParameterInfo()
        {
            // Arrange
            ParameterInfo pInfo = typeof(MyController).GetMethod("Foo").GetParameters()[0];

            // Act
            ReflectedParameterDescriptor pd = new ReflectedParameterDescriptor(pInfo, new Mock<ActionDescriptor>().Object);

            // Assert
            Assert.Same(pInfo, pd.ParameterInfo);
        }
        public void ConstructorSetsActionDescriptorProperty()
        {
            // Arrange
            ParameterInfo    pInfo = typeof(MyController).GetMethod("Foo").GetParameters()[0];
            ActionDescriptor ad    = new Mock <ActionDescriptor>().Object;

            // Act
            ReflectedParameterDescriptor pd = new ReflectedParameterDescriptor(pInfo, ad);

            // Assert
            Assert.AreSame(ad, pd.ActionDescriptor);
        }
        public void ConstructorSetsActionDescriptorProperty()
        {
            // Arrange
            ParameterInfo pInfo = typeof(MyController).GetMethod("Foo").GetParameters()[0];
            ActionDescriptor ad = new Mock<ActionDescriptor>().Object;

            // Act
            ReflectedParameterDescriptor pd = new ReflectedParameterDescriptor(pInfo, ad);

            // Assert
            Assert.Same(ad, pd.ActionDescriptor);
        }
        public void IsDefinedCallsParameterInfoIsDefined()
        {
            // Arrange
            Mock <ParameterInfo> mockParameter = new Mock <ParameterInfo>();

            mockParameter.Expect(pi => pi.Member).Returns(new Mock <MemberInfo>().Object);
            mockParameter.Expect(pi => pi.IsDefined(typeof(ObsoleteAttribute), true)).Returns(true);
            ReflectedParameterDescriptor pd = GetParameterDescriptor(mockParameter.Object);

            // Act
            bool isDefined = pd.IsDefined(typeof(ObsoleteAttribute), true);

            // Assert
            Assert.IsTrue(isDefined);
        }
        public void GetCustomAttributesWithAttributeTypeCallsParameterInfoGetCustomAttributes()
        {
            // Arrange
            object[]             expected      = new object[0];
            Mock <ParameterInfo> mockParameter = new Mock <ParameterInfo>();

            mockParameter.Expect(pi => pi.Member).Returns(new Mock <MemberInfo>().Object);
            mockParameter.Expect(pi => pi.GetCustomAttributes(typeof(ObsoleteAttribute), true)).Returns(expected);
            ReflectedParameterDescriptor pd = GetParameterDescriptor(mockParameter.Object);

            // Act
            object[] returned = pd.GetCustomAttributes(typeof(ObsoleteAttribute), true);

            // Assert
            Assert.AreSame(expected, returned);
        }
        public void GetParameters()
        {
            // Arrange
            ParameterInfo             pInfo = _taskMethod.GetParameters()[0];
            TaskAsyncActionDescriptor ad    = GetActionDescriptor(_taskMethod);

            // Act
            ParameterDescriptor[] pDescsFirstCall  = ad.GetParameters();
            ParameterDescriptor[] pDescsSecondCall = ad.GetParameters();

            // Assert
            Assert.NotSame(pDescsFirstCall, pDescsSecondCall); // Should get a new array every time
            Assert.Equal(pDescsFirstCall, pDescsSecondCall);

            ParameterDescriptor          parameterDescriptor = Assert.Single(pDescsFirstCall);
            ReflectedParameterDescriptor pDesc = Assert.IsType <ReflectedParameterDescriptor>(parameterDescriptor);

            Assert.NotNull(pDesc);
            Assert.Same(ad, pDesc.ActionDescriptor);
            Assert.Same(pInfo, pDesc.ParameterInfo);
        }
Exemplo n.º 12
0
        public void GetParameters()
        {
            // Arrange
            ParameterInfo pInfo = _asyncMethod.GetParameters()[0];
            ReflectedAsyncActionDescriptor ad = GetActionDescriptor(_asyncMethod, _completedMethod);

            // Act
            ParameterDescriptor[] pDescsFirstCall  = ad.GetParameters();
            ParameterDescriptor[] pDescsSecondCall = ad.GetParameters();

            // Assert
            Assert.AreNotSame(pDescsFirstCall, pDescsSecondCall, "GetParameters() should return a new array on each invocation.");
            CollectionAssert.AreEqual(pDescsFirstCall, pDescsSecondCall, "Array elements were not equal.");
            Assert.AreEqual(1, pDescsFirstCall.Length);

            ReflectedParameterDescriptor pDesc = pDescsFirstCall[0] as ReflectedParameterDescriptor;

            Assert.IsNotNull(pDesc, "Parameter 0 should have been of type ReflectedParameterDescriptor.");
            Assert.AreSame(ad, pDesc.ActionDescriptor, "Parameter 0 Action did not match.");
            Assert.AreSame(pInfo, pDesc.ParameterInfo, "Parameter 0 ParameterInfo did not match.");
        }
Exemplo n.º 13
0
        public void GetParametersWrapsParameterInfos()
        {
            // Arrange
            ParameterInfo pInfo = _setupMethod.GetParameters()[0];
            ReflectedEventPatternActionDescriptor ad = new ReflectedEventPatternActionDescriptor(_setupMethod, _completionMethod, "SomeAction", new Mock <ControllerDescriptor>().Object);

            // Act
            ParameterDescriptor[] pDescsFirstCall  = ad.GetParameters();
            ParameterDescriptor[] pDescsSecondCall = ad.GetParameters();

            // Assert
            Assert.AreNotSame(pDescsFirstCall, pDescsSecondCall, "GetParameters() should return a new array on each invocation.");
            Assert.IsTrue(pDescsFirstCall.SequenceEqual(pDescsSecondCall), "Array elements were not equal.");
            Assert.AreEqual(1, pDescsFirstCall.Length);

            ReflectedParameterDescriptor pDesc = pDescsFirstCall[0] as ReflectedParameterDescriptor;

            Assert.IsNotNull(pDesc, "Parameter 0 should have been of type ReflectedParameterDescriptor.");
            Assert.AreSame(ad, pDesc.ActionDescriptor, "Parameter 0 Action did not match.");
            Assert.AreSame(pInfo, pDesc.ParameterInfo, "Parameter 0 ParameterInfo did not match.");
        }
Exemplo n.º 14
0
        public void GetParameters()
        {
            // Arrange
            ParameterInfo pInfo = _asyncMethod.GetParameters()[0];
            ReflectedAsyncActionDescriptor ad = GetActionDescriptor(_asyncMethod, _completedMethod);

            // Act
            ParameterDescriptor[] pDescsFirstCall  = ad.GetParameters();
            ParameterDescriptor[] pDescsSecondCall = ad.GetParameters();

            // Assert
            Assert.NotSame(pDescsFirstCall, pDescsSecondCall);
            Assert.Equal(pDescsFirstCall, pDescsSecondCall);
            Assert.Single(pDescsFirstCall);

            ReflectedParameterDescriptor pDesc = pDescsFirstCall[0] as ReflectedParameterDescriptor;

            Assert.NotNull(pDesc);
            Assert.Same(ad, pDesc.ActionDescriptor);
            Assert.Same(pInfo, pDesc.ParameterInfo);
        }
Exemplo n.º 15
0
 public DescribedMvcActionParameterInfo(ParameterDescriptor paramDescr, ActionInfo action)
     : base(action)
 {
     this.paramDescr          = paramDescr;
     this.reflectedParamDescr = paramDescr as ReflectedParameterDescriptor;
 }