c# - Testing MVC Controller Action HttpAcceptAttribute Verbs -
What is the best way to test the action of the controller HttpAcceptAttribute verbs?
By now I have the following, but it is very ugly, even a mother can not love it and is not very flexible, is there any better way?
[Facts] // Using xUnit, junking the class public Zero Filters Controller Filter ControllerTrustRivoFilterByProductActivityThisTextepPost () {type [param paramypes = new [] {typeof (int)}; Var method = Typef (filter controller) .GetMethod ("MyMethod", Permaptes); Var attributes = method.GetCustomAttributes (typeof (AcceptVerbsAttribute), false) .sist & lt; AcceptVerbsAttribute & gt; (). SingleOrDefault (); Assert.NotNull (features); Claim it. Aquil (1, property workscount ()); Emphasis Properties (Properties Works first.) Equal (HTPVirb.post.tstrring (), String Compression. Inverted Culture Igniter Seas);) }
Thanks MAC
No reflection and magic string, easy Not to change the name of the controller and method without breaking the unit test:
[TestMethod] Public Zero homecontroller_index_action_should_acccept_Post_verb_only () {expression & lt; Action & lt; Homecontroller & gt; & Gt; Expression = (Home Controller C) = & gt; C.Index (zero); Var fractal = expression. Child in the form of legality; Var acceptVerbs = (AcceptVerbsAttribute []) methodCall.Method.GetCustomAttributes (typeof (AcceptVerbsAttribute), Incorrect); AcceptVerbs.ShouldNotBeNull (""); AcceptVerbs.Length.ShouldBe (1); AcceptVerbs [0] .Virbs.First () shouldbe ("Post"). }
Comments
Post a Comment