2022-04-20 22:34:13 +00:00
|
|
|
|
using System;
|
|
|
|
|
using Blazored.LocalStorage;
|
|
|
|
|
using Fluxor;
|
|
|
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
|
|
|
using Start.Client.Store.State;
|
|
|
|
|
using Start.Shared.Api;
|
|
|
|
|
using Start_Tests.Client.MockApis;
|
|
|
|
|
|
|
|
|
|
namespace Start_Tests.Client.Store {
|
|
|
|
|
public abstract class UnitTestWithFluxor {
|
|
|
|
|
protected IServiceProvider ServiceProvider { get; set; }
|
|
|
|
|
protected IStore Store { get; set; }
|
2022-04-28 15:57:58 +00:00
|
|
|
|
protected IDispatcher Dispatcher { get; set; }
|
2022-04-20 22:34:13 +00:00
|
|
|
|
protected IState<RootState> State { get; set; }
|
|
|
|
|
// Add child states in the individual tests
|
|
|
|
|
|
|
|
|
|
protected Bunit.TestContext BunitTc { get; set; }
|
|
|
|
|
|
|
|
|
|
public UnitTestWithFluxor() {
|
|
|
|
|
this.ResetState();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void ResetState() {
|
|
|
|
|
this.BunitTc = new Bunit.TestContext();
|
|
|
|
|
|
|
|
|
|
BunitTc.Services.AddBlazoredLocalStorage();
|
|
|
|
|
BunitTc.Services.AddFluxor(config => config.ScanAssemblies(typeof(RootState).Assembly));
|
|
|
|
|
BunitTc.Services.AddScoped<IBookmarksApi>(sp => new MockBookmarksApi());
|
|
|
|
|
BunitTc.Services.AddScoped<IBookmarkGroupsApi>(sp => new MockBookmarkGroupsApi());
|
|
|
|
|
BunitTc.Services
|
|
|
|
|
.AddScoped<IBookmarkContainersApi>(sp => new MockBookmarkContainersApi());
|
|
|
|
|
|
|
|
|
|
this.Store = this.BunitTc.Services.GetRequiredService<IStore>();
|
2022-04-28 15:57:58 +00:00
|
|
|
|
this.Dispatcher = this.BunitTc.Services.GetRequiredService<IDispatcher>();
|
2022-04-20 22:34:13 +00:00
|
|
|
|
this.State = this.BunitTc.Services.GetRequiredService<IState<RootState>>();
|
|
|
|
|
this.Store.InitializeAsync().Wait();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|