Exemplo n.º 1
0
        public void when_get_unregistered_service_with_generic_method_it_should_fail()
        {
            var    adapter = new SimpleInjectorAdapter(MakeContainer());
            Action sut     = () => adapter.GetService <UnregisteredService>();

            sut.Should().ThrowExactly <InvalidOperationException>().Where(exception => exception.Message.Contains(nameof(UnregisteredService)));
        }
Exemplo n.º 2
0
        public void when_get_unspecified_service_it_should_fail()
        {
            var    adapter = new SimpleInjectorAdapter(MakeContainer());
            Action sut     = () => adapter.GetService(serviceType: null);

            sut.Should().ThrowExactly <ArgumentNullException>().Where(exception => exception.ParamName.Equals("serviceType"));
        }
Exemplo n.º 3
0
        public void when_get_registered_service_with_generic_method_it_should_return_instance()
        {
            var sut = new SimpleInjectorAdapter(MakeContainer());

            sut.GetService <IService1>().Should().BeOfType <Service1>();
            sut.GetService <Service1>().Should().BeOfType <Service1>();
            sut.GetService <Service2>().Should().BeOfType <Service2>();
        }
		public void TestRegister()
		{
			var container = new SimpleInjectorAdapter();

			container.Register<IFoo, Foo>();
			//container.Has<IFoo>();
			container.Verify();
		}
		public void TestGetInstance()
		{
			var container = new SimpleInjectorAdapter();

			container.Register<IFoo, Foo>();

			IFoo foo = container.GetInstance<IFoo>();
			Assert.NotNull(foo);
			Assert.IsType<Foo>(foo);
		}
Exemplo n.º 6
0
        public static Container RegisterEasyNetQ(this Container container, Func <IServiceResolver, ConnectionConfiguration> connectionConfigurationFactory, Action <IServiceRegister> registerServices)
        {
            if (container == null)
            {
                throw new ArgumentNullException(nameof(container));
            }

            var serviceRegister = new SimpleInjectorAdapter(container);

            RabbitHutch.RegisterBus(serviceRegister, connectionConfigurationFactory, registerServices);
            return(container);
        }
        public void MultipleImplementationAreRegisteredByTypeAsParameter_ResolvedCollectionContainsAllImplementations()
        {
            var adapter = new SimpleInjectorAdapter();

            adapter.RegisterCollection(typeof(ITestDependency), new[] { typeof(TestDependencyA), typeof(TestDependencyB) });

            var collection = adapter.Resolve <IEnumerable <ITestDependency> >().ToArray();

            var firstItem  = collection.First();
            var secondItem = collection.Last();

            Assert.IsInstanceOf(typeof(TestDependencyA), firstItem);
            Assert.IsInstanceOf(typeof(TestDependencyB), secondItem);
        }
Exemplo n.º 8
0
        public void when_begin_scope_it_should_return_instance_of_scoped_service()
        {
            var adapter = new SimpleInjectorAdapter(MakeContainer());

            using (adapter.BeginScope())
            {
                adapter.GetService(typeof(ScopedService)).Should().BeOfType <ScopedService>("scoped service should be available in a scope");
                adapter.GetService <ScopedService>().Should().BeOfType <ScopedService>("scoped service should be available in a scope");
            }

            Action sut = () => adapter.GetService <ScopedService>();

            sut.Should().ThrowExactly <InvalidOperationException>("scoped service should be unavailable in a scope");
        }
        public void MultipleImplementationAreRegisteredByInstance_ResolvedCollectionContainsAllImplementations()
        {
            var adapter   = new SimpleInjectorAdapter();
            var instanceA = new TestDependencyA();
            var instanceB = new TestDependencyB();

            adapter.RegisterCollection(new ITestDependency[] { instanceA, instanceB });

            var collection = adapter.Resolve <IEnumerable <ITestDependency> >().ToArray();

            var firstItem  = collection.First();
            var secondItem = collection.Last();

            Assert.AreSame(instanceA, firstItem);
            Assert.AreSame(instanceB, secondItem);
        }
		public void TestGetInstanceCheckForInstanceIdentity()
		{
			var container = new SimpleInjectorAdapter();

			container.Register<IFoo, Foo>();

			IFoo foo1 = container.GetInstance<IFoo>();
			Assert.NotNull(foo1);
			Assert.IsType<Foo>(foo1);

			IFoo foo2 = container.GetInstance<IFoo>();
			Assert.NotNull(foo2);
			Assert.IsType<Foo>(foo2);

			Assert.Same(foo1, foo2);
		}
Exemplo n.º 11
0
        public async Task when_constructed_without_required_arguments_it_should_fail()
        {
            var state = new TestDriverState();

            await using var container = RoutingTests
                                        .SetupContainer(_testOutputHelper)
                                        .AddRouterWithComplexApis <SampleBrokerPipeFitter, EmptyPipeFitter, EmptyPipeFitter, EmptyPipeFitter>(state);

            var containerAdapter = new SimpleInjectorAdapter(container);
            var configuration    = new MessageRouterConfiguration();
            // ReSharper disable AccessToModifiedClosure - it's a way to test.
            // ReSharper disable once ObjectCreationAsStatement
            Action sut = () => new MessageRouter(configuration, containerAdapter);

            containerAdapter = null;
            sut.Should().ThrowExactly <ArgumentNullException>().Where(exception => exception.ParamName.Equals("diContainerAdapter"));

            containerAdapter = new SimpleInjectorAdapter(container);
            configuration    = null;
            sut.Should().ThrowExactly <ArgumentNullException>().Where(exception => exception.ParamName.Equals("configuration"));
        }
 public void ForContext_AdministratorContextAndImplementation_ReturnsAdministratorImplementation()
 {
     var adapter = new SimpleInjectorAdapter(new Container());
     TestScenarios.AdministratorRole_AdministratorImplementation_ReturnsAdministratorImplementation(adapter);
 }
Exemplo n.º 13
0
        public void ForContext_AdministratorContextAndImplementation_ReturnsAdministratorImplementation()
        {
            var adapter = new SimpleInjectorAdapter(new Container());

            TestScenarios.AdministratorRole_AdministratorImplementation_ReturnsAdministratorImplementation(adapter);
        }