Base solution for your next web application
Open Closed

Use Localization on Tests project (unit testing) #746


User avatar
0
byteplatz created

Hello there,

I was wondering why ILocalizationManager does not get injected in custom classes (not appservice and alike) when using the Test infrastructure (extending from AbpIntegratedTestBase).

Is this expected behavior ?

If so, how can I make the ILocalizationManager to be registered in Test infrastructure?

Bruno


5 Answer(s)
  • User Avatar
    0
    byteplatz created

    The issue here is :

    If I resolve ILocalizationManager inside test class constructor = its not registered.

    If I resolve inside a [Fact] it works

    Is this expected behavior ?

    BRuno

  • User Avatar
    0
    hikalkan created
    Support Team

    This test passes for me:

    public class LocalizationManager_Constructor_Resolve_Test : AbpIntegratedTestBase
        {
            private readonly ILocalizationManager _localizationManager;
    
            public LocalizationManager_Constructor_Resolve_Test()
            {
                _localizationManager = Resolve<ILocalizationManager>();
            }
    
            [Fact]
            public void Test_If_Null()
            {
                _localizationManager.ShouldNotBeNull();            
            }
        }
    

    There is no such a restriction.

  • User Avatar
    0
    byteplatz created

    Thank you Halil.

    I will try to reproduce the test and let you know

    Bruno

  • User Avatar
    0
    raffee created

    Hi, I'm facing this same issue, but not in the test classes.

    I want to create a custom exception type that contains a localized error message (specific to the exception, and not injected from outside). But when I try to resolve the ILocalizationManager interface I get an error that it is not implemented.

  • User Avatar
    0
    hikalkan created
    Support Team

    Can you share some code. ILocalizationManager should be injectable, because most of base classes (MVC Controllers, App services) already injecting and using it eveywhere.