public void NameProperty() {
            // Arrange
            ActionNameAttribute attr = new ActionNameAttribute("someName");

            // Act & Assert
            Assert.AreEqual("someName", attr.Name);
        }
        public void IsValidForRequestReturnsFalseIfGivenNameDoesNotMatch() {
            // Arrange
            ActionNameAttribute attr = new ActionNameAttribute("Bar");

            // Act
            bool returned = attr.IsValidName(null, "foo", null);

            // Assert
            Assert.IsFalse(returned, "Given name should not have matched.");
        }
        public void IsValidForRequestReturnsTrueIfGivenNameMatches() {
            // Arrange
            ActionNameAttribute attr = new ActionNameAttribute("Bar");

            // Act
            bool returned = attr.IsValidName(null, "bar", null);

            // Assert
            Assert.IsTrue(returned, "Given name should have matched.");
        }
Ejemplo n.º 4
0
        // Get the action name for the method.
        public string GetActionName(MethodInfo methodInfo)
        {
            // Check for ActionName attribute
            object[] nameAttributes = methodInfo.GetCustomAttributes(typeof(ActionNameAttribute), inherit: true);
            if (nameAttributes.Length > 0)
            {
                ActionNameAttribute nameAttribute = nameAttributes[0] as ActionNameAttribute;
                if (nameAttribute != null)
                {
                    return(nameAttribute.Name);
                }
            }

            return(GetCanonicalMethodName(methodInfo));
        }