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

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

message

message(&v) starts an input with the publish builder the service itself publishes through: destination, headers and codec.

The value is an Outgoing type, and the type decides whether the builder still asks for a destination. A type that names its destination publishes there; a type that names none takes to(name). with_headers(&meta) adds a typed header contract, and with_codec(codec) encodes with another codec than the default one. publish() sends the input and drives the reaction, and with checks the value the handler received. TestApp::message publishes onto the app's only broker. With more than one broker it has no single target, so the publish fails with TestError::Ambiguous. tb.broker::<B>().message(..), the BrokerHandle::message of a broker chosen with broker::<B>() or broker_named, publishes onto that broker. A value whose type the test does not own goes through the shortcuts.

Example​

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

let broker = tb.broker::<MemoryBroker>();
broker
.subscriber("orders")
.assert_called_once()
.with(&Order { id: 7 });
broker
.subscriber("refunds")
.assert_called_once()
.with(&Refund { order_id: 7 });
Ok(())
}