jsakamoto / Toolbelt.Blazor.I18nText

The class library that provides the ability to localize texts on your Blazor app!
Mozilla Public License 2.0
246 stars 23 forks source link

bunit test #39

Closed Niputi closed 3 years ago

Niputi commented 3 years ago

How am I supposed to write bunit tests?

I get the following error message during OnInitializedAsync()

  Message: 
    System.NullReferenceException : Object reference not set to an instance of an object.
  Stack Trace: 
    I18nTextRepository.<FetchTextTableAsync>g__splitLangCode|15_0(String lang)
    I18nTextRepository.FetchTextTableAsync(String langCode, Object targetTableObject)
    I18nTextRepository.GetTextTableAsync[T](Guid scopeId, String langCode, Boolean singleLangInAScope)
    I18nText.GetTextTableAsync[T](ComponentBase component)

I have added the i18n service to the service collection like this

ctx.Services.AddI18nText(r =>
{
    r.IsWasm = () => false;
});
jsakamoto commented 3 years ago

I have not tested this case by myself yet, but could you try the code below?

ctx.Services.AddI18nText(r =>
{
    // 👇 Add this code.
    r.GetInitialLanguageAsync = (serviceProvider, options) => new ValueTask<string>("en");

    r.IsWasm = () => false;
});

I'm not certain at this time, but the reason for your problem looks related to getting the current language code.

I hope the solution above resolves this issue.

Niputi commented 3 years ago

yes. that made the test complete

thank you