3

I've been trying to do a sample 3-tier app with PL, BLL, and DAL and now I'm doing some unit tests. I was about to reference the BLL to my test project but then suddenly it won't allow it. I found out that this class library is different from the regular class library.

So, right now, I don't know if I should replace this with the regular class library or continue using the new one (package). What is appropriate for this situation? Lets say this 3-tier program is a cloud app.

Or maybe the right questions are:

  1. What's the difference between the old class library and this new one?
  2. When is one appropriate? I can't find clear answers googling around.
  3. Can you do unit testing with the new one using current MS Test?
g_b
  • 11,728
  • 9
  • 43
  • 80

2 Answers2

3

If you are going asp.net-core you I would suggest to stick with the newer Class Library (Package), unless you have reason to use that same library in other projects that does not use DNX to compile/execute.

  1. Class Library (.csproj) and Class Library Package (.kproj). The big difference between these two types of projects is that the Class Library (Package) will use the file project.json and DNX to compile, execute and package the library, where as the standard Class Library (.csproj) uses .net framework to compile and execute the library .dll file.

    Side note: The package project (.kproj) will create a NuGet package automatically (where as the Class Library (.csproj) you would have to build your NuGet package manually).

  2. The main thing you need to know is that you can reference a Class Library (.csproj) in a Class Library (Package) (.kproj) and not the other way around, because of DNX. So this means all the unit test libraries wont work with asp.net core at the moment. A good way to get around that is to use XUnit in a Class Library (Project) (.kproj). If this library is shared between other projects that does not support DNX (eg between an older MVC5 project and a new ASP.NET Core project), you cant use a Class Library Package .kproj and would have to go with the standard Class Library .csproj project.

  3. See this answer https://stackoverflow.com/a/31751864/1284637 how to get unit testing working with asp.net core. As answered in 2, app.net-core does not currently support unit test libraries, that means MSTest will also not work.

I hope this helps clear things up for you.

Community
  • 1
  • 1
Nick De Beer
  • 5,232
  • 6
  • 35
  • 50
2

1 and 2 have been answered perfectly by Nick De Beer (my compliments @Nick De Beer).

But as far as 3 is concerned, as of december 2015 there is a NuGet package called MSTest.Runner.Dnx which targets DNX especially for MSTest. You can read here how to set it up in a DNX project: https://dannyvanderkraan.wordpress.com/2016/03/07/asp-net-core-1-0s-dnx-and-mstest/

Danny van der Kraan
  • 5,344
  • 6
  • 31
  • 41