CURRICULUM PREVIEWRevision 1 · Open for reviewReview the full course
CONNECTING THE PIECES8 min read

C# with a purpose

Model a booking with values, invariants, and clear ownership.

The idea

A booking reserves one seat for a tenant. Represent the identity as an immutable value and reject an empty tenant before persistence. A record is useful for data with value equality; it does not automatically enforce business rules. Keep rule checks close to the operation that needs them.

Follow the flow

Make it concrete

This excerpt isolates the concept. Connect it to the booking API as you work through the exercise.

Focused example
C#
public sealed record Booking(Guid Id, string TenantId);

static Booking CreateBooking(string tenantId)
{
    ArgumentException.ThrowIfNullOrWhiteSpace(tenantId);
    return new Booking(Guid.NewGuid(), tenantId);
}

Decisions that matter

  • An immutable record makes updates deliberate; its referenced objects may still be mutable.
  • Keep transport validation and domain invariants distinct: both protect different boundaries.
  • Use explicit constructors or factory methods when a value must always be valid.

Your turn

Add a seat count and reject a value below one. What behavior should a test assert instead of checking the exact generated ID?

Reveal a worked answer

Assert that invalid counts are rejected and a valid booking retains the tenant and count. Check that the ID is nonempty and unique across calls; avoid binding the test to a randomly generated literal.

Keep exploring

One more piece connected.

Mark this lesson complete when you can explain the idea.