serverlesstechnology / cqrs

A lightweight, opinionated CQRS and event sourcing framework.
Other
382 stars 40 forks source link

What is the correct approach for unit testing a view? #56

Closed aitoroses closed 1 year ago

aitoroses commented 1 year ago

Would there be a possibiliy to add an MemViewRepository?

serverlesstechnology commented 1 year ago

Hi @aitoroses, that should be a fairly trivial implementation with a HashMap but I don't think it's what you need.

If you need to test a view, you should just test it directly. If you are using a GenericQuery then you should test the object that implements the View trait`. That might look something like

    let mut view = MyView::default();
    view.update(&EventEnvelope{
        aggregate_id: "my-aggregate-12345".to_string(),
        sequence: 0,
        payload: MyEvents::SomethingWasDone,
        metadata: Default::default(),
    });

... add asserts here...