aboutsummaryrefslogtreecommitdiff
path: root/src/di_container/blocking/binding/scope_configurator.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/di_container/blocking/binding/scope_configurator.rs')
-rw-r--r--src/di_container/blocking/binding/scope_configurator.rs50
1 files changed, 50 insertions, 0 deletions
diff --git a/src/di_container/blocking/binding/scope_configurator.rs b/src/di_container/blocking/binding/scope_configurator.rs
index 5553415..dc33cbc 100644
--- a/src/di_container/blocking/binding/scope_configurator.rs
+++ b/src/di_container/blocking/binding/scope_configurator.rs
@@ -79,3 +79,53 @@ where
Ok(BindingWhenConfigurator::new(self.di_container.clone()))
}
}
+
+#[cfg(test)]
+mod tests
+{
+ use super::*;
+ use crate::test_utils::{mocks, subjects};
+
+ #[test]
+ fn in_transient_scope_works()
+ {
+ let mut di_container_mock = mocks::blocking_di_container::MockDIContainer::new();
+
+ di_container_mock
+ .expect_set_binding::<dyn subjects::IUserManager>()
+ .withf(|name, _provider| name.is_none())
+ .return_once(|_name, _provider| ())
+ .once();
+
+ let binding_scope_configurator = BindingScopeConfigurator::<
+ dyn subjects::IUserManager,
+ subjects::UserManager,
+ mocks::blocking_di_container::MockDIContainer,
+ >::new(Rc::new(di_container_mock));
+
+ binding_scope_configurator.in_transient_scope();
+ }
+
+ #[test]
+ fn in_singleton_scope_works()
+ {
+ let mut di_container_mock = mocks::blocking_di_container::MockDIContainer::new();
+
+ di_container_mock
+ .expect_set_binding::<dyn subjects::IUserManager>()
+ .withf(|name, _provider| name.is_none())
+ .return_once(|_name, _provider| ())
+ .once();
+
+ let binding_scope_configurator = BindingScopeConfigurator::<
+ dyn subjects::IUserManager,
+ subjects::UserManager,
+ mocks::blocking_di_container::MockDIContainer,
+ >::new(Rc::new(di_container_mock));
+
+ assert!(matches!(
+ binding_scope_configurator.in_singleton_scope(),
+ Ok(_)
+ ));
+ }
+}