public void ResolveHandleByComponentId_WhenComponentIdIsNull_Throws()
            {
                var registry       = new FakeRegistry();
                var serviceLocator = new RegistryServiceLocator(registry);

                Assert.Throws <ArgumentNullException>(() => serviceLocator.ResolveHandleByComponentId(null));
            }
        public void HttpProxy_Local_Parsing(string bypass, int count)
        {
            RemoteExecutor.Invoke((bypassValue, expected) =>
            {
                int expectedCount = Convert.ToInt32(expected);
                IWebProxy p;

                FakeRegistry.Reset();
                FakeRegistry.WinInetProxySettings.Proxy       = insecureProxyUri;
                FakeRegistry.WinInetProxySettings.ProxyBypass = bypassValue;

                Assert.True(HttpWindowsProxy.TryCreate(out p));
                Assert.NotNull(p);

                HttpWindowsProxy sp = p as HttpWindowsProxy;
                Assert.NotNull(sp);

                if (expectedCount > 0)
                {
                    Assert.Equal(expectedCount, sp.BypassList.Count);
                }
                else
                {
                    Assert.Null(sp.BypassList);
                }
            }, bypass, count.ToString()).Dispose();
        }
            public void ResolveAllHandles_WhenServiceTypeIsNull_Throws()
            {
                var registry       = new FakeRegistry();
                var serviceLocator = new RegistryServiceLocator(registry);

                Assert.Throws <ArgumentNullException>(() => serviceLocator.ResolveAllHandles(null));
            }
        public void HttpProxy_WindowsProxy_Manual_Loaded(string rawProxyString, string rawInsecureUri, string rawSecureUri)
        {
            RemoteExecutor.Invoke((proxyString, insecureProxy, secureProxy) =>
            {
                FakeRegistry.Reset();

                Assert.False(HttpWindowsProxy.TryCreate(out IWebProxy p));

                FakeRegistry.WinInetProxySettings.Proxy = proxyString;
                WinInetProxyHelper proxyHelper          = new WinInetProxyHelper();
                Assert.Null(proxyHelper.AutoConfigUrl);
                Assert.Equal(proxyString, proxyHelper.Proxy);
                Assert.False(proxyHelper.AutoSettingsUsed);
                Assert.True(proxyHelper.ManualSettingsUsed);

                Assert.True(HttpWindowsProxy.TryCreate(out p));
                Assert.NotNull(p);

                Assert.Equal(!string.IsNullOrEmpty(insecureProxy) ? new Uri(insecureProxy) : null, p.GetProxy(new Uri(fooHttp)));
                Assert.Equal(!string.IsNullOrEmpty(secureProxy) ? new Uri(secureProxy) : null, p.GetProxy(new Uri(fooHttps)));
                Assert.Equal(!string.IsNullOrEmpty(insecureProxy) ? new Uri(insecureProxy) : null, p.GetProxy(new Uri(fooWs)));
                Assert.Equal(!string.IsNullOrEmpty(secureProxy) ? new Uri(secureProxy) : null, p.GetProxy(new Uri(fooWss)));
                return(RemoteExecutor.SuccessExitCode);
            }, rawProxyString, rawInsecureUri ?? string.Empty, rawSecureUri ?? string.Empty).Dispose();
        }
Esempio n. 5
0
        public void HttpProxy_Local_Parsing(string bypass, int count)
        {
            RemoteInvoke((bypassValue, expected) =>
            {
                int expectedCount = Convert.ToInt32(expected);
                IWebProxy p;

                FakeRegistry.Reset();
                FakeRegistry.WinInetProxySettings.Proxy       = FakeProxyString;
                FakeRegistry.WinInetProxySettings.ProxyBypass = bypassValue;

                Assert.True(HttpSystemProxy.TryCreate(out p));
                Assert.NotNull(p);

                HttpSystemProxy sp = p as HttpSystemProxy;
                Assert.NotNull(sp);

                if (expectedCount > 0)
                {
                    Assert.Equal(expectedCount, sp.BypassList.Count);
                }
                else
                {
                    Assert.Null(sp.BypassList);
                }
                return(SuccessExitCode);
            }, bypass, count.ToString()).Dispose();
        }
            public void HasService_WhenServiceTypeIsNull_Throws()
            {
                var registry       = new FakeRegistry();
                var serviceLocator = new RegistryServiceLocator(registry);

                Assert.Throws <ArgumentNullException>(() => serviceLocator.HasService(null));
            }
            public void Resolve_WhenServiceTypeIsNull_Throws()
            {
                var registry = new FakeRegistry();
                var serviceLocator = new RegistryServiceLocator(registry);

                Assert.Throws<ArgumentNullException>(() => serviceLocator.Resolve(null));
            }
            public void HasComponent_WhenComponentIdIsNull_Throws()
            {
                var registry       = new FakeRegistry();
                var serviceLocator = new RegistryServiceLocator(registry);

                Assert.Throws <ArgumentNullException>(() => serviceLocator.HasComponent(null));
            }
            public void Resolve_WhenServiceTypeNotRegistered_Throws()
            {
                var registry = new FakeRegistry();
                var serviceLocator = new RegistryServiceLocator(registry);

                var ex = Assert.Throws<RuntimeException>(() => serviceLocator.Resolve(typeof(DummyService)));
                Assert.Contains(ex.Message, "Could not resolve component for service type '" + typeof(DummyService) + "' because there do not appear to be any components registered and enabled for that service type.");
            }
            public void HasComponent_WhenComponentNotRegistered_ReturnsFalse()
            {
                var registry       = new FakeRegistry();
                var serviceLocator = new RegistryServiceLocator(registry);

                var result = serviceLocator.HasComponent("componentId");

                Assert.IsFalse(result);
            }
            public void ResolveAllHandles_WhenServiceTypeNotRegistered_ReturnsAnEmptyList()
            {
                var registry       = new FakeRegistry();
                var serviceLocator = new RegistryServiceLocator(registry);

                var result = serviceLocator.ResolveAllHandles(typeof(DummyService));

                Assert.IsEmpty(result);
            }
        public void Execute_should_run_a_RegistryWriteIntValueCommand()
        {
            var registry = new FakeRegistry();
            var executor = new CommandExecutor(new NullLogger(), registry);

            executor.Execute(new RegistryWriteIntValueCommand(RegistryBaseKey.CurrentUser, "SubKey", "IntValue", 123))
            .Should()
            .BeEquivalentTo(ServiceCommandResponse.Create(ServiceCommandName.RegistryWriteIntValue, 123));
        }
            public void ResolveAllHandlesGeneric_WhenServiceTypeNotRegistered_ReturnsAnEmptyList()
            {
                var registry       = new FakeRegistry();
                var serviceLocator = new RegistryServiceLocator(registry);

                var result = serviceLocator.ResolveAllHandles <DummyService, DummyTraits>();

                Assert.IsEmpty(result);
            }
            public void Resolve_WhenServiceTypeNotRegistered_Throws()
            {
                var registry       = new FakeRegistry();
                var serviceLocator = new RegistryServiceLocator(registry);

                var ex = Assert.Throws <RuntimeException>(() => serviceLocator.Resolve(typeof(DummyService)));

                Assert.Contains(ex.Message, "Could not resolve component for service type '" + typeof(DummyService) + "' because there do not appear to be any components registered and enabled for that service type.");
            }
            public void HasService_WhenServiceTypeNotRegistered_ReturnsFalse()
            {
                var registry       = new FakeRegistry();
                var serviceLocator = new RegistryServiceLocator(registry);

                var result = serviceLocator.HasService(typeof(DummyService));

                Assert.IsFalse(result);
            }
            public void ResolveHandleByComponentId_WhenComponentNotRegistered_Throws()
            {
                var registry       = new FakeRegistry();
                var serviceLocator = new RegistryServiceLocator(registry);

                var ex = Assert.Throws <RuntimeException>(() => serviceLocator.ResolveHandleByComponentId("componentId"));

                Assert.Contains(ex.Message, "Could not resolve component with id 'componentId' because it does not appear to be registered.");
            }
        public void Execute_should_run_a_RegistryWriteStringValueCommand()
        {
            var registry = new FakeRegistry(@"HKCU\SubKey\StringValue=""Here""");
            var executor = new CommandExecutor(new NullLogger(), registry);

            executor.Execute(
                new RegistryReadStringValueCommand(RegistryBaseKey.CurrentUser, "SubKey", "StringValue", null))
            .Should()
            .BeEquivalentTo(ServiceCommandResponse.Create(ServiceCommandName.RegistryReadStringValue, "Here"));
        }
Esempio n. 18
0
		public void SaveRecord()
		{
			var f = new FakeRegistry();
			var r = new FakeRecord();

			f.Add(r);
			var r2 = f.GetCurrentRecord(r.Identifier);

			Assert.NotNull(r2);
			Assert.AreEqual(r2.Identifier, r.Identifier);
		}
            public void ResolveHandleGeneric_WhenServiceTypeMapsToExactlyOneComponent_ReturnsComponentHandle()
            {
                var registry            = new FakeRegistry();
                var serviceLocator      = new RegistryServiceLocator(registry);
                var serviceDescriptor   = registry.RegisterService(typeof(DummyService));
                var componentDescriptor = registry.RegisterComponent(serviceDescriptor, "componentId", typeof(DummyComponent));

                var componentHandle = serviceLocator.ResolveHandle <DummyService, DummyTraits>();

                Assert.AreSame(componentDescriptor, componentHandle.Descriptor);
            }
            public void ResolveHandleByComponentId_WhenComponentRegistered_ReturnsComponentHandle()
            {
                var registry            = new FakeRegistry();
                var serviceLocator      = new RegistryServiceLocator(registry);
                var serviceDescriptor   = registry.RegisterService(typeof(DummyService));
                var componentDescriptor = registry.RegisterComponent(serviceDescriptor, "componentId", typeof(DummyComponent));

                var componentHandle = serviceLocator.ResolveHandleByComponentId("componentId");

                Assert.AreSame(componentDescriptor, componentHandle.Descriptor);
            }
            public void ResolveAllHandlesGeneric_WhenServiceTypeRegisteredButNoComponents_ReturnsAnEmptyList()
            {
                var registry       = new FakeRegistry();
                var serviceLocator = new RegistryServiceLocator(registry);

                registry.RegisterService(typeof(DummyService));

                var result = serviceLocator.ResolveAllHandles <DummyService, DummyTraits>();

                Assert.IsEmpty(result);
            }
Esempio n. 22
0
        public void ExecuteRead_should_return_the_read_value()
        {
            var registry = new FakeRegistry(@"HKCU\SubKey\IntValue=123");
            var executor = new RegistryCommandExecutor(registry);
            IServiceCommandResponse response = executor.ExecuteRead(
                new RegistryReadIntValueCommand(RegistryBaseKey.CurrentUser, "SubKey", "IntValue", 0),
                new NullLogger());

            response.IsSuccess.Should().BeTrue();
            response.Result.Should().Be(123);
        }
Esempio n. 23
0
        public void ExecuteWrite_should_return_the_value()
        {
            var registry = new FakeRegistry(@"HKLM\SubKey");
            var executor = new RegistryCommandExecutor(registry);
            IServiceCommandResponse response = executor.ExecuteWrite(
                new RegistryWriteIntValueCommand(RegistryBaseKey.LocalMachine, "SubKey", "IntValue", 123),
                new NullLogger());

            response.IsSuccess.Should().BeTrue();
            response.Result.Should().Be(123);
        }
            public void Resolve_WhenServiceTypeRegisteredButMoreThanOneComponent_Throws()
            {
                var registry = new FakeRegistry();
                var serviceLocator = new RegistryServiceLocator(registry);
                var serviceDescriptor = registry.RegisterService(typeof(DummyService));
                registry.RegisterComponent(serviceDescriptor, "component1Id", typeof(DummyComponent));
                registry.RegisterComponent(serviceDescriptor, "component2Id", typeof(DummyComponent2));

                var ex = Assert.Throws<RuntimeException>(() => serviceLocator.Resolve(typeof(DummyService)));
                Assert.Contains(ex.Message, "Could not resolve component for service type '" + typeof(DummyService) + "' because there are more than one of them registered and enabled so the request is ambiguous.");
            }
            public void ResolveHandleGeneric_WhenServiceTypeMapsToExactlyOneComponentButItIsDisabled_Throws()
            {
                var registry          = new FakeRegistry();
                var serviceLocator    = new RegistryServiceLocator(registry);
                var serviceDescriptor = registry.RegisterService(typeof(DummyService));

                registry.RegisterDisabledComponent(serviceDescriptor, "componentId", typeof(DummyComponent));

                var ex = Assert.Throws <RuntimeException>(() => serviceLocator.ResolveHandle <DummyService, DummyTraits>());

                Assert.Contains(ex.Message, "Could not resolve component for service type '" + typeof(DummyService) + "' because there do not appear to be any components registered and enabled for that service type.");
            }
            public void ResolveByComponentId_WhenComponentRegistered_ReturnsResolvedComponent()
            {
                var registry          = new FakeRegistry();
                var serviceLocator    = new RegistryServiceLocator(registry);
                var serviceDescriptor = registry.RegisterService(typeof(DummyService));

                registry.RegisterComponent(serviceDescriptor, "componentId", typeof(DummyComponent));

                var component = (DummyComponent)serviceLocator.ResolveByComponentId("componentId");

                Assert.IsNotNull(component);
            }
            public void ResolveHandleByComponentId_WhenComponentRegisteredButItIsDisabled_ReturnsComponentHandle()
            {
                var registry          = new FakeRegistry();
                var serviceLocator    = new RegistryServiceLocator(registry);
                var serviceDescriptor = registry.RegisterService(typeof(DummyService));

                registry.RegisterDisabledComponent(serviceDescriptor, "componentId", typeof(DummyComponent));

                var ex = Assert.Throws <RuntimeException>(() => serviceLocator.ResolveHandleByComponentId("componentId"));

                Assert.Contains(ex.Message, "Could not resolve component with id 'componentId' because it has been disabled.  Reason: ");
            }
            public void Resolve_WhenServiceTypeMapsToExactlyOneComponent_ReturnsResolvedComponent()
            {
                var registry          = new FakeRegistry();
                var serviceLocator    = new RegistryServiceLocator(registry);
                var serviceDescriptor = registry.RegisterService(typeof(DummyService));

                registry.RegisterComponent(serviceDescriptor, "componentId", typeof(DummyComponent));

                var component = (DummyComponent)serviceLocator.Resolve(typeof(DummyService));

                Assert.IsNotNull(component);
            }
            public void HasComponent_WhenComponentRegisteredButDisabled_ReturnsFalse()
            {
                var registry       = new FakeRegistry();
                var serviceLocator = new RegistryServiceLocator(registry);
                var service        = registry.RegisterService(typeof(DummyService));

                registry.RegisterDisabledComponent(service, "componentId", typeof(DummyComponent2));

                var result = serviceLocator.HasComponent("componentId");

                Assert.IsFalse(result);
            }
            public void Resolve_WhenServiceTypeRegisteredButMoreThanOneComponent_Throws()
            {
                var registry          = new FakeRegistry();
                var serviceLocator    = new RegistryServiceLocator(registry);
                var serviceDescriptor = registry.RegisterService(typeof(DummyService));

                registry.RegisterComponent(serviceDescriptor, "component1Id", typeof(DummyComponent));
                registry.RegisterComponent(serviceDescriptor, "component2Id", typeof(DummyComponent2));

                var ex = Assert.Throws <RuntimeException>(() => serviceLocator.Resolve(typeof(DummyService)));

                Assert.Contains(ex.Message, "Could not resolve component for service type '" + typeof(DummyService) + "' because there are more than one of them registered and enabled so the request is ambiguous.");
            }
Esempio n. 31
0
        public void HttpProxy_SystemProxy_Loaded()
        {
            IWebProxy p;

            FakeRegistry.Reset();
            Assert.False(HttpSystemProxy.TryCreate(out p));

            FakeRegistry.WinInetProxySettings.Proxy = FakeProxyString;

            Assert.True(HttpSystemProxy.TryCreate(out p));
            Assert.NotNull(p);
            Assert.Equal(fakeProxyUri, p.GetProxy(fooHttp));
            Assert.Equal(fakeProxyUri, p.GetProxy(fooHttps));
        }
            public void ResolveAllHandlesGeneric_WhenServiceTypeRegisteredAndAtLeastOneComponent_ReturnsAllComponentHandles()
            {
                var registry             = new FakeRegistry();
                var serviceLocator       = new RegistryServiceLocator(registry);
                var serviceDescriptor    = registry.RegisterService(typeof(DummyService));
                var component1Descriptor = registry.RegisterComponent(serviceDescriptor, "component1Id", typeof(DummyComponent));
                var component2Descriptor = registry.RegisterComponent(serviceDescriptor, "component2Id", typeof(DummyComponent2));

                var result = serviceLocator.ResolveAllHandles <DummyService, DummyTraits>();

                Assert.Count(2, result);
                Assert.AreSame(component1Descriptor, result[0].Descriptor);
                Assert.AreSame(component2Descriptor, result[1].Descriptor);
            }
            public void ResolveAllGeneric_WhenServiceTypeRegisteredAndAtLeastOneComponent_ReturnsAllResolvedComponents()
            {
                var registry          = new FakeRegistry();
                var serviceLocator    = new RegistryServiceLocator(registry);
                var serviceDescriptor = registry.RegisterService(typeof(DummyService));

                registry.RegisterComponent(serviceDescriptor, "component1Id", typeof(DummyComponent));
                registry.RegisterComponent(serviceDescriptor, "component2Id", typeof(DummyComponent2));

                var result = serviceLocator.ResolveAll <DummyService>();

                Assert.Count(2, result);
                Assert.IsInstanceOfType <DummyComponent>(result[0]);
                Assert.IsInstanceOfType <DummyComponent2>(result[1]);
            }
Esempio n. 34
0
        public void RegisterSingle_WithFactory()
        {
            var registry = new FakeRegistry();

            Func <TestImplementation1> instanceFactory = () => new TestImplementation1();

            registry.RegisterSingle <ITestType> (instanceFactory);

            Assert.That(registry.ServiceConfigurationEntry.ServiceType, Is.EqualTo(typeof(ITestType)));
            Assert.That(registry.ServiceConfigurationEntry.ImplementationInfos.Count, Is.EqualTo(1));
            Assert.That(registry.ServiceConfigurationEntry.ImplementationInfos[0].ImplementationType, Is.EqualTo(typeof(ITestType)));
            Assert.That(registry.ServiceConfigurationEntry.ImplementationInfos[0].Factory, Is.SameAs(instanceFactory));
            Assert.That(registry.ServiceConfigurationEntry.ImplementationInfos[0].Lifetime, Is.EqualTo(LifetimeKind.InstancePerDependency));
            Assert.That(registry.ServiceConfigurationEntry.ImplementationInfos[0].RegistrationType, Is.EqualTo(RegistrationType.Single));
        }
            public void Resolve_WhenServiceTypeMapsToExactlyOneComponent_ReturnsResolvedComponent()
            {
                var registry = new FakeRegistry();
                var serviceLocator = new RegistryServiceLocator(registry);
                var serviceDescriptor = registry.RegisterService(typeof(DummyService));
                registry.RegisterComponent(serviceDescriptor, "componentId", typeof(DummyComponent));

                var component = (DummyComponent)serviceLocator.Resolve(typeof(DummyService));

                Assert.IsNotNull(component);
            }
            public void ResolveHandleGeneric_WhenServiceTypeMapsToExactlyOneComponent_ReturnsComponentHandle()
            {
                var registry = new FakeRegistry();
                var serviceLocator = new RegistryServiceLocator(registry);
                var serviceDescriptor = registry.RegisterService(typeof(DummyService));
                var componentDescriptor = registry.RegisterComponent(serviceDescriptor, "componentId", typeof(DummyComponent));

                var componentHandle = serviceLocator.ResolveHandle<DummyService, DummyTraits>();

                Assert.AreSame(componentDescriptor, componentHandle.Descriptor);
            }
            public void HasComponent_WhenComponentRegisteredButDisabled_ReturnsFalse()
            {
                var registry = new FakeRegistry();
                var serviceLocator = new RegistryServiceLocator(registry);
                var service = registry.RegisterService(typeof(DummyService));
                registry.RegisterDisabledComponent(service, "componentId", typeof(DummyComponent2));

                var result = serviceLocator.HasComponent("componentId");

                Assert.IsFalse(result);
            }
            public void HasComponent_WhenComponentNotRegistered_ReturnsFalse()
            {
                var registry = new FakeRegistry();
                var serviceLocator = new RegistryServiceLocator(registry);

                var result = serviceLocator.HasComponent("componentId");

                Assert.IsFalse(result);
            }
            public void HasComponent_WhenComponentIdIsNull_Throws()
            {
                var registry = new FakeRegistry();
                var serviceLocator = new RegistryServiceLocator(registry);

                Assert.Throws<ArgumentNullException>(() => serviceLocator.HasComponent(null));
            }
            public void ResolveHandleByComponentId_WhenComponentRegisteredButItIsDisabled_ReturnsComponentHandle()
            {
                var registry = new FakeRegistry();
                var serviceLocator = new RegistryServiceLocator(registry);
                var serviceDescriptor = registry.RegisterService(typeof(DummyService));
                registry.RegisterDisabledComponent(serviceDescriptor, "componentId", typeof(DummyComponent));

                var ex = Assert.Throws<RuntimeException>(() => serviceLocator.ResolveHandleByComponentId("componentId"));
                Assert.Contains(ex.Message, "Could not resolve component with id 'componentId' because it has been disabled.  Reason: ");
            }
            public void ResolveAllHandles_WhenServiceTypeNotRegistered_ReturnsAnEmptyList()
            {
                var registry = new FakeRegistry();
                var serviceLocator = new RegistryServiceLocator(registry);

                var result = serviceLocator.ResolveAllHandles(typeof(DummyService));

                Assert.IsEmpty(result);
            }
            public void ResolveHandleByComponentId_WhenComponentIdIsNull_Throws()
            {
                var registry = new FakeRegistry();
                var serviceLocator = new RegistryServiceLocator(registry);

                Assert.Throws<ArgumentNullException>(() => serviceLocator.ResolveHandleByComponentId(null));
            }
            public void ResolveAllHandlesGeneric_WhenServiceTypeRegisteredAndAtLeastOneComponent_ReturnsAllComponentHandles()
            {
                var registry = new FakeRegistry();
                var serviceLocator = new RegistryServiceLocator(registry);
                var serviceDescriptor = registry.RegisterService(typeof(DummyService));
                var component1Descriptor = registry.RegisterComponent(serviceDescriptor, "component1Id", typeof(DummyComponent));
                var component2Descriptor = registry.RegisterComponent(serviceDescriptor, "component2Id", typeof(DummyComponent2));

                var result = serviceLocator.ResolveAllHandles<DummyService, DummyTraits>();

                Assert.Count(2, result);
                Assert.AreSame(component1Descriptor, result[0].Descriptor);
                Assert.AreSame(component2Descriptor, result[1].Descriptor);
            }
            public void ResolveAllHandlesGeneric_WhenServiceTypeRegisteredButNoComponents_ReturnsAnEmptyList()
            {
                var registry = new FakeRegistry();
                var serviceLocator = new RegistryServiceLocator(registry);
                registry.RegisterService(typeof(DummyService));

                var result = serviceLocator.ResolveAllHandles<DummyService, DummyTraits>();

                Assert.IsEmpty(result);
            }
Esempio n. 45
0
		public void Setup()
		{
			var container = new WindsorContainer();
			var processor = new FakeMessageProcessor();
			container.Register(Component.For<FakeMessageProcessor>().Instance(processor));

			container.Register(
				Component.For<IPublicationRegistry<IPublicationRecord, IPublicationRecord>>().ImplementedBy<FakeRegistry>());
			container.Register(
				Component.For<IRecordMapper<FakePublicationRecord>>().ImplementedBy<InMemoryRecordMapper<FakePublicationRecord>>());
			container.Register(Component.For<IBlobStorage>().ImplementedBy<InMemoryBlobStorage>());
			container.Register(Component.For<IMessageSerializer>().ImplementedBy<JsonMessageSerializer>());

			container.Register(Component.For<FakeMessageProcessor2>().Instance(new FakeMessageProcessor2()));
			container.Register(Component.For<FakeMultipleMessageProcessor>().Instance(new FakeMultipleMessageProcessor()));

			_registry = new FakeRegistry(
				new InMemoryRecordMapper<FakePublicationRecord>(), new InMemoryBlobStorage(), new JsonMessageSerializer());

			var locator = new WindsorServiceLocator(container);

			_dispatcher = new MultitaskingMessageDispatcher<IPublicationRegistry<IPublicationRecord, IPublicationRecord>>(
				locator, _registry);

			_transport = new InMemoryMessageChannel();
		}
            public void ResolveHandleGeneric_WhenServiceTypeMapsToExactlyOneComponentButItIsDisabled_Throws()
            {
                var registry = new FakeRegistry();
                var serviceLocator = new RegistryServiceLocator(registry);
                var serviceDescriptor = registry.RegisterService(typeof(DummyService));
                registry.RegisterDisabledComponent(serviceDescriptor, "componentId", typeof(DummyComponent));

                var ex = Assert.Throws<RuntimeException>(() => serviceLocator.ResolveHandle<DummyService, DummyTraits>());
                Assert.Contains(ex.Message, "Could not resolve component for service type '" + typeof(DummyService) + "' because there do not appear to be any components registered and enabled for that service type.");
            }
            public void ResolveByComponentId_WhenComponentRegistered_ReturnsResolvedComponent()
            {
                var registry = new FakeRegistry();
                var serviceLocator = new RegistryServiceLocator(registry);
                var serviceDescriptor = registry.RegisterService(typeof(DummyService));
                registry.RegisterComponent(serviceDescriptor, "componentId", typeof(DummyComponent));

                var component = (DummyComponent)serviceLocator.ResolveByComponentId("componentId");

                Assert.IsNotNull(component);
            }
            public void HasService_WhenServiceTypeRegisteredButDisabled_ReturnsFalse()
            {
                var registry = new FakeRegistry();
                var serviceLocator = new RegistryServiceLocator(registry);
                registry.RegisterDisabledService(typeof(DummyService));

                var result = serviceLocator.HasService(typeof(DummyService));

                Assert.IsFalse(result);
            }
            public void ResolveHandleByComponentId_WhenComponentNotRegistered_Throws()
            {
                var registry = new FakeRegistry();
                var serviceLocator = new RegistryServiceLocator(registry);

                var ex = Assert.Throws<RuntimeException>(() => serviceLocator.ResolveHandleByComponentId("componentId"));
                Assert.Contains(ex.Message, "Could not resolve component with id 'componentId' because it does not appear to be registered.");
            }
            public void ResolveAllHandlesGeneric_WhenServiceTypeNotRegistered_ReturnsAnEmptyList()
            {
                var registry = new FakeRegistry();
                var serviceLocator = new RegistryServiceLocator(registry);

                var result = serviceLocator.ResolveAllHandles<DummyService, DummyTraits>();

                Assert.IsEmpty(result);
            }
            public void ResolveAllGeneric_WhenServiceTypeRegisteredAndAtLeastOneComponent_ReturnsAllResolvedComponents()
            {
                var registry = new FakeRegistry();
                var serviceLocator = new RegistryServiceLocator(registry);
                var serviceDescriptor = registry.RegisterService(typeof(DummyService));
                registry.RegisterComponent(serviceDescriptor, "component1Id", typeof(DummyComponent));
                registry.RegisterComponent(serviceDescriptor, "component2Id", typeof(DummyComponent2));

                var result = serviceLocator.ResolveAll<DummyService>();

                Assert.Count(2, result);
                Assert.IsInstanceOfType<DummyComponent>(result[0]);
                Assert.IsInstanceOfType<DummyComponent2>(result[1]);
            }
            public void ResolveHandleByComponentId_WhenComponentRegistered_ReturnsComponentHandle()
            {
                var registry = new FakeRegistry();
                var serviceLocator = new RegistryServiceLocator(registry);
                var serviceDescriptor = registry.RegisterService(typeof(DummyService));
                var componentDescriptor = registry.RegisterComponent(serviceDescriptor, "componentId", typeof(DummyComponent));

                var componentHandle = serviceLocator.ResolveHandleByComponentId("componentId");

                Assert.AreSame(componentDescriptor, componentHandle.Descriptor);
            }