Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8320219
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T22:35:04+00:00 2026-06-08T22:35:04+00:00

I’m trying to setup a test using NUnit to perform some integration testing of

  • 0

I’m trying to setup a test using NUnit to perform some integration testing of ASP.NET WebApi controllers. I’ve found a couple articles discussing In-Memory hosting using HttpServer that appears to simplify things by not needing a web server hosting everything.

  • ASP.NET Web API: in-memory hosting
  • ASP.NET Web API integration testing with in-memory hosting

The problem is the only response I ever get is 404-Not Found.

The controller are working when manually tested via a browser or Fiddler. The route definition was copied from the working site. The api project is referenced by the test project and the dll is getting copied to the same folder as the tests.

Thanks in advance.

Here’s the test class

[TestFixture]
public class InMemoryTests
{
    private HttpServer Server;
    private string UrlBase = "http://some.server/";

    [TestFixtureSetUp]
    public void Setup()
    {

        var config = new HttpConfiguration();
        config.Routes.MapHttpRoute(name: "Default", routeTemplate: "api/{controller}/{action}/{id}", defaults: new { id = RouteParameter.Optional });
        config.IncludeErrorDetailPolicy = IncludeErrorDetailPolicy.Always;

        Server = new HttpServer(config);
    }

    [Test]
    public void GetOrderStatus()
    {
        var client = new HttpClient(Server);
        var request = createRequest("api/Orders/GetOrderStatus?companyCode=001&orderNumber=1234", "application/json", HttpMethod.Get);

        using (HttpResponseMessage response = client.SendAsync(request).Result)
        {
            Assert.IsNotNull(response);
            Assert.AreEqual(HttpStatusCode.OK, response.StatusCode);
            Assert.NotNull(response.Content);
        }
    }

    private HttpRequestMessage createRequest(string url, string mthv, HttpMethod method)
    {
        var request = new HttpRequestMessage();

        request.RequestUri = new Uri(UrlBase + url);
        request.Headers.Accept.Add(new MediaTypeWithQualityHeaderValue(mthv));
        request.Method = method;

        return request;
    }

    private HttpRequestMessage createRequest<T>(string url, string mthv, HttpMethod method, T content, MediaTypeFormatter formatter) where T : class
    {
        HttpRequestMessage request = createRequest(url, mthv, method);
        request.Content = new ObjectContent<T>(content, formatter);

        return request;
    }

    public void Dispose()
    {
        if (Server != null)
        {
            Server.Dispose();
        }
    }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T22:35:05+00:00Added an answer on June 8, 2026 at 10:35 pm

    I was seeing this problem also, seemed to go away when I moved my test class into the same assembly as my controller; generally not practical for testing I know.

    After a bit of digging it appears there’s a bug that only occurs with self host when the calling code doesn’t share the same assembly as the controller as it hasn’t managed to load the required assemblies.

    To confirm this is your problem / temporarily workaround add this as the first line of your test: –

    Type myType = typeof(myControllerType);
    

    More info at : http://forums.asp.net/t/1772734.aspx/1

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and
For some reason, after submitting a string like this Jack’s Spindle from a text
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I am reading a book about Javascript and jQuery and using one of the
I am trying to render a haml file in a javascript response like so:

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.