0

I am attempting to create a unit test that checks for a file (e.g. http://images/icon.png) in an asp.net core project. I know how to do it for a specific controller for example.

    [TestMethod]
    public void WebApp_GetFoo()
    {
        var controller = new HomeController();
        var result = (OkObjectResult)controller.GetFoo();
        Assert.AreEqual(200, result.StatusCode);

        dynamic resultModel = DynamicExtensions.ToDynamic(result.Value);

        Assert.AreEqual("The Quick Brown Fox Jumped Over The Lazy Dog", resultModel.Text);
    }

But how does one do it for a simple GET request.

12
  • You just call the method. You don't need to create GET request. Commented Aug 27, 2017 at 15:39
  • What exactly is it you want to test? Do you have an example of the code to be tested? Commented Aug 27, 2017 at 15:40
  • For example, I have some image files that I want to make sure that they're there like http://<host>/images/icon.png. I guess I can just use FileExists but I would like to run through the stack to make sure routes are correct, etc. Thanks. Commented Aug 27, 2017 at 15:58
  • you just want to check the file exists or also the contents? Commented Aug 27, 2017 at 16:00
  • 3
    You are most likely not looking for a unit test, but an integration test: learn.microsoft.com/en-us/aspnet/core/testing/… Commented Aug 27, 2017 at 16:17

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.