2

I created an empty asp.net web application project with rc2. My project file is:

{
  "testRunner": "xunit",
  "dependencies": {
    "xunit": "2.1.0",
    "dotnet-test-xunit": "1.0.0-rc2-build10025",
    "Microsoft.NETCore.App": {
      "version": "1.0.0-rc2-3002702",
      "type": "platform"
    },

    "Microsoft.AspNetCore.Server.IISIntegration": "1.0.0-rc2-final",
    "Microsoft.AspNetCore.Server.Kestrel": "1.0.0-rc2-final",
    "Microsoft.AspNetCore.Mvc.Cors": "1.0.0-rc2-final",
    "Microsoft.AspNetCore.Mvc.ViewFeatures": "1.0.0-rc2-final"
  },

  "tools": {
    "Microsoft.AspNetCore.Server.IISIntegration.Tools": {
      "version": "1.0.0-preview1-final",
      "imports": "portable-net45+win8+dnxcore50"
    }
  },
  "frameworks": {
    "netcoreapp1.0": {
      "imports": [
        "dotnet5.6",
        "dnxcore50",
        "portable-net45+win8"
      ]
    }
  },

  "buildOptions": {
    "emitEntryPoint": true,
    "preserveCompilationContext": true
  },

  "runtimeOptions": {
    "gcServer": true
  },

  "publishOptions": {
    "include": [
      "wwwroot",
      "web.config"
    ]
  },

  "scripts": {
    "postpublish": [ "dotnet publish-iis --publish-folder %publish:OutputPath% --framework %publish:FullTargetFramework%" ]
  }
}

Now I want to add HttpConfiguration config = new HttpConfiguration(); in my unit test.

But HtppConfiguration is from ASP.NET WEB API 2. How to change my project.json file? Or is there any replacement for it in ASP.NET CORE RC2?

6
  • Why do you need it? Why do you want to change it? What you're doing do not sound like unit test. Unit test should only test small chunks of code (units). You should redesign your classes instead, depending on a configuration file in unit test is definitely wrong Commented Jun 18, 2016 at 13:16
  • @Tseng, I want to do in memory unit test. See the example here. Is the example wrong? Commented Jun 18, 2016 at 13:32
  • If you'd have read the title of this article, you'd have realized it's not about unit testing ;) Commented Jun 18, 2016 at 14:16
  • @Tseng, my bad:). It is an integration test. But whatever, how to get HtppConfiguration in asp.net core rc2? Commented Jun 18, 2016 at 14:18
  • What exactly do you want to achieve? Use an alternate project.json? Or do you want to replace certain dependencies with mocks? You could check out how Swashbuckle Swagger (ASP.NET Core Swagger Generator) does integration tests here github.com/domaindrivendev/Ahoy/blob/master/test/…. Basically it boils down to having separate projects with their own project.json Commented Jun 18, 2016 at 14:24

1 Answer 1

2

ASP.Core provides an easy way for integration testing using TestServer class. The following may help to start using it:

and keep in mind that a lot of projects in https://github.com/aspnet use TestServer for testing (like Diagnostics ).

Sign up to request clarification or add additional context in comments.

3 Comments

It is hard to follow. I find the link. But there is no zip file or git to pull the sample.
I marked the answer, thanks. I have a following question, if I want to add a unit test or integration test project. What is the project template? Is it a unit test project or just a folder under the web application project? From asp.net team document, the test project has a project.json file. My question is if it is an unit test project template, there is no project.json.
You should create a simple .NET Core Class Library Project (that by default, as any .NET Core project will have project.json file), as unit tests is a classes with public methods.

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.