MockerBlazorTestBase<(Of <(<'T>)>)> Class

Class MockerBlazorTestBase. Implements the TestContext Implements the IMockerBlazorTestHelpers<(Of <(<'T>)>)>

Namespace:  FastMoq.Web.Blazor
Assembly:  FastMoq.Web (in FastMoq.Web.dll)

Syntax


public abstract class MockerBlazorTestBase<T> : TestContext, 
	IMockerBlazorTestHelpers<T>
where T : ComponentBase
Public MustInherit Class MockerBlazorTestBase(Of T As ComponentBase) _
	Inherits TestContext _
	Implements IMockerBlazorTestHelpers(Of T)
generic<typename T>
where T : ComponentBase
public ref class MockerBlazorTestBase abstract : public TestContext, 
	IMockerBlazorTestHelpers<T>

Type Parameters

T

Examples


Basic Example
C#
public class IndexTests : MockerBlazorTestBase<Index>
{
    [Fact]
    public void Create() => Component.Should().NotBeNull();
}

Examples


Setup Services
C#
protected override Action<TestServiceProvider, IConfiguration, Mocker> ConfigureServices => (services, c, m) => services.AddSingleton<IWeatherForecastService, WeatherForecastService>();

Examples


Setup Roles.
C#
protected override MockerObservableCollection<string> AuthorizedRoles => new MockerObservableCollection<string>() { "Role1", "Role2"}

Examples


Setup Http Response Message
C#
protected override Action<Mocker> SetupComponent => mocker =>
mocker.SetupHttpMessage(() => new HttpResponseMessage { StatusCode = HttpStatusCode.OK, Content = new StringContent("ContextGoesHere")});

Examples


Setup Mocks
C#
protected override Action<Mocker> SetupComponent => mocker =>
{
    mocker.GetMock<IFile>().Setup(f => f.Exists(It.IsAny<string>())).Returns(true);                     // Add setup to mock.
    mocker.Initialize<IDirectory>(mock => mock.Setup(d => d.Exists(It.IsAny<string>())).Returns(true)); // Clears existing mocks and set new mock.
    mocker.GetMock<IDirectory>().Setup(d=>d.Exists("C:\\testfile.txt")).Returns(false);                 // add setup to existing mock.
};

Examples


Click Button by class, tag, or id and check the navigation manager for changes.
C#
NavigationManager.History.Count.Should().Be(0);

ClickButton("button", () => NavigationManager.History.Count == 1);
NavigationManager.History.Count.Should().Be(1);

ClickButton("button[id='testbutton']", () => NavigationManager.History.Count == 2);
NavigationManager.History.Count.Should().Be(2);

ClickButton(FindAllByTag("button").First(x => x.Id == "testbutton"), () => NavigationManager.History.Count == 3);
NavigationManager.History.Count.Should().Be(3);

ClickButton(FindById("testbutton"), () => NavigationManager.History.Count == 4);
NavigationManager.History.Count.Should().Be(4);

ClickButton("button", () => NavigationManager.History.Count == 5, Component, TimeSpan.FromSeconds(5));
NavigationManager.History.Count.Should().Be(5);

ClickButton(e => e.Id == "testbutton", () => NavigationManager.History.Count == 6);
NavigationManager.History.Count.Should().Be(6);

Inheritance Hierarchy


Object
  TestContextBase
    TestContext
      FastMoq.Web.Blazor..::..MockerBlazorTestBase<(Of <(<'T>)>)>