pub struct MockClient<T: ActorEntity> {
client: ResourceClient<T>,
expectations: Arc<Mutex<VecDeque<Expectation<T>>>>,
_handle: JoinHandle<()>,
}Expand description
A mock client with expectation tracking for fluent testing.
§Example
ⓘ
let mut mock = MockClient::<User>::new();
mock.expect_get("user_1".to_string()).return_ok(Some(user));
mock.expect_create().return_ok("user_2".to_string());
let client = mock.client();
// Use client in tests...
mock.verify(); // Ensures all expectations were metFields§
§client: ResourceClient<T>§expectations: Arc<Mutex<VecDeque<Expectation<T>>>>§_handle: JoinHandle<()>Implementations§
Source§impl<T: ActorEntity + Send + 'static> MockClient<T>
impl<T: ActorEntity + Send + 'static> MockClient<T>
Sourcepub fn client(&self) -> ResourceClient<T>
pub fn client(&self) -> ResourceClient<T>
Returns the client for use in tests.
Sourcepub fn expect_get(&mut self, id: T::Id) -> GetExpectationBuilder<T>
pub fn expect_get(&mut self, id: T::Id) -> GetExpectationBuilder<T>
Expects a get operation.
Sourcepub fn expect_create(&mut self) -> CreateExpectationBuilder<T>
pub fn expect_create(&mut self) -> CreateExpectationBuilder<T>
Expects a create operation.
Sourcepub fn expect_action(&mut self, id: T::Id) -> ActionExpectationBuilder<T>
pub fn expect_action(&mut self, id: T::Id) -> ActionExpectationBuilder<T>
Expects an action operation.
Trait Implementations§
Auto Trait Implementations§
impl<T> Freeze for MockClient<T>
impl<T> RefUnwindSafe for MockClient<T>
impl<T> Send for MockClient<T>
impl<T> Sync for MockClient<T>
impl<T> Unpin for MockClient<T>
impl<T> UnwindSafe for MockClient<T>
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