ABP Framework version: v5.1.3 UI type: MVC / Blazor DB provider: EF Core Tiered (MVC) or Identity Server Separated (Angular): Blazor Server Microservices
Expected Behaviour
The Unit Tests would use SQLite In-Memory repository and pass first time out of the box.
Actual Behaviour
The Unit Tests fail and always try to use SQL Server
Steps to reproduce the issue
- Create New Microservices Templates
- Build Solution
- Run Docker Infrastructure
- Run DB Migrator to Setup and Seed Databases
- Open Product Service Solution
- Run Unit Tests. The units test are supposed to use SQLite and seed test data.
- Tests fails because connection string is NULL.
- Bring over appSettings.json to set a connection string.
- Connection fails because it is trying to use SQL Server not SQLite.
- Changing Connection String to valid SQL Server
- Run tests, some tests pass], most fail, however tests are using SQL Server not the in memory DB of SQLite
Summary
We have also tested this against all other unit tests and its the same behaviour as the example product service. Even for new microservice modules added later.
Images below show where there are references to the EF SQL Server Module in the Test base classes.
And this is where it crashes trying to setup a connection
We have spent a good couple of days going through examples and docs and trying to figure out why this does not work. Please could you help us fix this as it should really work out of the box.
Thanks
24 Answer(s)
-
0
hi
We will fix this in the next version. Thanks
-
0
-
0
Thanks for the ticket refund. It puts in a really awkward spot when practicing TDD
- Is there a work around ?
- What causing it as it works ok in a standalone app ?
- When is the new version coming out?
- Is there an escalation process?
-
0
We are planning a new release (5.1.4) on 28.02.2022.
As a workaround, you can update your related
MyServiceEntityFrameworkCoreTestModule
:Configure<AbpDbContextOptions>(options => { options.Configure(abpDbContextConfigurationContext => { abpDbContextConfigurationContext.DbContextOptions.UseSqlite(sqliteConnection); }); });
to
Configure<AbpDbContextOptions>(options => { options.Configure<MyDbContext>(abpDbContextConfigurationContext => { abpDbContextConfigurationContext.DbContextOptions.UseSqlite(sqliteConnection); }); });
-
0
We are planning a new release (5.1.4) on 28.02.2022.
As a workaround, you can update your related
MyServiceEntityFrameworkCoreTestModule
:Configure<AbpDbContextOptions>(options => { options.Configure(abpDbContextConfigurationContext => { abpDbContextConfigurationContext.DbContextOptions.UseSqlite(sqliteConnection); }); });
to
Configure<AbpDbContextOptions>(options => { options.Configure<MyDbContext>(abpDbContextConfigurationContext => { abpDbContextConfigurationContext.DbContextOptions.UseSqlite(sqliteConnection); }); });
thanks gterdem. The above work-around works for most modules except for the administration service module. We followed the below steps and it still errors out,
- Make changes as per your suggestion on AdministrationServiceEntityFrameworkCoreTestModule
- Enable a test method Method1Async in SampleAppService_Tests
- Add Assert.True(true); inside Method1Async
- Run the above test Method1Async ion Test Explorer
This shows this error in Tests (output) window - The active test run was aborted. Reason: Test host process crashed
I get the below error when I try to run the same test in command prompt using 'dotnet test' - Can you please help?
The active test run was aborted. Reason: Test host process crashed
Test Run Aborted with error System.Exception: One or more errors occurred. ---> System.Exception: Unable to read data from the transport connection: An existing connection was forcibly closed by the remote host.. ---> System.Exception: An existing connection was forcibly closed by the remote host. at System.Net.Sockets.NetworkStream.Read(Span
1 buffer) --- End of inner exception stack trace --- at System.Net.Sockets.NetworkStream.Read(Span
1 buffer) at System.Net.Sockets.NetworkStream.ReadByte() at System.IO.BinaryReader.Read7BitEncodedInt() at System.IO.BinaryReader.ReadString() at Microsoft.VisualStudio.TestPlatform.CommunicationUtilities.LengthPrefixCommunicationChannel.NotifyDataAvailable() at Microsoft.VisualStudio.TestPlatform.CommunicationUtilities.TcpClientExtensions.MessageLoopAsync(TcpClient client, ICommunicationChannel channel, Action`1 errorHandler, CancellationToken cancellationToken) --- End of inner exception stack trace --- -
0
We are planning a new release (5.1.4) on 28.02.2022.
...
5.1.4 has been released
-
0
Hi,
I have run the IdentityService and the AdministrationService xUnit Tests in a new solution on 5.1.4 and they both fail with a Test Host Crashed. The Product Service Test Examples work just fine.
C:\Development\apb5.1.4\MyTestApp\services\administration\test\MyTestApp.AdministrationService.Application.Tests\Samples\SampleAppService_Tests.cs
Please could we get some assistance with this.
using System.Threading.Tasks; using Xunit; namespace DataAdmiral.IdentityService.Samples; public class SampleAppService_Tests : IdentityServiceDomainTestBase { //private readonly ISampleAppService _sampleAppService; public SampleAppService_Tests() { //_sampleAppService = GetRequiredService<ISampleAppService>(); } [Fact] public async Task Method1Async() { } }
Starting test execution, please wait... A total of 1 test files matched the specified pattern. The active test run was aborted. Reason: Test host process crashed Test Run Aborted with error System.Exception: One or more errors occurred. ---> System.Exception: Unable to read data from the transport connection: An existing connection was forcibly closed by the remote host.. ---> System.Exception: An existing connection was forcibly closed by the remote host. at System.Net.Sockets.NetworkStream.Read(Span`1 buffer) --- End of inner exception stack trace --- at System.Net.Sockets.NetworkStream.Read(Span`1 buffer) at System.Net.Sockets.NetworkStream.ReadByte() at System.IO.BinaryReader.Read7BitEncodedInt() at System.IO.BinaryReader.ReadString() at Microsoft.VisualStudio.TestPlatform.CommunicationUtilities.LengthPrefixCommunicationChannel.NotifyDataAvailable() at Microsoft.VisualStudio.TestPlatform.CommunicationUtilities.TcpClientExtensions.MessageLoopAsync(TcpClient client, ICommunicationChannel channel, Action`1 errorHandler, CancellationToken cancellationToken) --- End of inner exception stack trace ---.
-
0
Can you share:
- IdentityServiceEntityFrameworkCoreTestModule
ConfigureServices
method - AdministrationServiceEntityFrameworkCoreTestModule
ConfigureServices
method
They should be configured as shown above.
Did you manually update your project or used cli to update?
- IdentityServiceEntityFrameworkCoreTestModule
-
0
Hi,
I created a new M/S Solution on 5.1.4 so I did not have to migrate anything. It just doesn't work when trying to create unit tests in the Identity Service or the Administration Service.
The problem is the samples are commented out so there aren't any tests. If you run the Product Service App Tests it works fine.
-
0
I have reproduced the problem. We'll fix this problem as soon as possible.
-
0
We've fixed this issue and it will be available in the next patch. However I will keep this issue open until we confirm it is fixed. As a work around, adding appsettings.json and appsettings.secret.json to
TestBase
projects of related services should fix the issue. -
0
This question has been automatically marked as stale because it has not had recent activity.
-
0
-
0
Test Run Aborted with error System.Exception: One or more errors occurred. ---> System.Exception: Unable to read data from the transport connection: An existing connection was forcibly closed by the remote host.. ---> System.Exception: An existing connection was forcibly closed by the remote host. at System.Net.Sockets.Socket.Receive(Span1 buffer, SocketFlags socketFlags) at System.Net.Sockets.NetworkStream.Read(Span1 buffer) --- End of inner exception stack trace --- at System.Net.Sockets.NetworkStream.Read(Span1 buffer) at System.Net.Sockets.NetworkStream.ReadByte() at System.IO.BinaryReader.ReadByte() at System.IO.BinaryReader.Read7BitEncodedInt() at System.IO.BinaryReader.ReadString() at Microsoft.VisualStudio.TestPlatform.CommunicationUtilities.LengthPrefixCommunicationChannel.NotifyDataAvailable() at Microsoft.VisualStudio.TestPlatform.CommunicationUtilities.TcpClientExtensions.MessageLoopAsync(TcpClient client, ICommunicationChannel channel, Action1 errorHandler, CancellationToken cancellationToken) --- End of inner exception stack trace ---.
-
0
-
0
we are using 5.2.1 also. I can provide team viewer if you want
-
0
Do you have appsettings.json and appsettings.secrets.json files under
SaasService/TestBase
folder? -
0
I did added them and test but that did not fix the issue. I tried with appsettings.json and appsettings.secrets.json under TestBase and without that both of them did not fix the issue
-
0
see this solution https://support.abp.io/QA/Questions/2826/Replace-module-with-source-code-tests-crashes#answer-fd831a3a-b7f5-a33e-6157-3a035e5f456c
-
0
Hello
Thank you that fixed the issue
-
0
-
0
-
0
posted the screenshots in case someone else is facing the same issue
-
0
thanks! happy coding...