Starting Test Server in Memory to test Razor Pages with Playwright - asp.net-core

My objective is to start Playwright in memory and run some end to end tests against a in-memory test server.
I've forked Jonathan's great repo which demonstrates exactly what I want to do, however it's using .Net core 3.1 and a MVC project which uses Program.cs & Start.cs.
I have forked and upgraded the project files to .net 6, I have also added a razor project which uses the new top-level statements in program.cs
https://github.com/carlblanchard/InMemoryPlaywrightDemo (Repo has the failure .net 6.0)
https://github.com/JD-Innovensa/InMemoryPlaywrightDemo (Report that works in .net 3.1)
When running the test When_ClickEmployeeMenuOption_Then_EmployeesPageDisplayed_Chrome the following errors occurs.
System.InvalidOperationException: 'A public method named 'ConfigureAutomatedTesting' or 'Configure' could not be found in the 'Program' type.'
I can't see any decent documentation on how to run a test server against a project with a minimal program.cs file.
If anyone knows how to do this please help, it's been really annoying me.
Thanks in advance.

Related

How to use Microsoft.AspNetCore.DataProtection in the console application?

On the page Non-DI aware scenarios for Data Protection in ASP.NET Core I find the code that is intended to be a console application.
It is unexpected for me because console application references to ASP.NET Core library:
using Microsoft.AspNetCore.DataProtection;
When I tried to run it, I expectedly got an error message about missing assembly.
I asked Microsoft about this https://github.com/dotnet/AspNetCore.Docs/issues/17098. But I just got the come-off answer, I just got the reference to the page which is upper in the content: https://learn.microsoft.com/en-us/aspnet/core/security/data-protection/introduction?view=aspnetcore-3.1#package-layout
When I run the code in the ASP.NET app, the following statement dataProtectionProvider.CreateProtector("Program.No-DI") returned Microsoft.AspNetCore.DataProtection.KeyManagement.KeyRingBasedDataProtector.
Which library contains KeyRingBasedDataProtector?
I included the package https://www.nuget.org/packages/Microsoft.AspNetCore.DataProtection.Abstractions/, but it expectedly does not contain implementation.
In general, are ASP.NET libraries are suitable to use in console applications?
After all, how to run the code from the page Non-DI aware scenarios for Data Protection in ASP.NET Core?
Thank you
I included 3 packages to the console project:
Microsoft.AspNetCore.DataProtection
Microsoft.AspNetCore.DataProtection.Abstractions
Microsoft.AspNetCore.DataProtection.Extensions
This makes the console project working.

.NET Web API Unit Test for model with DbGeography System.DllNotFoundException: Unable to load DLL 'SqlServerSpatial110.dll'

I have a working ASP NET Web APIs, some of which are using Spatial Data Types using DbGeography. I added this line to the startup code to make it work here.
SqlServerTypes.Utilities.LoadNativeAssemblies(Server.MapPath("~/bin"));
I have a unit testing project, which is referencing the project mentioned above. When trying to run a test that calls a method that uses DbGeograohy, I get the error "System.DllNotFoundException: Unable to load DLL 'SqlServerSpatial110.dll'".
This error appeared previously in the Web API project, and I solved by adding the line above to the startup class, which basically loads the native Windows library.
I want to learn if it's possible to have a "Startup" class for the tests, where the library would be loaded before executing them.
Cheers :)

Unable to build .net core AspnetBoilerplate Starter Template

I have spent quite a time trying to load the Initial Project generated by the AspnetBoilerplate startup template all to no avail. This is a .net core template (JQuery with MVC) with Target Cross platform.
See error sample below
I installed the dotnet core 2 for VS 2017. The project won't just build. I can not see anything related to NetStandard, yet that seems to be what the project supports
Any help i can get will be appreciated

Asp.net Core application is not running with VS 2017?

I have installed the visual studio 2017 for ASP.Net Core. I created Dot Net Core project. Build it successfully and run it but on Firefox it shows the blank page and on chrome it shows "**The localhost page isn’t working
localhost is currently unable to handle this request"
I thought there is a problem in code. I debugged the code and there is nothing wrong with the code. It's the default template and code generated for Asp.Net Core. I googled and tried many things like restart the VS, removed cache, etc but nothing worked for me. Then i uninstalled the VS 2017 and used C Cleaner to remove all temp files etc and installed the visual studio 2017 again but the same error came again. Then i created MVC application, console application in VS 2017 and both worked fine. Issue comes only in Asp.net core application. I use fiddler to see the request status and it is 500. I debugged the code but nothing wrong with the code(No Exception). I have tried many things but did not find anything helpful. Can anyone tell me what's the issue?
The blank page response can be caused by a number of reasons. Sometimes because you are lacking something in the system , routing issues, wrong code on the wrong location, .csproj configuration issues, permission issues, and many more.
There are a couple of things you can try:
Check to see if you have the appropriate ASP.NET Core Module installed in you system. (Either x86 or x64 depending on your system )
Make sure you have enabled IIS Integration in your code
See if you have the error middleware in your Configure code, it mostly helps to solve your issues by giving full detail.
Looks like you are running into error similar to this issue with browserlink .What version of browser link package do you have in your machine
Microsoft.VisualStudio.Web.BrowserLink should be 1.0.1 referring the templates
This SO post discuss the similar issue .If that does not solve, Please make sure you have 1.0.1 in your project referenced and then try this
Clearing your NuGet cache
dotnet nuget locals all --clear
Set Environment variable DOTNET_SKIP_FIRST_TIME_EXPERIENCE to 1 . This is to avoid caching packages
dotnet restore
Does it happens to be runtime compilation issues?
I stumble across this issues log while studying the feasibility of using ASP.Net Core for ERP System host on LinuxOS.
Issues #2017 on GitHub
Try setting
<PreserveCompilationContext>false<PreserveCompilationContext>
in your csproj

Xunit not working using Visual Studio Team Services Build VNext

After following several blogs detailing how to get xUnit working with Team Services Build vNext:
http://tech.trailmax.info/2014/01/run-xunit-in-hosted-team-foundation-service/
Running unit tests in TFS/VSO Build vNext using xUnit adapter
http://www.donovanbrown.com/post/2015/06/15/how-to-run-xunit-test-with-vnext-build
None of which worked for me. From examining the build logs I get the following warnings for each of my test assemblies.
--------------------
Warning: [xUnit.net 00:00:00.1644156] Exception discovering tests from CHO.SAM.Business.Test: System.BadImageFormatException:
Could not load file or assembly 'c:\_Work\473cef3c\CHO\CHO.ALL\Tests\CHO.SAM.Business.Test\CHO.SAM.Business.Test\bin\Debug\xunit.execution.desktop.dll' or one of its dependencies. This assembly is built by a runtime newer than the currently loaded runtime and cannot be loaded.
--------------------
Has anyone seen this before? and if so did you figure out a solution?
My thoughts are; my test projects are compiled using .NET Framework 4.6, I was wondering if this could be causing the problem? If so I would have to move over to nUnit or something as I don't feel it's right to change the compilation just to use a single test framework.
Add "/Framework:Framework45" to "Advanced/Other console options" (to run under .NET 4.5)
or
Add "/Framework:Framework40" to "Advanced/Other console options" (to run under .NET 4.0)
or
Change "Advanced/VSTest version" to "Visual Studio 2013" (to run under .NET 3.5)
This error is normally caused by a x64 compiled assembly running on x86 test runner or vice versa. Check the solution build configuration that is being run.
I had this same issue. Adding a UI test did not fix it for me. I found two alternatives that work:
use .net 4.5
OR
Set the advanced options of the VSTest task to use 2013 instead of 2015.
Hopefully this will be fixed soon.
In the end, I added a Visual Studio Coded UI test project and removed all it's contents (a class), it's empty!
I'm assuming it's added a reference or something that the build server felt it needed.
I am now getting my unit tests discovered, running and with code coverage.
Wierd!
It works, but I don't know why...
I ran into this issue when using a .Net Core class library to run my xUnit tests against a .Net Core Web Project (.Net Framework). What solved the issue for me was to change the default processor for running test to X64 in VS2015 via:
Menu Bar -> Test -> Test Settings -> Default Processor Architecture -> X64
This solution was posted by #RehanSaeed here https://github.com/dotnet/cli/issues/3103