Open Closed

xUnit Service Tests do not work after creating Microservice Template #2648


User avatar
0
thedatacrew created

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

  1. Create New Microservices Templates
  2. Build Solution
  3. Run Docker Infrastructure
  4. Run DB Migrator to Setup and Seed Databases
  5. Open Product Service Solution
  6. Run Unit Tests. The units test are supposed to use SQLite and seed test data.
  7. Tests fails because connection string is NULL.
  8. Bring over appSettings.json to set a connection string.
  9. Connection fails because it is trying to use SQL Server not SQLite.
  10. Changing Connection String to valid SQL Server
  11. 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)
  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    hi

    We will fix this in the next version. Thanks

  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

  • User Avatar
    0
    thedatacrew created

    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?
  • User Avatar
    0
    gterdem created
    Support Team Senior .NET Developer

    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);
        });
    });
    
  • User Avatar
    0
    thedatacrew created

    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,

    1. Make changes as per your suggestion on AdministrationServiceEntityFrameworkCoreTestModule
    2. Enable a test method Method1Async in SampleAppService_Tests
    3. Add Assert.True(true); inside Method1Async
    4. 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(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.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 ---

  • User Avatar
    0
    enisn created
    Support Team .NET Developer

    We are planning a new release (5.1.4) on 28.02.2022.

    ...

    5.1.4 has been released

  • User Avatar
    0
    thedatacrew created

    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 ---.
    
  • User Avatar
    0
    gterdem created
    Support Team Senior .NET Developer

    Can you share:

    1. IdentityServiceEntityFrameworkCoreTestModule ConfigureServices method
    2. AdministrationServiceEntityFrameworkCoreTestModule ConfigureServices method

    They should be configured as shown above.

    Did you manually update your project or used cli to update?

  • User Avatar
    0
    thedatacrew created

    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.

  • User Avatar
    0
    gterdem created
    Support Team Senior .NET Developer

    I have reproduced the problem. We'll fix this problem as soon as possible.

  • User Avatar
    0
    gterdem created
    Support Team Senior .NET Developer

    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.

  • User Avatar
    0
    ServiceBot created
    Support Team Automatic process manager

    This question has been automatically marked as stale because it has not had recent activity.

  • User Avatar
    0
    mhdbazcashin created

    Hello we are using the latest version of abp but we are still getting the below error

  • User Avatar
    0
    mhdbazcashin created

    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 ---.

  • User Avatar
    0
    gterdem created
    Support Team Senior .NET Developer

    I failed to reproduce this error using microservice template version 5.2.1:

    Hello we are using the latest version of abp but we are still getting the below error

    What is your template version?

  • User Avatar
    0
    mhdbazcashin created

    we are using 5.2.1 also. I can provide team viewer if you want

  • User Avatar
    0
    gterdem created
    Support Team Senior .NET Developer

    Do you have appsettings.json and appsettings.secrets.json files under SaasService/TestBase folder?

  • User Avatar
    0
    mhdbazcashin created

    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

  • User Avatar
    0
    alper created
    Support Team Director

    see this solution https://support.abp.io/QA/Questions/2826/Replace-module-with-source-code-tests-crashes#answer-fd831a3a-b7f5-a33e-6157-3a035e5f456c

  • User Avatar
    0
    mhdbazcashin created

    Hello

    Thank you that fixed the issue

  • User Avatar
    0
    mhdbazcashin created

  • User Avatar
    0
    mhdbazcashin created

  • User Avatar
    0
    mhdbazcashin created

    posted the screenshots in case someone else is facing the same issue

  • User Avatar
    0
    alper created
    Support Team Director

    thanks! happy coding...

Made with ❤️ on ABP v8.2.0-preview Updated on March 25, 2024, 15:11