Development Components
IcuBlazor is not just a testing framework. It is a library of Blazor deveopment tools.
<ViewOf Model=@myObject>
<ViewOf>
will create a display of any data--even nulls. You can embed this display anywhere in your UI.
To create the appropriate visual, ViewOf looks for a component roughly named typeof(myObject)+"View.razor"
. So if myObject is a System.NullReferenceException
then it looks for NullReferenceExceptionView.razor
. If that doesn't exist, it moves up the type hierarchy until it finds a match. If all else fails, the default ObjectViewer.razor
is used.
Example Usage:
@code {
int[] intArray = { 2, 5, 23 };
WeatherCounter.Weather wc = new WeatherCounter.Weather();
object foo = null;
Exception ex = new Exception("Oops!");
}
<ViewOf Model=42/>
<ViewOf Model=false/>
<ViewOf Model=null/>
<ViewOf Model=@foo/>
<ViewOf Model=@wc/>
<ViewOf Model=@intArray/>
<ViewOf Model=@ex/>
<ExceptionView Model=@ex>
Based on ViewOf, <ExceptionView>
creates an interactive display of the exception. It has the following features:
- The display is in the UI--not printed in the console.
- By clicking on the header, you can toggle between two views.
- The standard exception stacktrace
- A smaller stacktrace where most "system" lines are removed.
<Debug v=@myVar>
Allows you to see a ViewOf
your variable but displayed in a less intrusive DropDown
component.
Example Usage:
<Debug v="a String constant"/>
<Debug [email protected]/>
<Debug v=@myComponent?.data/> // myComponent may be null
<Debug v=@(this.GetType())/>
Property-Based Testing (Experimental)
Icublazor uses FsCheck to create interactive property-based checks. See Property-Test Demo
The following example tests the round-trip property, FromX(ToX(s))==s
, on a base64 implementation. FsCheck generates many random s
inputs and checks that the property holds. This technique is great for finding (surprising!) edge cases.
public void test_base64_conversions()
{
var pc = new PropertyChecker();
Check().Property(pc, "base64 conversions", (string s) => {
var encString = Str.ToBase64(s);
var decString = Str.FromBase64(encString);
return s.Equals(decString);
});
}
VisNet Graph (Experimental)
Turn complex ideas into simple diagrams. Then turn them into tests. See Diagram Test Demo
Example Usage:
public async Task Test_SimpleGraph()
{
var graph = new Graph<string>();
graph.Filename = "simple";
graph.Tree = true;
graph.TopDownFlow = true;
graph.AddEdge("A", "B");
graph.AddEdge("A", "C");
graph.AddEdge("B", "Cool!");
await render_graph(graph);
await Check().Div("simple_graph");
}
<MyAwesomeIdea>
IcuBlazor is meant to be extended with a number of components that developers would find useful. What component would love to see? Let us know.