Base solution for your next web application
Open Closed

Unit tests in extended app service class #11974


User avatar
0
ashjackson created

ASPZ Version - 13.1, aspnetcore + angular. DB - Entity Framework + MySQL

Hi There, I've added an additional method to the .extended class of an entity app service generated with Power Tools, and created an associated unit test. The unit test however fails with a registration error:

Abp.AbpException: Can not register IXxxxxxxxAppServiceExtended. It should be a non-abstract class. If not, it should be registered before.

Abp.AbpException
Can not register IXxxxxxxxAppServiceExtended. It should be a non-abstract class. If not, it should be registered before.
   at Abp.TestBase.AbpIntegratedTestBase`1.EnsureClassRegistered(Type type, DependencyLifeStyle lifeStyle)

The interface for the extended app service looks like this:

using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using Abp.Application.Services;
using Abp.Application.Services.Dto;
using Xxxxxxxx.Xxxxxxxx.Dtos;
using Xxxxxxxx.Dto;

namespace Xxxxxxxx.Xxxxxxxx
{
    public interface IXxxxxxxxAppServiceExtended
    {
        // Write your custom code here. 
        // ASP.NET Zero Power Tools will not overwrite this class when you regenerate the related entity.
        
        Task<List<Tuple<String,String>>> GetValidationMessagesAsync(Guid id);
    }
}

And the implementation:

using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using Abp.Domain.Repositories;
using Xxxxxxx.Xxxxxx.Exporting;
using Xxxxxx.Authorization;
using Abp.Authorization;
using Xxxxxx.Storage;

namespace Xxxxxx.Xxxxxxx
{
    [AbpAuthorize(AppPermissions.Pages_Xxxxxx)]
    public class XxxxxxxAppService : XxxxxxxAppServiceBase,
        IXxxxxxAppService,
        IXxxxxxAppServiceExtended
    {
        public XxxxxxxAppService(IRepository<Xxxxxxx, Guid> xxxxxxxRepository,
            IXxxxxxExcelExporter xxxxxxxExcelExporter,
            IRepository<Xxxxxxx,Guid> lookup_xxxxxxxRepository)
        : base(xxxxxxxRepository, xxxxxxxExcelExporter, lookup_xxxxxxxRepository
        )
        {
        }

        // Write your custom code here. 
        // ASP.NET Zero Power Tools will not overwrite this class when you regenerate the related entity.

        public async Task<List<Tuple<String, String>>> GetValidationMessagesAsync(Guid id)
        {
          // Implementation
        }

    }
}

Test:

using System;
using System.Linq;
using System.Threading.Tasks;
using JetBrains.Annotations;
using Xxxxxx.Xxxxxxx;
using Shouldly;
using Xunit;

namespace MSystem.Tests.App.Shipping.Shiptheory;

[TestSubject(typeof(XxxxxxxAppService))]
public class XxxxxxxAppServiceTest : AppTestBase
{
    private readonly IXxxxxxxAppServiceExtended _xxxxxxxAppServiceExtended;
    private readonly Guid _testId;

    public XxxxxxxAppServiceTest()
    {
        _testId = Guid.NewGuid();
        _xxxxxxxAppServiceExtended = Resolve<IXxxxxxxAppServiceExtended>();
        SeedTestData();
    }

    private void SeedTestData()
    {
      // Seeding test data
    }
    
    [Fact]
    public async Task Should_Get_No_Validation_Messages()
    {
        // Test
    }
}

I was expecting the IXxxxxxxAppServiceExtended service to auto-register like the base service does, but for some reason that hasn't happened.

Thanks, AJ.


1 Answer(s)