Esempio n. 1
0
        public bool ContainsKey(object key)
        {
            // Arrange
            IKeyedServiceRegister register = GetRegistrar();

            // Act
            // Assert
            return(register.Contains <IMyService>(key));
        }
Esempio n. 2
0
        public void LookUp_DoesNotExist()
        {
            // Arrange
            IKeyedServiceRegister register = GetRegistrar();

            // Act
            var types = register.LookUp <IAsyncResult>();

            // Assert
            Assert.That(types, Is.Empty);
        }
Esempio n. 3
0
        public void LookUp_Key_Exists()
        {
            // Arrange
            IKeyedServiceRegister register = GetRegistrar();

            // Act
            Type t = register.LookUp <IMyService>(AvailableServices.Service1);

            // Assert
            Assert.That(t, Is.EqualTo(typeof(MyService1)));
        }
Esempio n. 4
0
        public void Contains_False()
        {
            // Arrange
            IKeyedServiceRegister register = GetRegistrar();

            // Act
            bool contains = register.Contains <IAsyncResult>();

            // Assert
            Assert.That(contains, Is.False);
        }
Esempio n. 5
0
        public void LookUp_Key_DoesNotExist()
        {
            // Arrange
            IKeyedServiceRegister register = GetRegistrar();

            // Act
            Type t = register.LookUp <IMyService>("DOES_NOT_EXIST");

            // Assert
            Assert.That(t, Is.Null);
        }
Esempio n. 6
0
        public void Contains_True()
        {
            // Arrange
            IKeyedServiceRegister register = GetRegistrar();

            // Act
            bool contains = register.Contains <IMyService>();

            // Assert
            Assert.That(contains, Is.True);
        }
Esempio n. 7
0
        public void GetKeys_Typed_Enum()
        {
            // Arrange
            IKeyedServiceRegister register = GetRegistrar();

            // Act
            var types = register.GetKeys <IMyService, AvailableServices>().ToList();

            // Assert
            Assert.That(types, Has.Count.EqualTo(2));
            Assert.That(types, Contains.Item(AvailableServices.Service1));
            Assert.That(types, Contains.Item(AvailableServices.Service2));
        }
Esempio n. 8
0
        public void LookUp_Exists()
        {
            // Arrange
            IKeyedServiceRegister register = GetRegistrar();

            // Act
            var types = register.LookUp <IMyService>().ToList();

            // Assert
            Assert.That(types, Has.Count.EqualTo(2));
            Assert.That(types, Contains.Item(typeof(MyService1)));
            Assert.That(types, Contains.Item(typeof(MyService2)));
        }
Esempio n. 9
0
        public void GetKeys_Typed_String()
        {
            // Arrange
            IKeyedServiceRegister register = GetRegistrar();

            // Act
            var types = register.GetKeys <IMyService, string>().ToList();

            // Assert
            Assert.That(types, Has.Count.EqualTo(2));
            Assert.That(types, Contains.Item("Service1"));
            Assert.That(types, Contains.Item("Service2"));
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="KeyedServiceFactory"/> class.
 /// </summary>
 /// <param name="registrar">The registrar.</param>
 /// <param name="services">The services.</param>
 public KeyedServiceFactory([NotNull] IKeyedServiceRegister registrar, [NotNull] IServiceProvider services)
 {
     _registrar = registrar ?? throw new ArgumentNullException(nameof(registrar));
     _services  = services ?? throw new ArgumentNullException(nameof(services));
 }
 public static bool Contains <TInterface>(this IKeyedServiceRegister register)
 {
     return(register.Contains(typeof(TInterface)));
 }
 public static IEnumerable <TKey> GetKeys <TInterface, TKey>(this IKeyedServiceRegister register)
 {
     return(register.GetKeys(typeof(TInterface)).OfType <TKey>());
 }
 public static IEnumerable <object> GetKeys <TInterface>(this IKeyedServiceRegister register)
 {
     return(register.GetKeys(typeof(TInterface)));
 }
 public static IEnumerable <Type> LookUp <TInterface>(this IKeyedServiceRegister register)
 {
     return(register.LookUp(typeof(TInterface)).Distinct());
 }
 public static Type LookUp <TInterface>(this IKeyedServiceRegister register, object key)
 {
     return(register.LookUp(typeof(TInterface), key));
 }