Example #1
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>();
        }
Example #2
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");
        }
Example #3
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)));
        }
Example #4
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"));
        }