Exemple #1
0
 it_should_throw_a_NotImplementedException_because_Autofac_does_not_support_reseting_the_container()
 {
     using (var helper = new AutofacServiceLocatorHelper())
     {
         helper.AutofacServiceLocator.Invoking(x => x.Reset()).ShouldThrow <NotImplementedException>();
     }
 }
Exemple #2
0
 public void it_should_throw_an_ArgumentNullException_when_the_type_is_null_for_the_key_specified()
 {
     using (var helper = new AutofacServiceLocatorHelper())
     {
         helper.ValidateType(helper.AutofacServiceLocator.Invoking(x => x.Register("my key", null)), "implType");
     }
 }
Exemple #3
0
 public void when_the_instance_is_null_it_should_not_throw_any_exceptions()
 {
     using (var helper = new AutofacServiceLocatorHelper())
     {
         helper.AutofacServiceLocator.Invoking(x => x.TearDown <IMyTestingContract>(null)).ShouldNotThrow();
     }
 }
Exemple #4
0
 it_should_return_an_empty_enumerable_when_there_are_not_types_registered_for_the_generic_type_specified()
 {
     using (var helper = new AutofacServiceLocatorHelper())
     {
         helper.AutofacServiceLocator.ResolveServices <IMyTestingContract>().Should().NotBeNull().And.
         HaveCount(0);
     }
 }
Exemple #5
0
 public void it_should_resolve_the_type_registered_with_the_generic_contract_specified()
 {
     using (var helper = new AutofacServiceLocatorHelper())
     {
         helper.AutofacServiceLocator.Register <IMyTestingContract, MyImplementation>();
         helper.AutofacServiceLocator.Resolve <IMyTestingContract>().Should().BeOfType <MyImplementation>();
     }
 }
Exemple #6
0
 public void it_should_throw_an_ArgumentNullException_when_the_instance_to_be_injected_is_null()
 {
     using (var helper = new AutofacServiceLocatorHelper())
     {
         helper.ValidateInstance(
             helper.AutofacServiceLocator.Invoking(x => x.Inject <IMyTestingContract>(null)), "instance");
     }
 }
Exemple #7
0
 public void it_should_register_the_type_specified_with_the_contract_type_specified()
 {
     using (var helper = new AutofacServiceLocatorHelper())
     {
         helper.AutofacServiceLocator.Register(typeof(IMyTestingContract), typeof(MyImplementation));
         helper.Container.Resolve <IMyTestingContract>().Should().BeOfType <MyImplementation>();
     }
 }
Exemple #8
0
 public void it_should_resolve_the_type_registered_for_the_type_specified()
 {
     using (var helper = new AutofacServiceLocatorHelper())
     {
         helper.AutofacServiceLocator.Register <IMyTestingContract, MyImplementation>();
         helper.AutofacServiceLocator.Resolve(typeof(IMyTestingContract)).Should().NotBeNull().And.BeOfType
         <MyImplementation>();
     }
 }
Exemple #9
0
 it_should_resolve_the_type_registered_with_the_generic_contract_specified_and_with_the_key_specifdied()
 {
     using (var helper = new AutofacServiceLocatorHelper())
     {
         helper.AutofacServiceLocator.Register <IMyTestingContract, MyImplementation>("my key");
         helper.AutofacServiceLocator.Resolve <IMyTestingContract>("my key").Should().NotBeNull().And.BeOfType
         <MyImplementation>();
     }
 }
Exemple #10
0
 public void it_should_register_the_specified_type_with_the_key_specified()
 {
     using (var helper = new AutofacServiceLocatorHelper())
     {
         helper.AutofacServiceLocator.Register("my key", typeof(MyImplementation));
         helper.Container.ResolveNamed <MyImplementation>("my key").Should().NotBeNull().And.BeOfType
         <MyImplementation>();
     }
 }
Exemple #11
0
 it_should_register_the_instance_returned_from_the_Func_delegate_with_the_generic_contract_specified()
 {
     using (var helper = new AutofacServiceLocatorHelper())
     {
         var myType = new MyImplementation();
         helper.AutofacServiceLocator.Register <IMyTestingContract>(() => myType);
         helper.Container.Resolve <IMyTestingContract>().Should().BeOfType <MyImplementation>().And.Be(myType);
     }
 }
Exemple #12
0
 it_should_throw_an_ArgumentNullException_when_the_delegate_is_null_for_the_generic_contract_specified()
 {
     using (var helper = new AutofacServiceLocatorHelper())
     {
         helper.ValidateFuncDelegate(
             helper.AutofacServiceLocator.Invoking(
                 x => x.Register <IMyTestingContract>((Func <IMyTestingContract>)null)), "factoryMethod");
     }
 }
Exemple #13
0
 it_should_throw_an_ArgumentNullException_when_the_instance_is_null_for_the_generic_type_specified()
 {
     using (var helper = new AutofacServiceLocatorHelper())
     {
         helper.ValidateInstance(
             helper.AutofacServiceLocator.Invoking(
                 x => x.Register <IMyTestingContract>((IMyTestingContract)null)), "instance");
     }
 }
Exemple #14
0
 public void it_should_throw_an_ArgumentNullException_when_the_type_is_null_for_the_contract_type_specified()
 {
     using (var helper = new AutofacServiceLocatorHelper())
     {
         helper.ValidateType(
             helper.AutofacServiceLocator.Invoking(x => x.Register(typeof(IMyTestingContract), (Type)null)),
             "implType");
     }
 }
 public void it_should_inject_an_existing_instance()
 {
     using (var helper = new AutofacServiceLocatorHelper())
     {
         helper.AutofacServiceLocator.Register<Additionaltype>(new Additionaltype());
         var myObject = new MyImplementation();
         myObject = helper.AutofacServiceLocator.Inject(myObject);
         myObject.Should().NotBeNull().And.BeOfType<MyImplementation>();
         myObject.AdditionalType.Should().NotBeNull().And.BeOfType<Additionaltype>();
     }
 }
Exemple #16
0
 public void it_should_inject_an_existing_instance()
 {
     using (var helper = new AutofacServiceLocatorHelper())
     {
         helper.AutofacServiceLocator.Register <Additionaltype>(new Additionaltype());
         var myObject = new MyImplementation();
         myObject = helper.AutofacServiceLocator.Inject(myObject);
         myObject.Should().NotBeNull().And.BeOfType <MyImplementation>();
         myObject.AdditionalType.Should().NotBeNull().And.BeOfType <Additionaltype>();
     }
 }
Exemple #17
0
 public void it_should_dispose_the_service_locator_container()
 {
     using (var helper = new AutofacServiceLocatorHelper())
     {
         helper.Container.Should().NotBeNull();
         helper.AutofacServiceLocator.Register <IMyTestingContract, MyImplementation>();
         helper.AutofacServiceLocator.IsDisposed.Should().BeFalse();
         helper.AutofacServiceLocator.Dispose();
         GC.Collect();
         helper.AutofacServiceLocator.IsDisposed.Should().BeTrue();
     }
 }
 public void it_should_dispose_the_service_locator_container()
 {
     using (var helper = new AutofacServiceLocatorHelper())
     {
         helper.Container.Should().NotBeNull();
         helper.AutofacServiceLocator.Register<IMyTestingContract, MyImplementation>();
         helper.AutofacServiceLocator.IsDisposed.Should().BeFalse();
         helper.AutofacServiceLocator.Dispose();
         GC.Collect();
         helper.AutofacServiceLocator.IsDisposed.Should().BeTrue();
     }
 }
Exemple #19
0
 public void it_should_throw_an_ArgumentNullException_when_the_key_is_null_for_the_type_specified()
 {
     using (var helper = new AutofacServiceLocatorHelper())
     {
         helper.ValidateKey(
             helper.AutofacServiceLocator.Invoking(x => x.Register((string)null, typeof(MyImplementation))));
         helper.ValidateKey(
             helper.AutofacServiceLocator.Invoking(x => x.Register(string.Empty, typeof(MyImplementation))));
         helper.ValidateKey(
             helper.AutofacServiceLocator.Invoking(x => x.Register(" ", typeof(MyImplementation))));
     }
 }
Exemple #20
0
        public void it_should_tear_down_the_specified_instance()
        {
            using (var helper = new AutofacServiceLocatorHelper())
            {
                var myObject = new MyImplementation();

                helper.AutofacServiceLocator.Invoking(x => x.Release(myObject));

                helper.AutofacServiceLocator.Register <IMyTestingContract>(myObject);
                helper.AutofacServiceLocator.Invoking(x => x.TearDown(myObject))
                .ShouldNotThrow();
            }
        }
Exemple #21
0
 public void it_should_resolve_all_the_types_registered_for_the_generic_contract_specified()
 {
     using (var helper = new AutofacServiceLocatorHelper())
     {
         helper.AutofacServiceLocator.Register <IMyTestingContract, MyImplementation>();
         helper.AutofacServiceLocator.Register <IMyTestingContract, MyImplementation3>();
         helper.AutofacServiceLocator.Register <IMyTestingContract, MyImplementation2>();
         helper.AutofacServiceLocator.ResolveServices <IMyTestingContract>().Should()
         .NotBeNull().And.HaveCount(3).And.ContainItemsAssignableTo <IMyTestingContract>()
         .And.OnlyHaveUniqueItems()
         .And.Match(x => x.OfType <MyImplementation>().Count() == 1)
         .And.Match(x => x.OfType <MyImplementation2>().Count() == 1)
         .And.Match(x => x.OfType <MyImplementation3>().Count() == 1);
     }
 }
Exemple #22
0
 it_should_throw_an_ArgumentNullException_when_the_key_specified_is_null_for_the_generic_contract_and_the_generic_type_specified
     ()
 {
     using (var helper = new AutofacServiceLocatorHelper())
     {
         helper.ValidateKey(
             helper.AutofacServiceLocator.Invoking(
                 x => x.Register <IMyTestingContract, MyImplementation>(null)));
         helper.ValidateKey(
             helper.AutofacServiceLocator.Invoking(
                 x => x.Register <IMyTestingContract, MyImplementation>(string.Empty)));
         helper.ValidateKey(
             helper.AutofacServiceLocator.Invoking(x => x.Register <IMyTestingContract, MyImplementation>(" ")));
     }
 }
 public void when_the_instance_is_null_it_should_not_throw_any_exceptions()
 {
     using (var helper = new AutofacServiceLocatorHelper())
     {
         helper.AutofacServiceLocator.Invoking(x => x.TearDown<IMyTestingContract>(null)).ShouldNotThrow();
     }
 }
 public void it_should_register_the_specified_type_with_the_key_specified()
 {
     using (var helper = new AutofacServiceLocatorHelper())
     {
         helper.AutofacServiceLocator.Register("my key", typeof (MyImplementation));
         helper.Container.ResolveNamed<MyImplementation>("my key").Should().NotBeNull().And.BeOfType
             <MyImplementation>();
     }
 }
 public void it_should_return_an_empty_enumerable_when_there_are_not_types_registered_for_the_generic_type_specified()
 {
     using (var helper = new AutofacServiceLocatorHelper())
     {
         helper.AutofacServiceLocator.ResolveServices<IMyTestingContract>().Should().NotBeNull().And.
             HaveCount(0);
     }
 }
        public void it_should_tear_down_the_specified_instance()
        {
            using (var helper = new AutofacServiceLocatorHelper())
            {
                var myObject = new MyImplementation();

                helper.AutofacServiceLocator.Invoking(x => x.Release(myObject));

                helper.AutofacServiceLocator.Register<IMyTestingContract>(myObject);
                helper.AutofacServiceLocator.Invoking(x => x.TearDown(myObject))
                    .ShouldNotThrow();
            }
        }
 public void it_should_resolve_the_type_registered_with_the_generic_contract_specified_and_with_the_key_specifdied()
 {
     using (var helper = new AutofacServiceLocatorHelper())
     {
         helper.AutofacServiceLocator.Register<IMyTestingContract, MyImplementation>("my key");
         helper.AutofacServiceLocator.Resolve<IMyTestingContract>("my key").Should().NotBeNull().And.BeOfType
             <MyImplementation>();
     }
 }
 public void it_should_resolve_all_the_types_registered_for_the_generic_contract_specified()
 {
     using (var helper = new AutofacServiceLocatorHelper())
     {
         helper.AutofacServiceLocator.Register<IMyTestingContract, MyImplementation>();
         helper.AutofacServiceLocator.Register<IMyTestingContract, MyImplementation3>();
         helper.AutofacServiceLocator.Register<IMyTestingContract, MyImplementation2>();
         helper.AutofacServiceLocator.ResolveServices<IMyTestingContract>().Should()
             .NotBeNull().And.HaveCount(3).And.ContainItemsAssignableTo<IMyTestingContract>()
             .And.OnlyHaveUniqueItems()
             .And.Match(x => x.OfType<MyImplementation>().Count() == 1)
             .And.Match(x => x.OfType<MyImplementation2>().Count() == 1)
             .And.Match(x => x.OfType<MyImplementation3>().Count() == 1);
     }
 }
 public void it_should_throw_a_NotImplementedException_because_Autofac_does_not_support_reseting_the_container()
 {
     using (var helper = new AutofacServiceLocatorHelper())
     {
         helper.AutofacServiceLocator.Invoking(x => x.Reset()).ShouldThrow<NotImplementedException>();
     }
 }
 public void it_should_throw_an_ArgumentNullException_when_the_delegate_is_null_for_the_generic_contract_specified()
 {
     using (var helper = new AutofacServiceLocatorHelper())
     {
         helper.ValidateFuncDelegate(
             helper.AutofacServiceLocator.Invoking(
                 x => x.Register<IMyTestingContract>((Func<IMyTestingContract>) null)), "factoryMethod");
     }
 }
 public void it_should_throw_an_ArgumentNullException_when_the_type_is_null_for_the_contract_type_specified()
 {
     using (var helper = new AutofacServiceLocatorHelper())
     {
         helper.ValidateType(
             helper.AutofacServiceLocator.Invoking(x => x.Register(typeof (IMyTestingContract), (Type) null)),
             "implType");
     }
 }
 public void it_should_throw_an_ArgumentNullException_when_the_type_is_null_for_the_key_specified()
 {
     using (var helper = new AutofacServiceLocatorHelper())
     {
         helper.ValidateType(helper.AutofacServiceLocator.Invoking(x => x.Register("my key", null)), "implType");
     }
 }
 public void it_should_throw_an_ArgumentNullException_when_the_key_specified_is_null_for_the_generic_contract_and_the_generic_type_specified()
 {
     using (var helper = new AutofacServiceLocatorHelper())
     {
         helper.ValidateKey(
             helper.AutofacServiceLocator.Invoking(
                 x => x.Register<IMyTestingContract, MyImplementation>(null)));
         helper.ValidateKey(
             helper.AutofacServiceLocator.Invoking(
                 x => x.Register<IMyTestingContract, MyImplementation>(string.Empty)));
         helper.ValidateKey(
             helper.AutofacServiceLocator.Invoking(x => x.Register<IMyTestingContract, MyImplementation>(" ")));
     }
 }
 public void it_should_throw_an_ArgumentNullException_when_the_key_is_null_for_the_type_specified()
 {
     using (var helper = new AutofacServiceLocatorHelper())
     {
         helper.ValidateKey(
             helper.AutofacServiceLocator.Invoking(x => x.Register((string) null, typeof (MyImplementation))));
         helper.ValidateKey(
             helper.AutofacServiceLocator.Invoking(x => x.Register(string.Empty, typeof (MyImplementation))));
         helper.ValidateKey(
             helper.AutofacServiceLocator.Invoking(x => x.Register(" ", typeof (MyImplementation))));
     }
 }
 public void it_should_throw_an_ArgumentNullException_when_the_instance_is_null_for_the_generic_type_specified()
 {
     using (var helper = new AutofacServiceLocatorHelper())
     {
         helper.ValidateInstance(
             helper.AutofacServiceLocator.Invoking(
                 x => x.Register<IMyTestingContract>((IMyTestingContract) null)), "instance");
     }
 }
 public void it_should_register_the_instance_specified_with_the_generic_contract_specified()
 {
     using (var helper = new AutofacServiceLocatorHelper())
     {
         var myType = new MyImplementation();
         helper.AutofacServiceLocator.Register<IMyTestingContract>(myType);
         helper.Container.Resolve<IMyTestingContract>().Should().BeOfType<MyImplementation>().And.Be(myType);
     }
 }
 public void it_should_resolve_the_type_registered_for_the_type_specified()
 {
     using (var helper = new AutofacServiceLocatorHelper())
     {
         helper.AutofacServiceLocator.Register<IMyTestingContract, MyImplementation>();
         helper.AutofacServiceLocator.Resolve(typeof(IMyTestingContract)).Should().NotBeNull().And.BeOfType
             <MyImplementation>();
     }
 }
 public void it_should_throw_an_ArgumentNullException_when_the_instance_to_be_injected_is_null()
 {
     using (var helper = new AutofacServiceLocatorHelper())
     {
         helper.ValidateInstance(
             helper.AutofacServiceLocator.Invoking(x => x.Inject<IMyTestingContract>(null)), "instance");
     }
 }
 public void it_should_register_the_type_specified_with_the_generic_contract_specified()
 {
     using (var helper = new AutofacServiceLocatorHelper())
     {
         helper.AutofacServiceLocator.Register<IMyTestingContract>(typeof (MyImplementation));
         helper.Container.Resolve<IMyTestingContract>().Should().BeOfType<MyImplementation>();
     }
 }