Skip to content

Make fields and ValidateActionResultType on ControllerResultTest public #40

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
robdmoore opened this issue Nov 11, 2014 · 3 comments
Closed

Comments

@robdmoore
Copy link
Member

Would be useful to enable ability to create extension methods on ControllerResultTest so that you can check for your own custom ActionResult types.

@robdmoore robdmoore changed the title Make fields and ValidateActionResultType on ControllerResultTest protected Make fields and ValidateActionResultType on ControllerResultTest public Nov 11, 2014
@robdmoore
Copy link
Member Author

FYI for anyone curious, this is possible with a bit of (nasty) reflection as a hack in the interim of getting this functionality built-in:

    public static class ControllerResultTestExtensions
    {
        public static void MyCustomTestMethod<TController>(this ControllerResultTest<TController> result, ...)
            where TController : Controller
        {
            var controller = result.GetType().GetField("_controller", BindingFlags.NonPublic | BindingFlags.Instance).GetValue(result) as TController;
            var actionResult = result.GetType().GetField("_actionResult", BindingFlags.NonPublic | BindingFlags.Instance).GetValue(result) as ActionResult;
            var actionName = result.GetType().GetField("_actionName", BindingFlags.NonPublic | BindingFlags.Instance).GetValue(result) as string;

            ...
    }

@robdmoore
Copy link
Member Author

(I would have just done it, but the CI server isn't accessible behind the proxy here and Git isn't installed on this computer :().

@AlexArchive
Copy link
Contributor

I can do this for you no problem.

I wonder what it is you wanted to achieve? Could we perhaps embed the assertion you need in the library?

robdmoore added a commit that referenced this issue Nov 11, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants