How-To: Use Class File for Blazor Logic Code

As our logic continues to grow and our testing requirements increase, we will find that it is more efficient to separate our application logic from the rendering logic on pages. This split helps us separate these concerns and build cleaner pages. Also, having the logic within a separate C# class allows us to unit test … Continue reading How-To: Use Class File for Blazor Logic Code

How-To: Use Blazor Code-Behind File

In Blazor, sometimes our page code becomes large and cumbersome. Rather than keep all of the HTML markup and C# code in the same .razor file, we can split our markup and code into separate files. Blazor supports creating code-behind files for the .razor file (similar to other .NET technologies like WinForms, ASP.NET, WPF, etc). … Continue reading How-To: Use Blazor Code-Behind File

How-To: Write bUnit Test for Component

bUnit is a testing library for Blazor components. Its goal is to make it easy to write comprehensive, stable unit tests for components. We will learn the steps to create a bUnit test class from setup to rendering to validation. This test will focus on testing a static component with a simple rendering operation. First, we must have a … Continue reading How-To: Write bUnit Test for Component

How-To: Create New Blazor Component

Blazor apps are based on components. A component in Blazor is the atomic unit of composition for any UI element, such as a page, control, dialog, or data entry form. Components are .NET C# classes built into assemblies. They can: Define UI rendering logic.Handle user events.Be nested and reused.Be shared and distributed as Razor class libraries or NuGet packages. The … Continue reading How-To: Create New Blazor Component

How-To: Unit Test Blazor Pages with DataBinding

Continuing with our use of the bUnit testing library for Blazor components. We will investigate how to create unit and component tests for pages/components that use both one-way and two-way data bindings. We will look at changing data on the page and performing actions (like button clicks) and then seeing how that impacts the page rendering. … Continue reading How-To: Unit Test Blazor Pages with DataBinding

How-to: Add bUnit Test Project to Blazor Solution

Having automated tests for our Blazor applications is very important. We can use xUnit (or any other) test framework to write unit tests for the C# classes in our app. However, some part of our logic (even if it's just the databinding logic) lives in Blazor components and pages. For those to be tested, we … Continue reading How-to: Add bUnit Test Project to Blazor Solution