Эта страница ещё не переведена
Ниже показан английский оригинал.
assert_called
assert_called(n) checks that exactly n messages were published to the destination.
The count is of published messages, so one delivery that publishes three times counts three.
A subscriber's assert_called(n) counts handler calls instead: the example asserts one call and three publishes.
The assertion panics with both numbers when they differ, and returns the record for further checks.
assert_called_once and assert_not_called cover one message and none, and messages returns the messages behind the count.
Example
- Macros
- Manual
#[tokio::test]
async fn one_ticket_per_seat() -> Result<(), Box<dyn Error>> {
let tb = TestApp::start(app()).await?;
let broker = tb.broker::<MemoryBroker>();
broker
.message(&Order { id: 7, seats: 3 })
.to("orders")
.publish()
.await?;
broker.subscriber("orders").assert_called_once();
broker.published::<Ticket>("tickets").assert_called(3);
Ok(())
}
#[tokio::test]
async fn one_ticket_per_seat() -> Result<(), Box<dyn Error>> {
let tb = TestApp::start(app()).await?;
let broker = tb.broker::<MemoryBroker>();
broker
.message(&Order { id: 7, seats: 3 })
.to("orders")
.publish()
.await?;
broker.subscriber("orders").assert_called_once();
broker.published::<Ticket>("tickets").assert_called(3);
Ok(())
}