Skip to content

Latest commit

 

History

History
78 lines (68 loc) · 2.1 KB

File metadata and controls

78 lines (68 loc) · 2.1 KB

Workflow

New Use Case - Query

  1. Info Needed
    • Name of Query
    • ViewModel name returned
      • Lookup or summary for list operations
      • more detailed vm for individual gets
  2. Build out VM with properties and DTOs
  3. Build out Query with properties
  4. Update Tests
    • Replace user type for admin vs. user
    • Update field validation based on rules of your query
    • Update non-field validation tests with a valid query
    • Add tests for required roles
    • Add a seed data method to populate known data in the DB
    • Add test for not found (if querying a single entity)
    • Update test for valid result to test fields
    • RUN TESTS
  5. Update Query handler
    • Add query validation
    • Add authentication and role
    • Add handler logic

New Use Case - Command

  1. Info Needed
    • Name of command
    • int typically returned
  2. Build out Command with properties
  3. Update Tests
    • Replace user type for admin vs. user
    • Update field validation based on rules of your query
    • Add tests for required roles
    • Add seed data as needed
    • Add tests
      • happy path
      • things not found
  4. Update command handler
    • add command validation
    • add authentication and role
    • add handler logic

Templates

Require Admin Query Example

[Test]
public async Task ShouldRequireAdministratorRole() 
{
    await ResetState();
    var userId = await RunAsDefaultUserAsync();

    var query = new GetAccountQuery { Id = 1 };

    await FluentActions.Invoking(() => SendAsync(query))
        .Should().ThrowAsync<ForbiddenAccessException>();
}

Seed Data Example

protected override async Task SeedData()
{
    await AddAsync<Account>(new Account("ACM", "Acme Industries"));
}

Rule Validation

public CreateAccountCommandValidator()
{
    RuleFor(x => x.Name)
        .MaximumLength(255)
        .NotEmpty();

    RuleFor(x => x.Code)
        .MaximumLength(20)
        .NotEmpty();
}

Auth Headers

[Authorize]
[Authorize(Roles = Roles.Administrator)]