Sample Projects
The fastest way to get started with IcuBlazor is to just copy one of the sample projects in IcuSamples.zip and just add your tests! To compile & run the samples load QuickStart.sln
in Visual Studio, set a startup project like Server.SSBLinked
and run it.
IcuSamples.zip contains various blazor hosting projects including Client-Side Blazor (CSB) and Server-Side Blazor (SSB). If you like, you can maintain both code-bases with two thin server projects: Server.CSBLinked
and Server.SSBLinked
. These projects use a CSB app as if it was an external library. With this setup, you can easily switch between server and wasm execution by changing Visual Studio's Startup Project. Here is a simplified dependency layout of the sample projects:
Easy Setup
Like other Blazor libraries, IcuBlazor requires a little configuration for both client & server projects.
Setup Client Projects
1 Frontend client projects (e.g. CSB.csproj
) need to reference the IcuBlazor
library.
<TargetFramework>net6.0</TargetFramework>
<PackageReference Include="IcuBlazor" Version="1.4.3" />
To target framework ".net5.0" use Version="1.3.1"
2 Configure Program.cs:
using IcuBlazor;
:
public static async Task Main(string[] args) {
:
builder.Services.AddIcuBlazor(new IcuConfig {
IcuServer = builder.HostEnvironment.BaseAddress,
//EnableServer = false,
});
:
await builder.Build().RunAsync();
}
Setup Server Projects
You can run your Blazor app (with Tests) as a frontend-only WASM app by setting EnableServer=false
. However, IcuBlazor will disable some functions. To get the full use of IcuBlazor, your client project needs to be backed by a server project.
1 Configure backend server .csproj (e.g. Server.CSBLinked
, Server.SSBLinked
or SSB
).
For full functionality, target
net6.0-windows
:<TargetFramework>net6.0-windows</TargetFramework> <PackageReference Include="IcuBlazor.Server" Version="1.4.3" /> <PackageReference Include="IcuBlazor.Native.Win" Version="1.4.3" />
You can target non-windows frameworks (e.g. linux) with the following:
<TargetFramework>net6.0</TargetFramework> <PackageReference Include="IcuBlazor.Server" Version="1.4.3" />
2 Configure the server startup.
Either insert the following lines in your Minimal Web app Program.cs:
using IcuBlazor; : builder.Services.AddIcuBlazor(new IcuConfig { }); builder.Services.AddIcuServer(); : app.UseIcuServer(app.Environment); :
OR insert these lines in Startup.cs:
using IcuBlazor; : public void ConfigureServices(IServiceCollection services) { : services.AddIcuBlazor(new IcuConfig { }); services.AddIcuServer(); : } public void Configure(IApplicationBuilder app, IWebHostEnvironment env) { : app.UseIcuServer(env); : }
3 Optional setup:
- In
_Imports.razor
we recommend adding@using IcuBlazor
.
Add Tests
1 Create a test suite.
Tests are defined in a class that inherits from IcuBlazor.IcuTestSuite
and test method names start with "Test". This is often implmented in a razor file. For example, add a MyTest.razor
file to your project with the following content:
@page "/MyTest"
@inherits IcuBlazor.IcuTestSuite
@code {
public void TestSimpleChecks() {
Check().True(2 < 3, "a true test");
Check().Equal(6*9, 42, "What's the question?");
}
}
2 Create a blazor component to render the test results.
Add an AllTests.razor
file with the following:
@page "/AllTests"
<IcuTestViewer Width="1000">
<MyTest>
</IcuTestViewer>
3 Run the tests by pointing your browser to https://localhost:xxxx/AllTests
.
Now that you have a basic framework for running tests you can explore other testing techniques...
Support
If you have any difficulties see the examples in IcuSamples.zip or contact IcuBlazor Support.