Вопрос

I am using MvcContrib-TestHelper to test the routing on my app. I have an action which is restricted to HTTP POST only:

public TestController
{
    [HttpPost]
    public ActionResult Example()
    {
        return View();
    }
}

And here is an example of a test that should fail:

[TestFixture]
public class RoutingTests
{
    [TestFixtureSetUp]
    public void TestFixtureSetUp()
    {
        RouteTable.Routes.Clear();
        Application.RegisterRoutes(RouteTable.Routes);
    }

    [Test]
    public void TestWithGet()
    {
        var route = "~/Test/Example".WithMethod(HttpVerbs.Get);
        route.ShouldMapTo(r => r.Example());
    }
}

However, the test passes! I've seen one other unanswered question (sorry, wrong link) where this was also raised, and it seems like the functionality is broken. What's a better way to test that this route is accessible via POST only?

Это было полезно?

Решение 2

use this code:

var controller = new HomeController();
var methodInfo = controller.GetType().GetMethod("MrthodName");
var attributes = methodInfo.GetCustomAttributes(typeof(ActionMethodSelectorAttribute), true).Cast<ActionMethodSelectorAttribute>().ToList();

attributes - this is list accept verbs

Другие советы

It looks like you are just trying to test the ASP.NET MVC framework there. I dont think that such test will bring value...

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top