pub struct MockMessageSender {
pub logged_in: bool,
pub session_info: SessionInfo,
pub sent_messages: Vec<SentMessage>,
pub next_error: Option<SteamError>,
pub current_job_id: u64,
}Expand description
Mock message sender for testing.
Records all sent messages for inspection and verification in tests. Can be configured to simulate logged-in or logged-out state.
§Example
ⓘ
let mut mock = MockMessageSender::new_logged_in(12345, 76561198012345678);
// Simulate sending a message
mock.send_message(EMsg::ClientChangeStatus, &body).await?;
// Verify the message was sent
assert_eq!(mock.sent_messages.len(), 1);
assert_eq!(mock.sent_messages[0].msg_type, EMsg::ClientChangeStatus);
// Decode the body for detailed verification
let sent_body: CMsgClientChangeStatus = mock.decode_last_message()?;
assert_eq!(sent_body.persona_state, Some(1));Fields§
§logged_in: boolWhether the mock is in “logged in” state.
session_info: SessionInfoSession information.
sent_messages: Vec<SentMessage>All messages sent through this mock.
next_error: Option<SteamError>If set, next send will return this error.
current_job_id: u64Current job ID source for simulation.
Implementations§
Source§impl MockMessageSender
impl MockMessageSender
Sourcepub fn new_logged_in(session_id: i32, steam_id: u64) -> Self
pub fn new_logged_in(session_id: i32, steam_id: u64) -> Self
Create a mock sender in logged-in state.
Sourcepub fn set_logged_in(&mut self, logged_in: bool)
pub fn set_logged_in(&mut self, logged_in: bool)
Set whether this mock is “logged in”.
Sourcepub fn set_next_error(&mut self, error: SteamError)
pub fn set_next_error(&mut self, error: SteamError)
Make the next send call return an error.
Sourcepub fn last_sent(&self) -> Option<&SentMessage>
pub fn last_sent(&self) -> Option<&SentMessage>
Get the last sent message, if any.
Sourcepub fn decode_last_message<T: Message + Default>(&self) -> Result<T, SteamError>
pub fn decode_last_message<T: Message + Default>(&self) -> Result<T, SteamError>
Decode the body of the last sent message.
Useful for verifying the exact content of sent messages in tests.
Sourcepub fn messages_of_type(&self, msg_type: EMsg) -> Vec<&SentMessage>
pub fn messages_of_type(&self, msg_type: EMsg) -> Vec<&SentMessage>
Get messages of a specific type.
Sourcepub fn service_calls(&self) -> Vec<&SentMessage>
pub fn service_calls(&self) -> Vec<&SentMessage>
Get service method calls.
Trait Implementations§
Source§impl Debug for MockMessageSender
impl Debug for MockMessageSender
Source§impl Default for MockMessageSender
impl Default for MockMessageSender
Source§fn default() -> MockMessageSender
fn default() -> MockMessageSender
Returns the “default value” for a type. Read more
Source§impl MessageSender for MockMessageSender
impl MessageSender for MockMessageSender
Source§fn is_logged_in(&self) -> bool
fn is_logged_in(&self) -> bool
Check if currently logged in.
Source§fn session_info(&self) -> SessionInfo
fn session_info(&self) -> SessionInfo
Get session info for building headers.
Source§fn send_message<'life0, 'life1, 'async_trait, T>(
&'life0 mut self,
msg_type: EMsg,
body: &'life1 T,
) -> Pin<Box<dyn Future<Output = Result<(), SteamError>> + Send + 'async_trait>>
fn send_message<'life0, 'life1, 'async_trait, T>( &'life0 mut self, msg_type: EMsg, body: &'life1 T, ) -> Pin<Box<dyn Future<Output = Result<(), SteamError>> + Send + 'async_trait>>
Send a protobuf message. Read more
Auto Trait Implementations§
impl !Freeze for MockMessageSender
impl !RefUnwindSafe for MockMessageSender
impl Send for MockMessageSender
impl Sync for MockMessageSender
impl Unpin for MockMessageSender
impl UnsafeUnpin for MockMessageSender
impl !UnwindSafe for MockMessageSender
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more