Beispiel #1
0
        public void when_getting_missing_service_then_throws()
        {
            var container = new CompositionContainer();
            var locator   = new ServiceLocatorImpl(Mock.Of <IServiceProvider>(), new Lazy <ExportProvider>(() => container));

            Assert.Throws <MissingDependencyException>(() => locator.GetService(typeof(Foo)));
        }
Beispiel #2
0
        public TestContainer(ComposablePartCatalog catalog, IServiceProvider services = null)
            : base(catalog)
        {
            var provider = new ServiceLocatorImpl(services ?? Mock.Of <IServiceProvider>(), new Lazy <ExportProvider>(() => this));

            this.ComposeExportedValue <IServiceLocator>(provider);
            this.ComposeExportedValue <IServiceProvider>(provider);
        }
Beispiel #3
0
		public void when_getting_exports_then_succeeds ()
		{
			var container = new CompositionContainer(new TypeCatalog(typeof(Foo)));
			var locator = new ServiceLocatorImpl(Mock.Of<IServiceProvider>(), new Lazy<ExportProvider>(() => container));

			var foo = locator.GetExports(typeof(Foo)).FirstOrDefault();

			Assert.NotNull (foo);
		}
        public void when_getting_typed_exports_then_succeeds()
        {
            var container = new CompositionContainer(new TypeCatalog(typeof(Foo)));
            var locator   = new ServiceLocatorImpl(Mock.Of <IServiceProvider>(), new Lazy <ExportProvider>(() => container));

            var foo = locator.GetExports <Foo>().FirstOrDefault();

            Assert.NotNull(foo);
        }
Beispiel #5
0
        public void when_getting_missing_exports_then_returns_empty()
        {
            var container = new CompositionContainer();
            var locator   = new ServiceLocatorImpl(Mock.Of <IServiceProvider>(), new Lazy <ExportProvider>(() => container));

            var instances = locator.GetExports(typeof(Foo)).ToList();

            Assert.Empty(instances);
        }
        public void when_retrieving_service_then_invokes_service_provider()
        {
            var locator = new ServiceLocatorImpl(
                Mock.Of <IServiceProvider>(x => x.GetService(typeof(Foo)) == new Foo()),
                new Lazy <ExportProvider>(() => Mock.Of <ExportProvider>()));

            var foo = locator.GetService(typeof(Foo));

            Assert.NotNull(foo);
        }
        public void when_getting_typed_exports_with_metadata_dictionary_then_succeeds()
        {
            var container = new CompositionContainer(new TypeCatalog(typeof(Foo)));
            var locator   = new ServiceLocatorImpl(Mock.Of <IServiceProvider>(), new Lazy <ExportProvider>(() => container));

            var foo = locator.GetExports <Foo, IDictionary <string, object> >().FirstOrDefault();

            Assert.NotNull(foo);
            Assert.Equal("asdf", foo.Metadata["Id"]);
        }
        public void when_getting_typed_export_with_metadata_then_succeeds()
        {
            var container = new CompositionContainer(new TypeCatalog(typeof(Foo)));
            var locator   = new ServiceLocatorImpl(Mock.Of <IServiceProvider>(), new Lazy <ExportProvider>(() => container));

            var foo = locator.GetExport <Foo, IFooMetadata>();

            Assert.NotNull(foo);
            Assert.Equal("asdf", foo.Metadata.Id);
        }
Beispiel #9
0
		public void when_getting_exports_with_metadata_dictionary_then_succeeds ()
		{
			var container = new CompositionContainer(new TypeCatalog(typeof(Foo)));
			var locator = new ServiceLocatorImpl(Mock.Of<IServiceProvider>(), new Lazy<ExportProvider>(() => container));

			var foo = locator.GetExports(typeof(Foo), typeof(IDictionary<string, object>)).FirstOrDefault();

			Assert.NotNull (foo);
			Assert.Equal ("asdf", ((IDictionary<string, object>)foo.Metadata)["Id"]);
		}
Beispiel #10
0
		public void when_getting_export_with_metadata_then_succeeds ()
		{
			var container = new CompositionContainer(new TypeCatalog(typeof(Foo)));
			var locator = new ServiceLocatorImpl(Mock.Of<IServiceProvider>(), new Lazy<ExportProvider>(() => container));

			var foo = locator.GetExport(typeof(Foo), typeof(IFooMetadata));

			Assert.NotNull (foo);
			Assert.Equal ("asdf", ((IFooMetadata)foo.Metadata).Id);
		}
Beispiel #11
0
        public void when_constructing_locator_with_service_provider_then_gets_exports_from_component_model_service()
        {
            var container = new CompositionContainer(new TypeCatalog(typeof(Foo)));
            var locator   = new ServiceLocatorImpl(
                Mock.Of <IServiceProvider>(s => s.GetService(typeof(SComponentModel)) ==
                                           Mock.Of <IComponentModel>(c => c.DefaultExportProvider == container)));

            var foo = locator.GetExport <Foo>();

            Assert.NotNull(foo);
        }
Beispiel #12
0
		public ServiceLocatorProvider([Import(typeof(SVsServiceProvider))] IServiceProvider serviceProvider)
		{
			ServiceLocator = new ServiceLocatorImpl(serviceProvider);
		}
Beispiel #13
0
		public void when_constructing_locator_with_service_provider_then_gets_exports_from_component_model_service ()
		{
			var container = new CompositionContainer(new TypeCatalog(typeof(Foo)));
			var locator = new ServiceLocatorImpl(
				Mock.Of<IServiceProvider>(s => s.GetService(typeof(SComponentModel)) ==
					Mock.Of<IComponentModel>(c => c.DefaultExportProvider == container)));

			var foo = locator.GetExport<Foo>();

			Assert.NotNull (foo);
		}
Beispiel #14
0
		public void when_retrieving_service_then_invokes_service_provider ()
		{
			var locator = new ServiceLocatorImpl(
				Mock.Of<IServiceProvider>(x => x.GetService(typeof(Foo)) == new Foo()),
				new Lazy<ExportProvider>(() => Mock.Of<ExportProvider>()));

			var foo = locator.GetService(typeof(Foo));

			Assert.NotNull (foo);
		}
Beispiel #15
0
		public void when_getting_missing_service_then_throws ()
		{
			var container = new CompositionContainer();
			var locator = new ServiceLocatorImpl(Mock.Of<IServiceProvider>(), new Lazy<ExportProvider>(() => container));

			Assert.Throws<MissingDependencyException> (() => locator.GetService (typeof (Foo)));
		}
Beispiel #16
0
		public void when_getting_missing_exports_then_returns_empty ()
		{
			var container = new CompositionContainer();
			var locator = new ServiceLocatorImpl(Mock.Of<IServiceProvider>(), new Lazy<ExportProvider>(() => container));

			var instances = locator.GetExports (typeof (Foo)).ToList ();

			Assert.Equal (0, instances.Count);
		}
Beispiel #17
0
 public ServiceLocatorProvider([Import(typeof(SVsServiceProvider))] IServiceProvider serviceProvider)
 {
     ServiceLocator = new ServiceLocatorImpl(serviceProvider);
 }