with
with(&value) checks that the latest handler call received this value, decoded with the default codec.
It reads the most recent call only; the earlier ones are in received.
It decodes the recorded payload with DefaultCodec, the codec the enabled features select (json first).
A handler mounted with another codec is checked with with_codec(&codec, &value), which decodes with that codec.
The value type needs Deserialize, PartialEq and Debug.
The latest call must hold one delivery: on a batch of several it panics, and the batch is read with batches.
with_raw checks the same call as bytes, and with_value the value a carrying delivery lent the handler.
A destination's with checks the value a publish carried.
Example
- Macros
- Manual
#[tokio::test]
async fn the_latest_call_got_the_second_order() -> Result<(), Box<dyn Error>> {
let tb = TestApp::start(app()).await?;
let broker = tb.broker::<MemoryBroker>();
for id in [7, 8] {
broker.message(&Order { id }).to("orders").publish().await?;
}
broker
.subscriber("orders")
.assert_called(2)
.with(&Order { id: 8 });
Ok(())
}
#[tokio::test]
async fn the_latest_call_got_the_second_order() -> Result<(), Box<dyn Error>> {
let tb = TestApp::start(app()).await?;
let broker = tb.broker::<MemoryBroker>();
for id in [7, 8] {
broker.message(&Order { id }).to("orders").publish().await?;
}
broker
.subscriber("orders")
.assert_called(2)
.with(&Order { id: 8 });
Ok(())
}