Exemple #1
0
        public void CanConfigureInjectionByNameWithoutUsingGenerics()
        {
            object expectedObjectZero = new object();
            object expectedObjectOne  = new object();

            IUnityContainer container = new UnityContainer()
                                        .Configure <InjectedMembers>()
                                        .ConfigureInjectionFor(typeof(GuineaPig), "one",
                                                               new InjectionConstructor(expectedObjectOne),
                                                               new InjectionProperty("IntProperty", 35))
                                        .ConfigureInjectionFor(typeof(GuineaPig),
                                                               new InjectionConstructor(),
                                                               new InjectionProperty("ObjectProperty", new ResolvedParameter(typeof(object), "zero")))
                                        .Container
                                        .RegisterInstance <object>("zero", expectedObjectZero);

            GuineaPig pigZero = container.Resolve <GuineaPig>();
            GuineaPig pigOne  = container.Resolve <GuineaPig>("one");

            Assert.IsTrue(pigZero.DefaultConstructorCalled);
            Assert.AreSame(expectedObjectZero, pigZero.ObjectProperty);
            Assert.IsTrue(pigOne.OneArgumentConstructorCalled);
            Assert.AreSame(expectedObjectOne, pigOne.ObjectProperty);
            Assert.AreEqual(35, pigOne.IntProperty);
        }
Exemple #2
0
            public void ClosePreviouslyInitializedFile()
            {
                string path = Path.GetTempFileName();

                H5File FILE = H5File.Open(path, mode: "w");

                // initialize a test-object, which creates two datasets:
                var PIG = new GuineaPig(FILE.Root);

                Assert.True(PIG.stringset.ID > 0);
                Assert.True(PIG.byteset.ID > 0);

                // th test-object must be disposed of as this is not automatic:
                PIG.Dispose();

                FILE.Dispose();

                // trying to re-open is a surefire way to check if FILE was closed correctly:
                H5File FILE2 = H5File.Open(path, mode: "w");

                FILE2.Dispose();

                Assert.Equal((hid_t)0, PIG.stringset.ID);
                Assert.Equal((hid_t)0, PIG.byteset.ID);

                File.Delete(path);

                Assert.False(File.Exists(FILE.Path));
            }
        public void StaticMethodsShouldNotBeInjected()
        {
            IUnityContainer container = new UnityContainer();

            GuineaPig pig = container.Resolve <GuineaPig>();

            Assert.IsFalse(GuineaPig.StaticMethodWasCalled);
        }
Exemple #4
0
        public void CanConfigureContainerToCallDefaultConstructor()
        {
            IUnityContainer container = new UnityContainer()
                                        .RegisterType <GuineaPig>(new InjectionConstructor());

            GuineaPig pig = container.Resolve <GuineaPig>();

            Assert.True(pig.DefaultConstructorCalled);
        }
        public void CanInjectMethodReturningVoid()
        {
            IUnityContainer container = new UnityContainer()
                                        .RegisterType(typeof(GuineaPig),
                                                      new InjectionMethod("Inject2", "Hello"));

            GuineaPig pig = container.Resolve <GuineaPig>();

            Assert.AreEqual("Hello", pig.StringValue);
        }
        public void CanInjectMethodReturningInt()
        {
            IUnityContainer container = new UnityContainer()
                                        .RegisterType(typeof(GuineaPig),
                                                      new InjectionMethod("Inject3", 17));

            GuineaPig pig = container.Resolve <GuineaPig>();

            Assert.AreEqual(17, pig.IntValue);
        }
        public void CanInjectMethodReturningVoid()
        {
            IUnityContainer container = new UnityContainer()
                                        .Configure <InjectedMembers>()
                                        .ConfigureInjectionFor(typeof(GuineaPig),
                                                               new InjectionMethod("Inject2", "Hello"))
                                        .Container;

            GuineaPig pig = container.Resolve <GuineaPig>();

            Assert.AreEqual("Hello", pig.StringValue);
        }
        public void CanInjectMethodReturningInt()
        {
            IUnityContainer container = new UnityContainer()
                                        .Configure <InjectedMembers>()
                                        .ConfigureInjectionFor(typeof(GuineaPig),
                                                               new InjectionMethod("Inject3", 17))
                                        .Container;

            GuineaPig pig = container.Resolve <GuineaPig>();

            Assert.AreEqual(17, pig.IntValue);
        }
Exemple #9
0
        public void CanConfigureContainerToCallDefaultConstructor()
        {
            IUnityContainer container = new UnityContainer()
                                        .Configure <InjectedMembers>()
                                        .ConfigureInjectionFor <GuineaPig>(
                new InjectionConstructor())
                                        .Container;

            GuineaPig pig = container.Resolve <GuineaPig>();

            Assert.IsTrue(pig.DefaultConstructorCalled);
        }
Exemple #10
0
        public void TestMethod0()
        {
            var guineaPig = new GuineaPig
            {
                Name = "TEST", Id = Guid.NewGuid(), DateTimeProp = DateTime.Now, IntProp = 1, DecimalProp = 100,
            };

            dynamic pigGuinea = guineaPig.ToDynamic();

            DynamicExtensions.CreateNewProperty(pigGuinea, "Id2", guineaPig.Id);
            Assert.AreEqual(pigGuinea.Id2, guineaPig.Id);
        }
Exemple #11
0
        public void MethodPassingVoid()
        {
            // Setup
            Container.RegisterType(typeof(GuineaPig),
                                   Invoke.Method(nameof(GuineaPig.Inject1)));

            // Act
            GuineaPig pig = Container.Resolve <GuineaPig>();

            // Verify
            Assert.AreEqual("void", pig.StringValue);
        }
        public void CanConfigureMultipleMethods()
        {
            IUnityContainer container = new UnityContainer()
                                        .RegisterType <GuineaPig>(
                new InjectionMethod("Inject3", 37),
                new InjectionMethod("Inject2", "Hi there"));

            GuineaPig pig = container.Resolve <GuineaPig>();

            Assert.AreEqual(37, pig.IntValue);
            Assert.AreEqual("Hi there", pig.StringValue);
        }
Exemple #13
0
        public void CanConfigureContainerToDoMethodInjectionWithRegisterType()
        {
            string expectedString = "expected string";

            IUnityContainer container = new UnityContainer()
                                        .RegisterType <GuineaPig>(new InjectionConstructor(),
                                                                  new InjectionMethod("InjectMeHerePlease", expectedString));
            GuineaPig pig = container.Resolve <GuineaPig>();

            Assert.IsTrue(pig.DefaultConstructorCalled);
            Assert.AreEqual(expectedString, pig.S);
        }
        public virtual void ReturningVoid()
        {
            // Setup
            Container.RegisterType(typeof(GuineaPig),
                                   Invoke.Method(nameof(GuineaPig.Inject2), "Hello"));

            // Act
            GuineaPig pig = Container.Resolve <GuineaPig>();

            // Verify
            Assert.AreEqual("Hello", pig.StringValue);
        }
        public virtual void ReturningInt()
        {
            // Setup
            Container.RegisterType(typeof(GuineaPig),
                                   Invoke.Method(nameof(GuineaPig.Inject3), 17));

            // Act
            GuineaPig pig = Container.Resolve <GuineaPig>();


            // Verify
            Assert.AreEqual(17, pig.IntValue);
        }
Exemple #16
0
        public void CanConfigureMultipleMethodsusingRegisterType()
        {
            string          expectedString = "expected string";
            int             expectedValue  = 10;
            IUnityContainer container      = new UnityContainer()
                                             .RegisterType <GuineaPig>(new InjectionConstructor(),
                                                                       new InjectionMethod("InjectMeHerePlease", expectedString),
                                                                       new InjectionMethod("InjectMeHerePleaseOnceMore", expectedValue));

            GuineaPig pig = container.Resolve <GuineaPig>();

            Assert.AreEqual(expectedString, pig.S);
            Assert.AreEqual(expectedValue, pig.I);
        }
Exemple #17
0
        public void ConfiguringInjectionAfterResolvingTakesEffect()
        {
            IUnityContainer container = new UnityContainer()
                                        .RegisterType <GuineaPig>(new InjectionConstructor());

            container.Resolve <GuineaPig>();

            container.RegisterType <GuineaPig>(
                new InjectionConstructor(new InjectionParameter(typeof(object), "someValue")));

            GuineaPig pig2 = container.Resolve <GuineaPig>();

            Assert.Equal("someValue", pig2.ObjectProperty.ToString());
        }
Exemple #18
0
        public void CanConfigureContainerToInjectPropertyWithValue()
        {
            int expectedInt = 82;

            IUnityContainer container = new UnityContainer()
                                        .RegisterType <GuineaPig>(
                new InjectionConstructor(),
                new InjectionProperty("IntProperty", expectedInt));

            GuineaPig pig = container.Resolve <GuineaPig>();

            Assert.True(pig.DefaultConstructorCalled);
            Assert.Equal(expectedInt, pig.IntProperty);
        }
Exemple #19
0
        public void CanConfigureContainerToInjectPropertyWithRegisterType()
        {
            object expectedObject = new object();

            IUnityContainer container = new UnityContainer()
                                        .RegisterInstance <object>(expectedObject)
                                        .RegisterType <GuineaPig>(new InjectionConstructor(),
                                                                  new InjectionProperty("ObjectProperty"));

            GuineaPig pig = container.Resolve <GuineaPig>();

            Assert.IsTrue(pig.DefaultConstructorCalled);
            Assert.AreSame(expectedObject, pig.ObjectProperty);
        }
        public virtual void Injection_MultipleMethods()
        {
            // Setup
            Container.RegisterType <GuineaPig>(
                new InjectionMethod(nameof(GuineaPig.Inject3), 37),
                new InjectionMethod(nameof(GuineaPig.Inject2), "Hi there"));

            // Act
            GuineaPig pig = Container.Resolve <GuineaPig>();


            // Verify
            Assert.AreEqual(37, pig.IntValue);
            Assert.AreEqual("Hi there", pig.StringValue);
        }
        public virtual void InjectTypeWithAnnotatdStatic()
        {
            // Setup
            Container.RegisterType <GuineaPig>(
                Invoke.Method(nameof(GuineaPig.Inject3), 37),
                Invoke.Method(nameof(GuineaPig.Inject2), "Hi there"));

            // Act
            GuineaPig pig = Container.Resolve <GuineaPig>();


            // Verify
            Assert.AreEqual(37, pig.IntValue);
            Assert.AreEqual("Hi there", pig.StringValue);
        }
Exemple #22
0
        public void CanConfigureContainerWithRegisterTypeToCallConstructorWithValues()
        {
            int    expectedInt    = 37;
            string expectedString = "Hey there";
            double expectedDouble = Math.PI;

            IUnityContainer container = new UnityContainer()
                                        .RegisterType <GuineaPig>(new InjectionConstructor(expectedInt, expectedString, expectedDouble));

            GuineaPig pig = container.Resolve <GuineaPig>();

            Assert.IsTrue(pig.ThreeArgumentConstructorCalled);
            Assert.AreEqual(expectedInt, pig.I);
            Assert.AreEqual(expectedDouble, pig.D);
            Assert.AreEqual(expectedString, pig.S);
        }
Exemple #23
0
        public void CanConfigureContainerToInjectPropertyWithValue()
        {
            int expectedInt = 82;

            IUnityContainer container = new UnityContainer()
                                        .Configure <InjectedMembers>()
                                        .ConfigureInjectionFor <GuineaPig>(
                new InjectionConstructor(),
                new InjectionProperty("IntProperty", expectedInt))
                                        .Container;

            GuineaPig pig = container.Resolve <GuineaPig>();

            Assert.IsTrue(pig.DefaultConstructorCalled);
            Assert.AreEqual(expectedInt, pig.IntProperty);
        }
Exemple #24
0
        public void ConfiguringInjectionAfterResolvingTakesEffect()
        {
            IUnityContainer container = new UnityContainer()
                                        .Configure <InjectedMembers>()
                                        .ConfigureInjectionFor <GuineaPig>(
                new InjectionConstructor())
                                        .Container;

            container.Resolve <GuineaPig>();

            container.Configure <InjectedMembers>()
            .ConfigureInjectionFor <GuineaPig>(
                new InjectionConstructor(new InjectionParameter(typeof(object), "foo")));

            GuineaPig pig2 = container.Resolve <GuineaPig>();

            Assert.AreEqual("foo", pig2.ObjectProperty.ToString());
        }
 public ObjectMethodInvokeExtensionsTests()
 {
     guineaPig = new GuineaPig();
 }
 public void OverloadedMethod(GuineaPig one, string two)
 {
 }