Welcome Guest! To enable all features please Login or Register.

Notification

Icon
Error

ASP.NET Core 2.1 integration tests
ctoru
#1 Posted : Thursday, May 31, 2018 2:57:18 AM(UTC)
Rank: Newbie

Groups: Registered
Joined: 5/31/2018(UTC)
Posts: 3

Hi,

I'm trying to run the sample integration test project from the ASP.NET Core documentation, but I am receiving the following error:

Quote:

System.InvalidOperationException: Solution root could not be located using application root C:\Users\Name\AppData\Local\NCrunch\27496\3\RazorPagesProject.Tests\bin\Debug\netcoreapp2.1\.
at Microsoft.AspNetCore.TestHost.WebHostBuilderExtensions.UseSolutionRelativeContentRoot(IWebHostBuilder builder, String solutionRelativePath, String applicationBasePath, String solutionName)
at Microsoft.AspNetCore.Mvc.Testing.WebApplicationFactory`1.SetContentRoot(IWebHostBuilder builder)
at Microsoft.AspNetCore.Mvc.Testing.WebApplicationFactory`1.EnsureServer()
at Microsoft.AspNetCore.Mvc.Testing.WebApplicationFactory`1.CreateDefaultClient(DelegatingHandler[] handlers)
at Microsoft.AspNetCore.Mvc.Testing.WebApplicationFactory`1.CreateClient(WebApplicationFactoryClientOptions options)
at RazorPagesProject.Tests.IntegrationTests.BasicTests.CanGetAGithubUser() in C:\Users\Name\source\repos\IntegrationTestSample\RazorPagesProject.Tests\IntegrationTests\BasicTests.cs:line 74
at Xunit.Sdk.TestInvoker`1.<>c__DisplayClass48_1.<<InvokeTestMethodAsync>b__1>d.MoveNext() in C:\Dev\xunit\xunit\src\xunit.execution\Sdk\Frameworks\Runners\TestInvoker.cs:line 260
--- End of stack trace from previous location where exception was thrown ---
at Xunit.Sdk.ExecutionTimer.AggregateAsync(Func`1 asyncAction) in C:\Dev\xunit\xunit\src\xunit.execution\Sdk\Frameworks\ExecutionTimer.cs:line 48
at Xunit.Sdk.ExceptionAggregator.RunAsync(Func`1 code) in C:\Dev\xunit\xunit\src\xunit.core\Sdk\ExceptionAggregator.cs:line 90


The tests run correctly using the Visual Studio and ReSharper test runners.

The documentation says to disable shadow copy in the xunit.runner.json for the xUnit runner, however I'm not able to find a way to make this work using NCrunch.

Thanks.
Remco
#2 Posted : Thursday, May 31, 2018 3:23:04 AM(UTC)
Rank: NCrunch Developer

Groups: Administrators
Joined: 4/16/2011(UTC)
Posts: 5,373

Thanks: 705 times
Was thanked: 878 time(s) in 835 post(s)
Hi, thanks for sharing this problem.

Does enabling the 'Copy referenced assemblies to workspace' setting for the projects involved make any difference for you?
ctoru
#3 Posted : Thursday, May 31, 2018 3:40:59 AM(UTC)
Rank: Newbie

Groups: Registered
Joined: 5/31/2018(UTC)
Posts: 3

Thanks for your reply.

Changing the Copy referenced assemblies to workspace setting doesn't appear to make any difference (same exception, still looking in the AppData folder).
Remco
#4 Posted : Thursday, May 31, 2018 4:49:48 AM(UTC)
Rank: NCrunch Developer

Groups: Administrators
Joined: 4/16/2011(UTC)
Posts: 5,373

Thanks: 705 times
Was thanked: 878 time(s) in 835 post(s)
Thanks for confirming this.

We'll do some deeper looking into this after .NET Core 2.1 is released. At the moment I'm having trouble getting the sample solution to build in my environment. The current situation with pre-release dependency conflicts seems to create all kinds of challenges.

Based on the message you're receiving here, I'm not optimistic that we can find a way to make this work without significant effort. The code here appears to be trying to find a solution file and using this to discover the web code, which is a major problem for NCrunch as in our workspaces the solution as a concept just doesn't exist. It's quite possible that MS have finally found a design that is so baked into the solution structure that we have no easy way to cater for it. It's hard for me to be certain about any of this without taking more time to analyse the issue, I'm merely stating this to help manage your expectations. If you have alternative design options, I do recommend exploring them.
ctoru
#5 Posted : Thursday, May 31, 2018 5:06:28 AM(UTC)
Rank: Newbie

Groups: Registered
Joined: 5/31/2018(UTC)
Posts: 3

.NET Core 2.1 was released today :)

I thought that may be the case with this one. Thanks for looking into it.

Let me know if you'd like me to upload the solution I have with just the integration test project and tests.
Remco
#6 Posted : Thursday, May 31, 2018 5:57:40 AM(UTC)
Rank: NCrunch Developer

Groups: Administrators
Joined: 4/16/2011(UTC)
Posts: 5,373

Thanks: 705 times
Was thanked: 878 time(s) in 835 post(s)
Thanks :) We'll take a look and will let you know when we have more information.
ElFik
#7 Posted : Monday, June 4, 2018 11:15:32 PM(UTC)
Rank: Newbie

Groups: Registered
Joined: 6/4/2018(UTC)
Posts: 1

Remco;12242 wrote:
Thanks :) We'll take a look and will let you know when we have more information.



It looks like you could investigate further around this area.

If we can get the correct TestAssemblies and the WebApplicationFactoryContentRoot configured correctly (no easy feat :)) it may be possible to load the correct content
Remco
#8 Posted : Wednesday, June 6, 2018 6:22:57 AM(UTC)
Rank: NCrunch Developer

Groups: Administrators
Joined: 4/16/2011(UTC)
Posts: 5,373

Thanks: 705 times
Was thanked: 878 time(s) in 835 post(s)
To update everyone on this issue, we've taken a deep look at it, and it's not good.

This package works by hard-baking the location of the web project into the test project's binary. So if the web project moves relative to the test project, everything breaks. Given the current design of NCrunch, that's a dealbreaker because we re-use test project binaries across different test runs with environments that are dynamically constructed out of whichever projects happen to be on the latest version of the code at the time. In short, given it's structure, there is no way we can make this tool work with NCrunch without either:

1. Significantly redesigning the NCrunch engine to introduce new concurrency constraints, introducing loss of performance, extra complexity, lots of work and all the potential issues that go with it (not really feasible)
2. Introducing a code change to the toolset to force it to use the web project from a specific location at run time

We can, of course, introduce IL-level hacks to force the toolset to work under the existing structure, but it feels cleaner to get a solution implemented in the toolset itself. I'll raise this issue with MS internally to see if they can help here.

At this stage it's safe to say that it will likely be at least a few weeks before we have a solution to this problem.
1 user thanked Remco for this useful post.
GreenMoose on 6/7/2018(UTC)
austsw
#9 Posted : Tuesday, July 3, 2018 3:43:56 PM(UTC)
Rank: Newbie

Groups: Registered
Joined: 7/3/2018(UTC)
Posts: 1
Location: United States of America

Quote:
To update everyone on this issue, we've taken a deep look at it, and it's not good.

This package works by hard-baking the location of the web project into the test project's binary. So if the web project moves relative to the test project, everything breaks. Given the current design of NCrunch, that's a dealbreaker because we re-use test project binaries across different test runs with environments that are dynamically constructed out of whichever projects happen to be on the latest version of the code at the time. In short, given it's structure, there is no way we can make this tool work with NCrunch without either:

1. Significantly redesigning the NCrunch engine to introduce new concurrency constraints, introducing loss of performance, extra complexity, lots of work and all the potential issues that go with it (not really feasible)
2. Introducing a code change to the toolset to force it to use the web project from a specific location at run time

We can, of course, introduce IL-level hacks to force the toolset to work under the existing structure, but it feels cleaner to get a solution implemented in the toolset itself. I'll raise this issue with MS internally to see if they can help here.

At this stage it's safe to say that it will likely be at least a few weeks before we have a solution to this problem.


Has there been any movement with regard to this issue?
Remco
#10 Posted : Tuesday, July 3, 2018 11:55:12 PM(UTC)
Rank: NCrunch Developer

Groups: Administrators
Joined: 4/16/2011(UTC)
Posts: 5,373

Thanks: 705 times
Was thanked: 878 time(s) in 835 post(s)
austsw;12426 wrote:

Has there been any movement with regard to this issue?


Yes! There has been movement, but no usable results yet. It's looking like this will require code changes on both sides (NCrunch and the package). I've submitted a PR to MS and we're discussing it with them directly.
Remco
#11 Posted : Saturday, July 7, 2018 1:51:13 AM(UTC)
Rank: NCrunch Developer

Groups: Administrators
Joined: 4/16/2011(UTC)
Posts: 5,373

Thanks: 705 times
Was thanked: 878 time(s) in 835 post(s)
Here's the pull request for anyone interested in following this closely (or chipping in!) - https://github.com/aspnet/Mvc/pull/8004#discussion_r200723013.
Remco
#12 Posted : Wednesday, July 18, 2018 11:49:11 PM(UTC)
Rank: NCrunch Developer

Groups: Administrators
Joined: 4/16/2011(UTC)
Posts: 5,373

Thanks: 705 times
Was thanked: 878 time(s) in 835 post(s)
The pull request for this change has been accepted from MS's side. My understanding is that it should be in the v2.2 release of the library. I'm not sure when v2.2 is expected. Hopefully when it arrives, we'll have NCrunch v3.18 released so that we're ready for it. If not, I'll just push an early build of v3.18 with a fix for this specific issue.
davetorutek
#13 Posted : Sunday, July 22, 2018 8:38:34 PM(UTC)
Rank: Newbie

Groups: Registered
Joined: 5/31/2018(UTC)
Posts: 1
Location: New Zealand

Was thanked: 1 time(s) in 1 post(s)
ASP.Net Core 2.2 Roadmap
https://github.com/aspnet/Announcements/issues/307

(Copy/Paste)
We are currently planning to have 3 previews before RTM:
August – Preview 1
September - Preview 2
October - Preview 3
Before End-of-year – RTM
1 user thanked davetorutek for this useful post.
Remco on 7/23/2018(UTC)
sextondjc
#14 Posted : Tuesday, July 31, 2018 11:09:39 AM(UTC)
Rank: Member

Groups: Registered
Joined: 6/7/2017(UTC)
Posts: 12
Location: Ireland

Thanks: 4 times
Was thanked: 4 time(s) in 4 post(s)
Are there any workarounds in the meantime?
Remco
#15 Posted : Wednesday, August 1, 2018 8:13:42 AM(UTC)
Rank: NCrunch Developer

Groups: Administrators
Joined: 4/16/2011(UTC)
Posts: 5,373

Thanks: 705 times
Was thanked: 878 time(s) in 835 post(s)
sextondjc;12475 wrote:
Are there any workarounds in the meantime?


NCrunch v3.18 has just been released including the NCrunch-side solution to this problem. Unfortunately, the solution won't be effective until ASP.NET pull request 8073 goes out the door in one of MS's releases. Hopefully they'll have a preview of .NET Core 2.2 out soon and the change will be included in this.

Unfortunately, I know of no workaround for this problem. I can honestly say that I did try very hard to find one.
2 users thanked Remco for this useful post.
sextondjc on 8/1/2018(UTC), jonas on 9/18/2018(UTC)
sextondjc
#16 Posted : Wednesday, August 1, 2018 8:25:28 AM(UTC)
Rank: Member

Groups: Registered
Joined: 6/7/2017(UTC)
Posts: 12
Location: Ireland

Thanks: 4 times
Was thanked: 4 time(s) in 4 post(s)
Remco;12476 wrote:
I can honestly say that I did try very hard to find one.


I'm sure you did & it is appreciated.Them's the dice at times unfortunately.

Keep up the good work. Still the best product out there by miles.
1 user thanked sextondjc for this useful post.
Remco on 8/1/2018(UTC)
GreenMoose
#17 Posted : Saturday, September 15, 2018 2:35:09 AM(UTC)
Rank: Advanced Member

Groups: Registered
Joined: 6/17/2012(UTC)
Posts: 397

Thanks: 89 times
Was thanked: 42 time(s) in 41 post(s)
Just bumped into the same issue for a new test project and verified it works when using 2.2.0-preview2-35157 (released 12th of September)
(I am using NCrunch 3.20)

So, with net core 2.1 you can use:
Code:

//Use Microsoft.AspNetCore.TestHost (2.1.1) in test project. Test web app target framework netcoreapp2.1.

private HttpClient _client;
public MiscWebTest()
{ //constructor (non static for simplicity)
var builder = new WebHostBuilder()
.UseStartup<Startup>();
var testServer = new TestServer(builder);
_client = testServer.CreateClient();
}

[Test]
public void CanInvokeValues()
{
var response = _client.GetAsync("/api/values").Result;
response.EnsureSuccessStatusCode();
}


with net core 2.2 preview you can use:
Code:

//Web project: Microsoft.AspNetCore.App (2.2.0-preview2-35157), target framework netcoreapp2.2
//Test project: Microsoft.AspNetCore.Mvc.Testing (2.2.0-preview2-35157)

private HttpClient _client;
public MiscWebTest()
{ //constructor (non static for simplicity)
var webAppFactory = new WebApplicationFactory<Startup>();
_client = webAppFactory.CreateClient();


[Test]
public void CanInvokeValues()
{
var client = _testServer.CreateClient();
var response = client.GetAsync("/api/values").Result;
response.EnsureSuccessStatusCode();
}


*Edit: I bumped into another issue with above WebapplicationFactory for 2.2 when using Startup (deriving from the "production startup" type) defined in my test project. so i reverted back to the way I did it in 2.1
Quote:

System.NullReferenceException : Object reference not set to an instance of an object.
at Microsoft.AspNetCore.Mvc.Testing.WebApplicationFactory`1.CreateWebHostBuilder()
at Microsoft.AspNetCore.Mvc.Testing.WebApplicationFactory`1.EnsureServer()
at Microsoft.AspNetCore.Mvc.Testing.WebApplicationFactory`1.CreateDefaultClient(DelegatingHandler[] handlers)
at Microsoft.AspNetCore.Mvc.Testing.WebApplicationFactory`1.CreateDefaultClient(Uri baseAddress, DelegatingHandler[] handlers)
at Microsoft.AspNetCore.Mvc.Testing.WebApplicationFactory`1.CreateClient(WebApplicationFactoryClientOptions options)
at Microsoft.AspNetCore.Mvc.Testing.WebApplicationFactory`1.CreateClient()

below did not help (which I use in netCore 2.1)
Code:

webAppFactoryDerivedStartup.WithWebHostBuilder(cfg =>
cfg.UseSetting(WebHostDefaults.ApplicationKey, typeof(Program).GetTypeInfo().Assembly.FullName));

1 user thanked GreenMoose for this useful post.
jonas on 9/18/2018(UTC)
Users browsing this topic
Guest (5)
Forum Jump  
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.

YAF | YAF © 2003-2011, Yet Another Forum.NET
This page was generated in 0.116 seconds.