Esempio n. 1
0
        public void HostProviderRegistry_GetProvider_ProviderSpecified_ReturnsProvider()
        {
            var context = new TestCommandContext
            {
                Settings = { ProviderOverride = "provider3" }
            };
            var registry = new HostProviderRegistry(context);
            var input    = new InputArguments(new Dictionary <string, string>());

            var provider1Mock = new Mock <IHostProvider>();
            var provider2Mock = new Mock <IHostProvider>();
            var provider3Mock = new Mock <IHostProvider>();

            provider1Mock.Setup(x => x.Id).Returns("provider1");
            provider1Mock.Setup(x => x.IsSupported(It.IsAny <InputArguments>())).Returns(true);
            provider2Mock.Setup(x => x.Id).Returns("provider2");
            provider2Mock.Setup(x => x.IsSupported(It.IsAny <InputArguments>())).Returns(true);
            provider3Mock.Setup(x => x.Id).Returns("provider3");
            provider3Mock.Setup(x => x.IsSupported(It.IsAny <InputArguments>())).Returns(false);

            registry.Register(provider1Mock.Object, provider2Mock.Object, provider3Mock.Object);

            IHostProvider result = registry.GetProvider(input);

            Assert.Same(provider3Mock.Object, result);
        }
Esempio n. 2
0
        public void HostProviderRegistry_GetProvider_AutoLegacyAuthoritySpecified_ReturnsFirstSupportedProvider()
        {
            var context = new TestCommandContext
            {
                Settings = { LegacyAuthorityOverride = Constants.AuthorityIdAuto }
            };
            var registry = new HostProviderRegistry(context);
            var input    = new InputArguments(new Dictionary <string, string>());

            var provider1Mock = new Mock <IHostProvider>();
            var provider2Mock = new Mock <IHostProvider>();
            var provider3Mock = new Mock <IHostProvider>();

            provider1Mock.Setup(x => x.SupportedAuthorityIds).Returns(new[] { "authorityA" });
            provider1Mock.Setup(x => x.IsSupported(It.IsAny <InputArguments>())).Returns(false);
            provider2Mock.Setup(x => x.SupportedAuthorityIds).Returns(new[] { "authorityB", "authorityC" });
            provider2Mock.Setup(x => x.IsSupported(It.IsAny <InputArguments>())).Returns(true);
            provider3Mock.Setup(x => x.SupportedAuthorityIds).Returns(new[] { "authorityD" });
            provider3Mock.Setup(x => x.IsSupported(It.IsAny <InputArguments>())).Returns(false);

            registry.Register(provider1Mock.Object, provider2Mock.Object, provider3Mock.Object);

            IHostProvider result = registry.GetProvider(input);

            Assert.Same(provider2Mock.Object, result);
        }
Esempio n. 3
0
        public void HostProviderRegistry_GetProvider_NoProviders_ThrowException()
        {
            var context  = new TestCommandContext();
            var registry = new HostProviderRegistry(context);
            var input    = new InputArguments(new Dictionary <string, string>());

            Assert.Throws <Exception>(() => registry.GetProvider(input));
        }
Esempio n. 4
0
        public void HostProviderRegistry_GetProvider_Auto_MultipleValidProviders_ReturnsFirstRegistered()
        {
            var context  = new TestCommandContext();
            var registry = new HostProviderRegistry(context);
            var input    = new InputArguments(new Dictionary <string, string>());

            var provider1Mock = new Mock <IHostProvider>();
            var provider2Mock = new Mock <IHostProvider>();
            var provider3Mock = new Mock <IHostProvider>();

            provider1Mock.Setup(x => x.IsSupported(It.IsAny <InputArguments>())).Returns(true);
            provider2Mock.Setup(x => x.IsSupported(It.IsAny <InputArguments>())).Returns(true);
            provider3Mock.Setup(x => x.IsSupported(It.IsAny <InputArguments>())).Returns(true);

            registry.Register(provider1Mock.Object, provider2Mock.Object, provider3Mock.Object);

            IHostProvider result = registry.GetProvider(input);

            Assert.Same(provider1Mock.Object, result);
        }