public void GetService_returns_instance_of_contract_interface_only_when_key_predicate_matches() { var instance = new Mock <IPilkington>().Object; var resolver = new SingletonDependencyResolver <IPilkington>(instance, k => k != null && ((string)k).StartsWith("K")); Assert.Same(instance, resolver.GetService <IPilkington>("Karl")); Assert.Null(resolver.GetService <IPilkington>("Ricky")); Assert.Null(resolver.GetService <IPilkington>()); Assert.Null(resolver.GetService <IGervais>("Ricky")); }
public void GetService_can_be_accessed_from_multiple_threads_concurrently() { for (var i = 0; i < 30; i++) { var bag = new ConcurrentBag <IPilkington>(); var karl = new Mock <IPilkington>().Object; var resolver = new SingletonDependencyResolver <IPilkington>(karl, "Karl"); ExecuteInParallel(() => bag.Add(resolver.GetService <IPilkington>("Karl"))); Assert.Equal(20, bag.Count); Assert.True(bag.All(c => karl == c)); } }