Blog Feed

How-To: Write bUnit Tests for Components with EventCallbacks

Component callbacks allow developers to build Blazor components that fire events to their parent components/pages to notify them of state changes. The parent components can then respond to those changes as well. bUnit supports EventCallbacks as parameters on those components, so that we can validate their behavior. First, we must have a Blazor project and … Continue reading How-To: Write bUnit Tests for Components with EventCallbacks

How-To: Write bUnit Tests for Components with Parameters

Component parameters allow developers to build interactive and reusable Blazor components. bUnit provides us a couple of mechanisms for passing parameters to components, so that we can validate their behavior with test data. These parameters are set as part of the TestContext rendering process. First, we must have a Blazor project and corresponding test project. … Continue reading How-To: Write bUnit Tests for Components with Parameters

App-Idea 6: JSON to CSV Converter (Part 2)

We will continue to enhance the JSON to CSV Converter, which allows users to enter text in a simplified JSON format and converts it into a comma-separated value (CSV) format. This app-idea has more complex requirements, so we will cover this application in 3 parts: In part 1, we focused on the basic conversion functionality … Continue reading App-Idea 6: JSON to CSV Converter (Part 2)

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

App-Idea 6: JSON to CSV Converter (Part 1)

The next app that we will look at is the JSON to CSV Converter, which allows users to enter text in a simplified JSON format and converts it into a comma-separated value (CSV) format. To map easily to the flat CSV structure, our JSON input won't deeply support nested objects. This app-idea has more complex … Continue reading App-Idea 6: JSON to CSV Converter (Part 1)

How-To: Define Routing Parameters on Blazor Page

As with Blazor components, we can also define parameters on a page. These parameters have slightly different meaning and are usually referred to as routing parameters. The Blazor routing engine will map segments of a URL to matching parameters on that page object. If no matching routes exist, then the "Not Found" message is displayed … Continue reading How-To: Define Routing Parameters on Blazor Page

How-To: Define EventCallback on Blazor Component

In some cases, a Blazor component needs to inform its parent of a state change. Blazor uses an EventCallback to define how events are passed from a component to its parent component or page. That parent's method gets called whenever the child component's event is fired. Defining an EventCallback is similar to how we place … Continue reading How-To: Define EventCallback on Blazor Component