Пример #1
0
            public void ShouldSetProperties()
            {
                // Arrange
                // Act
                var att = new FormActionAttribute("SomeForm", "SomeTitle", 1);

                // Assert
                Assert.AreEqual("SomeForm", att.Form);
                Assert.AreEqual("SomeTitle", att.ButtonTitle);
                Assert.AreEqual(1, att.Position);
            }
Пример #2
0
    protected override ActionDescriptor FindAction(ControllerContext controllerContext,
                                                   ControllerDescriptor controllerDescriptor, string actionName)
    {
        foreach (var mi in controllerDescriptor.ControllerType.GetMethods())
        {
            //Searches for the form action attribute first. And if it is present, then it looks
            //checks to see if the request is valid. This hpens BEFORE it checks the action name
            //which now means ActionName becomes obsolete
            var fa =
                mi.GetCustomAttributes(false).FirstOrDefault(x => x is FormActionAttribute) as FormActionAttribute;
            if (fa == null)
            {
                continue;
            }
            if (FormActionAttribute.GetAction(controllerContext) != null &&
                fa.IsValidForRequest(controllerContext, mi))
            {
                return(new ReflectedActionDescriptor(mi, actionName, controllerDescriptor));
            }
        }
        ActionDescriptor ad = base.FindAction(controllerContext, controllerDescriptor, actionName);
        var rad             = ad as ReflectedActionDescriptor;

        if (rad == null)
        {
            return(ad);
        }
        //Here we have to check that the form action attibute isn't in required mode. If it is
        //and the form-action is null then we should return null
        var formA =
            rad.MethodInfo.GetCustomAttributes(false).FirstOrDefault(x => x is FormActionAttribute) as
            FormActionAttribute;

        if (formA != null && FormActionAttribute.GetAction(controllerContext) == null &&
            formA.Mode == FormActionMode.Required)
        {
            return(null);
        }
        return(rad);
    }
Пример #3
0
 public void ShouldThrowOnEmptyButtonTitle()
 {
     // Arrange
     // Act
     _ = new FormActionAttribute("SomeForm", string.Empty, 0);
 }
Пример #4
0
 public void ShouldThrowOnNullButtonTitle()
 {
     // Arrange
     // Act
     _ = new FormActionAttribute("SomeForm", null, 0);
 }
Пример #5
0
 public void ShouldThrowOnEmptyForm()
 {
     // Arrange
     // Act
     _ = new FormActionAttribute(string.Empty, "title", 0);
 }
Пример #6
0
 public void ShouldThrowOnNullForm()
 {
     // Arrange
     // Act
     _ = new FormActionAttribute(null, "title", 0);
 }