1

I have a Blazor app that I'm writing tests for and it would make everything so much easier if I could just instantiate a view / component and trigger the onclick events etc. straight from my test, rather than from seperate injected classes (I have multiple things injected in the views).

E.g. InjectedClass.cs

public class InjectedClass : IInjectedClass
{
    public int MyNumber {get;set;}

    public void SetMyNumber(int num)
    {
        MyNumber = num;
    }
}

MyView.razor:

@inject IInjectedClass injectedClass

...


@code{

    protected override void OnInitialized()
    {
        injectedClass.SetMyNumber(5);
    }
}

At the moment I have to inject the class into my tests and trigger SetMyNumber manually. I want to be able to instantiate MyView.razor and then run

Assert.That(instanceOfMyView.injectedClass.MyNumber == 5)

but instanceOfMyView.injectedClass is hidden due to protection level.

Here's the error in context :

enter image description here

Broad3857
  • 363
  • 1
  • 4
  • 10
  • Maybe using code-behind? see https://stackoverflow.com/a/53448294/842935 and https://learn.microsoft.com/en-us/aspnet/core/blazor/components?view=aspnetcore-3.1#partial-class-support – dani herrera Mar 06 '20 at 11:29

0 Answers0