MockClient

Struct MockClient 

Source
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 met

Fields§

§client: ResourceClient<T>§expectations: Arc<Mutex<VecDeque<Expectation<T>>>>§_handle: JoinHandle<()>

Implementations§

Source§

impl<T: ActorEntity + Send + 'static> MockClient<T>
where T::Id: Send, T::Create: Send, T::Update: Send, T::Action: Send, T::ActionResult: Send,

Source

pub fn new() -> Self

Creates a new mock client with no expectations.

Source

pub fn client(&self) -> ResourceClient<T>

Returns the client for use in tests.

Source

pub fn expect_get(&mut self, id: T::Id) -> GetExpectationBuilder<T>

Expects a get operation.

Source

pub fn expect_create(&mut self) -> CreateExpectationBuilder<T>

Expects a create operation.

Source

pub fn expect_action(&mut self, id: T::Id) -> ActionExpectationBuilder<T>

Expects an action operation.

Source

pub fn verify(&self)

Verifies that all expectations were met.

Trait Implementations§

Source§

impl<T: ActorEntity + Send + 'static> Default for MockClient<T>
where T::Id: Send, T::Create: Send, T::Update: Send, T::Action: Send, T::ActionResult: Send,

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more