Add some service unit tests; add base for Fluxor tests
This commit is contained in:
parent
4e2b4d3806
commit
96553c3e2b
9 changed files with 289 additions and 23 deletions
29
Start_Tests/Client/MockApis/MockBookmarkContainersApi.cs
Normal file
29
Start_Tests/Client/MockApis/MockBookmarkContainersApi.cs
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Net.Http;
|
||||
using System.Threading.Tasks;
|
||||
using Refit;
|
||||
using Start.Shared;
|
||||
using Start.Shared.Api;
|
||||
|
||||
namespace Start_Tests.Client.MockApis {
|
||||
public class MockBookmarkContainersApi : IBookmarkContainersApi {
|
||||
public Task<ApiResponse<IEnumerable<BookmarkContainerDto>>> GetAllBookmarkContainers() {
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public Task<ApiResponse<BookmarkContainerDto>> GetBookmarkContainer(
|
||||
int bookmarkContainerId) {
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public Task<ApiResponse<BookmarkContainerDto>> CreateBookmarkContainer(string title,
|
||||
int sortOrder) {
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public Task<HttpResponseMessage> DeleteBookmarkContainer(int bookmarkContainerId) {
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
}
|
||||
23
Start_Tests/Client/MockApis/MockBookmarkGroupsApi.cs
Normal file
23
Start_Tests/Client/MockApis/MockBookmarkGroupsApi.cs
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
using System;
|
||||
using System.Net.Http;
|
||||
using System.Threading.Tasks;
|
||||
using Refit;
|
||||
using Start.Shared;
|
||||
using Start.Shared.Api;
|
||||
|
||||
namespace Start_Tests.Client.MockApis {
|
||||
public class MockBookmarkGroupsApi : IBookmarkGroupsApi {
|
||||
public Task<ApiResponse<BookmarkGroupDto>> GetBookmarkGroup(int bookmarkGroupId) {
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public Task<ApiResponse<BookmarkGroupDto>> CreateBookmarkGroup(string title, string color,
|
||||
int sortOrder, int bookmarkContainerId) {
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public Task<HttpResponseMessage> DeleteBookmarkGroup(int bookmarkGroupId) {
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
}
|
||||
23
Start_Tests/Client/MockApis/MockBookmarksApi.cs
Normal file
23
Start_Tests/Client/MockApis/MockBookmarksApi.cs
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
using System;
|
||||
using System.Net.Http;
|
||||
using System.Threading.Tasks;
|
||||
using Refit;
|
||||
using Start.Shared;
|
||||
using Start.Shared.Api;
|
||||
|
||||
namespace Start_Tests.Client.MockApis {
|
||||
public class MockBookmarksApi : IBookmarksApi {
|
||||
public Task<ApiResponse<BookmarkDto>> GetBookmark(int bookmarkId) {
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public Task<ApiResponse<BookmarkDto>> CreateBookmark(string title, string url,
|
||||
string notes, int sortOrder, int bookmarkGroupId) {
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public Task<HttpResponseMessage> DeleteBookmark(int bookmarkId) {
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
}
|
||||
25
Start_Tests/Client/Store/ContainerListTests.cs
Normal file
25
Start_Tests/Client/Store/ContainerListTests.cs
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
|
||||
using Start.Client.Store.Features.ContainersList;
|
||||
|
||||
namespace Start_Tests.Client.Store {
|
||||
[TestClass]
|
||||
public class ContainerListTests : UnitTestWithFluxor {
|
||||
public TestContext TestContext { get; set; }
|
||||
// Only RootState is needed, so no need to get child objects
|
||||
|
||||
[TestMethod]
|
||||
public void OnFetchContainersList() {
|
||||
base.Store.Dispatch(new FetchContainerListAction());
|
||||
|
||||
Assert.IsTrue(base.State.Value.ContainerListState.IsLoadingContainersList);
|
||||
Assert.AreEqual(0, this.State.Value.ContainerListState.Containers.Count);
|
||||
}
|
||||
|
||||
[TestInitialize]
|
||||
public void InitializeState() {
|
||||
TestContext.WriteLine("Resetting Fluxor state");
|
||||
base.ResetState();
|
||||
}
|
||||
}
|
||||
}
|
||||
37
Start_Tests/Client/Store/UnitTestWithFluxor.cs
Normal file
37
Start_Tests/Client/Store/UnitTestWithFluxor.cs
Normal file
|
|
@ -0,0 +1,37 @@
|
|||
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; }
|
||||
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>();
|
||||
this.State = this.BunitTc.Services.GetRequiredService<IState<RootState>>();
|
||||
this.Store.InitializeAsync().Wait();
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue