aboutsummaryrefslogtreecommitdiff
path: root/src/di_container/asynchronous/binding/scope_configurator.rs
diff options
context:
space:
mode:
authorHampusM <hampus@hampusmat.com>2022-10-24 22:32:42 +0200
committerHampusM <hampus@hampusmat.com>2022-10-24 22:32:42 +0200
commit8c6431fd834337be7f6b88e3c8a29c6a17e0b9cf (patch)
treeed64a10a89307f30ecfde6dfc2cde10126fcc00a /src/di_container/asynchronous/binding/scope_configurator.rs
parent494d905bcbc50b536de892ecb3fa285dc6b8a727 (diff)
test: add binding configurator unit tests
Diffstat (limited to 'src/di_container/asynchronous/binding/scope_configurator.rs')
-rw-r--r--src/di_container/asynchronous/binding/scope_configurator.rs52
1 files changed, 52 insertions, 0 deletions
diff --git a/src/di_container/asynchronous/binding/scope_configurator.rs b/src/di_container/asynchronous/binding/scope_configurator.rs
index fd42fea..e2e916a 100644
--- a/src/di_container/asynchronous/binding/scope_configurator.rs
+++ b/src/di_container/asynchronous/binding/scope_configurator.rs
@@ -90,3 +90,55 @@ where
Ok(AsyncBindingWhenConfigurator::new(self.di_container.clone()))
}
}
+
+#[cfg(test)]
+mod tests
+{
+ use super::*;
+ use crate::test_utils::{mocks, subjects_async};
+
+ #[tokio::test]
+ async fn in_transient_scope_works()
+ {
+ let mut di_container_mock =
+ mocks::async_di_container::MockAsyncDIContainer::new();
+
+ di_container_mock
+ .expect_set_binding::<dyn subjects_async::IUserManager>()
+ .withf(|name, _provider| name.is_none())
+ .return_once(|_name, _provider| ())
+ .once();
+
+ let binding_scope_configurator = AsyncBindingScopeConfigurator::<
+ dyn subjects_async::IUserManager,
+ subjects_async::UserManager,
+ mocks::async_di_container::MockAsyncDIContainer,
+ >::new(Arc::new(di_container_mock));
+
+ binding_scope_configurator.in_transient_scope().await;
+ }
+
+ #[tokio::test]
+ async fn in_singleton_scope_works()
+ {
+ let mut di_container_mock =
+ mocks::async_di_container::MockAsyncDIContainer::new();
+
+ di_container_mock
+ .expect_set_binding::<dyn subjects_async::IUserManager>()
+ .withf(|name, _provider| name.is_none())
+ .return_once(|_name, _provider| ())
+ .once();
+
+ let binding_scope_configurator = AsyncBindingScopeConfigurator::<
+ dyn subjects_async::IUserManager,
+ subjects_async::UserManager,
+ mocks::async_di_container::MockAsyncDIContainer,
+ >::new(Arc::new(di_container_mock));
+
+ assert!(matches!(
+ binding_scope_configurator.in_singleton_scope().await,
+ Ok(_)
+ ));
+ }
+}