public void RegisterExtension_RegisterMultipleInstances()
        {
            DefaultExtensionRegistry registry = new DefaultExtensionRegistry();

            ServiceA serviceA = new ServiceA();
            ServiceB serviceB = new ServiceB();
            ServiceC serviceC = new ServiceC();

            registry.RegisterExtension(typeof(IMyService), serviceA);
            registry.RegisterExtension(typeof(IMyService), serviceB);
            registry.RegisterExtension(typeof(IMyService), serviceC);

            OtherServiceA otherServiceA = new OtherServiceA();
            OtherServiceB otherServiceB = new OtherServiceB();

            registry.RegisterExtension(typeof(IMyOtherService), otherServiceA);
            registry.RegisterExtension(typeof(IMyOtherService), otherServiceB);

            object[] services = registry.GetExtensions(typeof(IMyService)).ToArray();
            Assert.Equal(3, services.Length);
            Assert.True(services.Contains(serviceA));
            Assert.True(services.Contains(serviceB));
            Assert.True(services.Contains(serviceC));

            services = registry.GetExtensions(typeof(IMyOtherService)).ToArray();
            Assert.Equal(2, services.Length);
            Assert.True(services.Contains(otherServiceA));
            Assert.True(services.Contains(otherServiceB));
        }
        public void RegisterExtension_RegisterMultipleInstances()
        {
            DefaultExtensionRegistry registry = new DefaultExtensionRegistry();

            ServiceA serviceA = new ServiceA();
            ServiceB serviceB = new ServiceB();
            ServiceC serviceC = new ServiceC();
            registry.RegisterExtension(typeof(IMyService), serviceA);
            registry.RegisterExtension(typeof(IMyService), serviceB);
            registry.RegisterExtension(typeof(IMyService), serviceC);

            OtherServiceA otherServiceA = new OtherServiceA();
            OtherServiceB otherServiceB = new OtherServiceB();
            registry.RegisterExtension(typeof(IMyOtherService), otherServiceA);
            registry.RegisterExtension(typeof(IMyOtherService), otherServiceB);

            object[] services = registry.GetExtensions(typeof(IMyService)).ToArray();
            Assert.Equal(3, services.Length);
            Assert.True(services.Contains(serviceA));
            Assert.True(services.Contains(serviceB));
            Assert.True(services.Contains(serviceC));

            services = registry.GetExtensions(typeof(IMyOtherService)).ToArray();
            Assert.Equal(2, services.Length);
            Assert.True(services.Contains(otherServiceA));
            Assert.True(services.Contains(otherServiceB));
        }
        public void GetExtensions_ReturnsEmptyCollection_WhenServiceTypeNotFound()
        {
            DefaultExtensionRegistry registry = new DefaultExtensionRegistry();

            object[] services = registry.GetExtensions(typeof(IConvertible)).ToArray();
            Assert.Equal(0, services.Length);
        }
 public void GetExtensions_ThrowsArgumentNull_WhenTypeIsNull()
 {
     DefaultExtensionRegistry registry = new DefaultExtensionRegistry();
     ArgumentNullException exception = Assert.Throws<ArgumentNullException>(
         () => registry.GetExtensions(null)
     );
     Assert.Equal("type", exception.ParamName);
 }
        public void GetExtensions_ThrowsArgumentNull_WhenTypeIsNull()
        {
            DefaultExtensionRegistry registry  = new DefaultExtensionRegistry();
            ArgumentNullException    exception = Assert.Throws <ArgumentNullException>(
                () => registry.GetExtensions(null)
                );

            Assert.Equal("type", exception.ParamName);
        }
        public void IExtensionRegistryExtensions_RegisterAndRetrieve()
        {
            DefaultExtensionRegistry registry = new DefaultExtensionRegistry();

            // use the generic extension methods to register
            ServiceA serviceA = new ServiceA();
            ServiceB serviceB = new ServiceB();
            ServiceC serviceC = new ServiceC();

            registry.RegisterExtension <IMyService>(serviceA);
            registry.RegisterExtension <IMyService>(serviceB);
            registry.RegisterExtension <IMyService>(serviceC);

            IMyService[] services = registry.GetExtensions <IMyService>().ToArray();
            Assert.Equal(3, services.Length);
            Assert.True(services.Contains(serviceA));
            Assert.True(services.Contains(serviceB));
            Assert.True(services.Contains(serviceC));
        }
        public void IExtensionRegistryExtensions_RegisterAndRetrieve()
        {
            DefaultExtensionRegistry registry = new DefaultExtensionRegistry();

            // use the generic extension methods to register
            ServiceA serviceA = new ServiceA();
            ServiceB serviceB = new ServiceB();
            ServiceC serviceC = new ServiceC();
            registry.RegisterExtension<IMyService>(serviceA);
            registry.RegisterExtension<IMyService>(serviceB);
            registry.RegisterExtension<IMyService>(serviceC);

            IMyService[] services = registry.GetExtensions<IMyService>().ToArray();
            Assert.Equal(3, services.Length);
            Assert.True(services.Contains(serviceA));
            Assert.True(services.Contains(serviceB));
            Assert.True(services.Contains(serviceC));
        }
        public void GetExtensions_ReturnsEmptyCollection_WhenServiceTypeNotFound()
        {
            DefaultExtensionRegistry registry = new DefaultExtensionRegistry();

            object[] services = registry.GetExtensions(typeof(IConvertible)).ToArray();
            Assert.Equal(0, services.Length);
        }