# `Trogon.Commanded.TestSupport.CommandHandlerCase`
[🔗](https://github.com/straw-hat-team/beam-monorepo/blob/trogon_commanded@v1.0.1/apps/trogon_commanded/lib/trogon/commanded/test_support/command_handler_case.ex#L1)

This module helps with test cases for testing aggregate states, and command handlers.

## Options

- `aggregate`: The aggregate module to use in the command handler case. If not provided, then you must provide a
  `handler` option.
- `handler`: The command handler module to use in the command handler case. If the `aggregate` option is not provided,
  then the `Handler.Aggregate` module will be used as the aggregate module. Read more about transaction script
  command handler at `Trogon.Commanded.CommandRouter.register_transaction_script/2`.

## Usage

After import the test support file, you should be able to have the module in your test files.

    defmodule MyAggregateTest do
      use Trogon.Commanded.TestSupport.CommandHandlerCase,
        handler: MyCommandHandler,
        async: true

      describe "my aggregate" do
        test "should do something" do
          assert_events(
            [%InitialEvent{}],
            %DoSomething{},
            [%SomethingHappened{}]
          )
        end

        test "the state" do
          assert_state(
            [%InitialEvent{}],
            %DoSomething{},
            %MyAggregate{}
          )
        end

        test "the error" do
          assert_error(
            [%InitialEvent{}],
            %DoSomething{},
            :already_exists
          )
        end
      end
    end

# `assert_error`

# `assert_events`

# `assert_state`

---

*Consult [api-reference.md](api-reference.md) for complete listing*
