Does xunit understand asp.net5? - xunit

I'm trying to get xunit wired up to test an asp.net5 application. If I create a vanilla .dll for my test project, I'm missing a bunch of references, and when I try to add mvc6, I run into problems.
PM> Install-Package Microsoft.AspNet.Mvc -Pre
Install-Package : Failed to add reference to 'System.IO'. Please make sure that it is in the Global Assembly Cache.
At line:1 char:1
+ Install-Package Microsoft.AspNet.Mvc -Pre
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [Install-Package], Exception
+ FullyQualifiedErrorId : NuGetCmdletUnhandledException,NuGet.PackageManagement.PowerShellCmdlets.InstallPackageCommand
So, being clever, I thought I'd create my test project with the same asp.net5 template as the project being tested. This gets me the references I need and my test project compiles, but the new project structure screws the discovery. The VS test runner can't find the test .dll (no tests found), and the console test runner, if I point it to the .dll in artifacts\bin[projName]\Debug\dnx451
C:\NotilusTNE\Sources\Hub\[projName]\Dev\[projName]>packages\xunit.runner.con
sole.2.1.0\tools\xunit.console "artifacts\bin\[projName]Tests2\Debug\dnx451\[projName]Tests2.dll"
xUnit.net Console Runner (64-bit .NET 4.0.30319.42000)
System.InvalidOperationException: Unknown test framework: could not find xunit.d
ll (v1) or xunit.execution.*.dll (v2) in C:\NotilusTNE\Sources\Hub\[projName]\
Dev\[projName]\artifacts\bin\[projName]Tests2\Debug\dnx451
Has anyone got xunit successfully testing an asp.net5 application? Surely?

Ok there's only one right way to do this. Specific versions of ASP.NET5 applications need specific versions of xunit, as explained here. Instructions followed to the letter, including creating the .dll type "Class Library (Package)". Hopefully this will be useful to someone.

Related

How to use Package Manager Console powershell outside visual studio

I have a powershell script which has nuget commands like:
Get-Project -All
Get-Package -ProjectName
When I run package manager console on visual studio like:
PM> .\download-packages-license.ps1
It worked but I cannot run powershell. I need a hlp.
Powershell error message:
download-packages-license.ps1 cannot be loaded because running scripts is disabled on this system. For more information, see about_Execution_Policies at https:/go.microsoft.com/
fwlink/?LinkID=135170.
At line:1 char:1
+ .\download-packages-license.ps1
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : SecurityError: (:) [], PSSecurityException
+ FullyQualifiedErrorId : UnauthorizedAccess
How to use Package Manager Console powershell outside visual studio
I am afraid you could not use Package Manager Console powershell outside visual studio. That because package manager console is providing is access to visual studio objects:
https://github.com/NuGet/Home/issues/1512
So, if you want use Package Manager Console powershell outside visual studio, we have to parse the .csproj file or .sln solution file with powershell manually, like:
How do I programmatically list all projects in a solution?
Hope this helps.

The type 'IdentityRole' is defined in an assembly that is not referenced

I'm getting the following error when I attempt to inherit my dbcontext in an asp.net core 2.0 library from IdentityDbContext:
Error CS0012 The type 'IdentityRole' is defined in an assembly that is not referenced. You must add a reference to assembly 'Microsoft.Extensions.Identity.Stores, Version=2.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60'.
When I attempt to install the pkg I get:
Unable to find version '2.0.0' of package 'Microsoft.Extensions.Identity.Stores'.
At line:1 char:1
+ Install-Package Microsoft.Extensions.Identity.Stores -Version 2.0.0
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [Install-Package], Exception
+ FullyQualifiedErrorId : NuGetCmdletUnhandledException,NuGet.PackageManagement.PowerShellCmdlets.InstallPackageCommand
I've been going round and round with this for two days. Hopefully a solution will come soon...
Because I had the same problem: Add the nuget package via Package Manager Console to your project.
Install-Package Microsoft.Extensions.Identity.Stores -Version 2.0.2
And choose the correct nuget package version.
Install-Package Microsoft.Extensions.Identity.Store will resolve the problem.

dotnet cli <> VS2017 nuget packages restore errors

I've used dotnet cli (2.0.0) to create 2 projects:
dotnet new webapi (name: webapiProject)
dotnet new xunit (name: testProject)
after that, on testProject project:
dotnet add reference webapiProject
test project is an integration test and it uses webapiProjects Startup.
when i do dotnet run on xunit one, all works fine. tests run, references work, all good.
But, when i load testProject.csproj in VS2017 (15.3.3), i get nuget NU1105 error:
Severity Code Description Project File Line Suppression State
Error NU1105 Unable to find project information for 'webapiProject'. The project file may be invalid or missing targets required for restore.
I am actually rather new to dotnet cli and i am not even sure i should be loading *.csproj in VS2017 but i did so because when i opened only my test class then i didn't have intellisense for it.
So, any advice would be highly appreciated about both:
the error
correct workflow

Entity Framework with NuGet - Import-Module error in init.ps1

Here is the complete error message that I get in the Package Manager Console when starting VS2010:
Import-Module : The specified module
'C:\Users\adam.assman\Project\packages\EntityFramework.4.3.1\tools\EntityFramework.psd1'
was not loaded because no valid module file was found in any module
directory. At
C:\Users\adam.assman\Project\packages\EntityFramework.4.3.1\tools\init.ps1:13
char:14
I've installed Entity Framework using NuGet, on a DLL/ClassLibrary project in my solution. The startup project is referencing and using this DLL project. I therefore tried running the startup command from the console with the DLL project selected in the dropdown "Default Project", but that gives me the same error message.
I have NuGet version 1.6.21215.9133 (and obviously EF version 4.3.1).
If I try to run the command "Enable-Migrations -EnableAutomaticMigrations", I get a CommandNotFoundException and I suppose it's a result from the init error. I'm trying to accomplish the simplest form of the automatic migrations, using this guide: http://blogs.msdn.com/b/adonet/archive/2012/02/09/ef-4-3-automatic-migrations-walkthrough.aspx
I have no idea what was wrong, but I finally fixed this by editing the file init.ps1 inside the folder \packages\EntityFramework.4.3.1\tools.
I changed this line:
Import-Module (Join-Path $toolsPath 'EntityFramework.psd1') -ArgumentList $installPath
Into this:
Import-Module '.\packages\EntityFramework.4.3.1\tools\EntityFramework.psd1' -ArgumentList $installPath

New version of NuGet not working on VS2010

I've downloaded ASP.NET MVC 3 RC and the new NuGet CTP version.
When I try to install anything in the thru the Package Manager Console I get the an error message. Here are two samples:
PM> nip elmah
Install-Package : Object reference not set to an instance of an object.
At line:1 char:4
+ nip <<<< elmah
+ CategoryInfo : NotSpecified: (:) [Install-Package], NullReferenceException
+ FullyQualifiedErrorId : NuGet.VisualStudio.Cmdlets.InstallPackageCmdlet
PM> nip SQLCE.EntityFramework
Install-Package : Object reference not set to an instance of an object.
At line:1 char:4
+ nip <<<< SQLCE.EntityFramework
+ CategoryInfo : NotSpecified: (:) [Install-Package], NullReferenceException
+ FullyQualifiedErrorId : NuGet.VisualStudio.Cmdlets.InstallPackageCmdlet
When I use the Add Library Package Reference in the Solution Explorer no message is displayed but the package is not installed.
I tried to revert to NuPack and it works fine but the Package list is not updated (for instance SQLCE.EntityFramework 4.0.8435.1 is not been displayed only 4.0.8402.1).
Any help?
I had the same problem. Deleting my packages folder fixed it.
I experienced exactly the same problem.
In the end I had to remove everything from the packages directory and go through each project and run an "update-package" for each package I had previously installed.
Are you pointing to the old feed by any chance? Or an old local feed?
I also had this problem.
I solved it by ensuring that I did packed with the nuspec and dll in the same folder and the nuspec name was mydll.dll.nuspec. When I deviated from this I got said error.

Resources