Пример #1
0
        public void PropertyInjectorCanSetReferenceType()
        {
            PropertyInfo property =
                typeof(PropertyAndFieldInvocationObject).GetProperty("Message", BindingFlags.Public | BindingFlags.Instance);
            IPropertyInjector injector = Factory.GetInjector(property);

            Assert.That(injector, Is.Not.Null);

            PropertyAndFieldInvocationObject mock = new PropertyAndFieldInvocationObject();

            injector.Set(mock, "Hello, world!");

            Assert.That(mock.Message, Is.EqualTo("Hello, world!"));
        }
Пример #2
0
        public void PropertyInjectorCanSetValueType()
        {
            PropertyInfo property =
                typeof(PropertyAndFieldInvocationObject).GetProperty("Value", BindingFlags.Public | BindingFlags.Instance);
            IPropertyInjector injector = Factory.GetInjector(property);

            Assert.That(injector, Is.Not.Null);

            PropertyAndFieldInvocationObject mock = new PropertyAndFieldInvocationObject();

            injector.Set(mock, 42);

            Assert.That(mock.Value, Is.EqualTo(42));
        }
Пример #3
0
        public void FieldInjectorCanSetValueType()
        {
            FieldInfo field =
                typeof(PropertyAndFieldInvocationObject).GetField("_value", BindingFlags.NonPublic | BindingFlags.Instance);
            IFieldInjector injector = Factory.GetInjector(field);

            Assert.That(injector, Is.Not.Null);

            PropertyAndFieldInvocationObject mock = new PropertyAndFieldInvocationObject();

            injector.Set(mock, 42);

            Assert.That(mock.Value, Is.EqualTo(42));
        }
Пример #4
0
        public void FieldInjectorCanGetReferenceType()
        {
            FieldInfo field =
                typeof(PropertyAndFieldInvocationObject).GetField("_message", BindingFlags.NonPublic | BindingFlags.Instance);
            IFieldInjector injector = Factory.GetInjector(field);

            Assert.That(injector, Is.Not.Null);

            PropertyAndFieldInvocationObject mock = new PropertyAndFieldInvocationObject();

            mock.Message = "Hello, world!";

            string message = (string)injector.Get(mock);

            Assert.That(message, Is.EqualTo("Hello, world!"));
        }