Перейти к основному содержимому
Эта страница ещё не переведена

Ниже показан английский оригинал.

assert_called_once

assert_called_once checks that exactly one message was published to the destination.

The assertion counts the messages in the record, published::<T>(name), not the handler calls that produced them. It panics with the count it found when the record holds none or more than one. It returns the record, so with, with_raw and with_header chain after it. assert_called(n) checks any other count, and assert_not_called checks that nothing was published.

Example​

#[tokio::test]
async fn one_order_gets_one_receipt() -> Result<(), Box<dyn Error>> {
let tb = TestApp::start(app()).await?;
let broker = tb.broker::<MemoryBroker>();
broker
.message(&Order { id: 7, seats: 2 })
.to("orders")
.publish()
.await?;

broker.published::<Receipt>("receipts").assert_called_once();
Ok(())
}