Base solution for your next web application
Open Closed

Test Class and two IocContainer instances #779


User avatar
0
antcandal created

I have a very weird error. I create a standard test class with AbpIntegratedTestBaselike base :

**public class BaseTestBorradores : AbpIntegratedTestBase { protected BaseTestBorradores() {

    }

    #region ImplementacionesBase
    protected override void PreInitialize()
    {
        LocalIocManager.IocContainer.AddFacility<LoggingFacility>(f => f.UseLog4Net().WithAppConfig());
        base.PreInitialize();
    }

    protected override void AddModules(Abp.Collections.ITypeList<Abp.Modules.AbpModule> modules)
    {
        base.AddModules(modules);
        modules.Add<ComisionVirtualApplicationModule>();
    }

    public override void Dispose()
    {
        base.Dispose();
    }
    #endregion
}**

And a class with a test using It :

**public class TestBorradores : BaseTestBorradores { protected IAsuntosService _AsuntosService;

    public TestBorradores()
    {
        _AsuntosService = LocalIocManager.IocContainer.Resolve<IAsuntosService>();
    }

    #region Test
    [Fact]
    public int Altasaunto()
    {
        int id = 0;
        id.ShouldBe(0);
        return id;
    }
    #endregion
}**

The problem is when the i try to resolve the AsuntosService Dependency and the service itself calls inside IocContainer to manually resolve any dependency. The test create one IocContainer ComisionVirtual.IntegrationTest 2 (with the dependencies well resolved) and the application Services use another IocContainer ComisionVirtual.IntegrationTest 1, with causes the app to fail when try to resolve the first direct Call to IocContainer.

Markdown is supported
Copy & paste or drag & drop images (max 30 MB per image)

1 Answer(s)
  • User Avatar
    0
    hikalkan created
    Support Team

    How you resolve dependencies in your AsuntosService? You should inject IIocManager (or IIocResolver) and use it.

    Markdown is supported
    Copy & paste or drag & drop images (max 30 MB per image)