Beispiel #1
0
        public void Overrides_CanOverrideValue()
        {
            // Act
            var result = Container.Resolve <ObjectWithProperty>(
                Override.Property(nameof(ObjectWithProperty.MyProperty), Resolve.Dependency <ISomething>(Name))
                .OnType <ObjectWithProperty>());

            // Assert
            Assert.IsNotNull(result);
            Assert.IsNotNull(result.MyProperty);
            Assert.IsInstanceOfType(result.MyProperty, typeof(Something2));
        }
Beispiel #2
0
        public void Overrides_ValueOverrideForTypeDifferentThanResolvedTypeIsIgnored()
        {
            // Act
            var result = Container.Resolve <ObjectWithProperty>(
                Override.Property(nameof(ObjectWithProperty.MyProperty), Resolve.Dependency <ISomething>(Name))
                .OnType <ObjectThatDependsOnSimpleObject>());

            // Assert
            Assert.IsNotNull(result);
            Assert.IsNotNull(result.MyProperty);
            Assert.IsInstanceOfType(result.MyProperty, typeof(Something1));
        }
        public void Overrides_CanOverrideValueResolver()
        {
            // Act
            var resolver = new ValidatingResolver(new Something2());
            var result   = Container.Resolve <ObjectWithProperty>(
                Override.Property(nameof(ObjectWithProperty.MyProperty), resolver));

            // Assert
            Assert.IsNotNull(result);
            Assert.IsNotNull(result.MyProperty);
            Assert.IsInstanceOfType(result.MyProperty, typeof(Something2));
            Assert.AreEqual(typeof(ISomething), resolver.Type);
        }
Beispiel #4
0
        public void Overrides_CanOverrideAttributedValue()
        {
            var other = "other";

            // Act
            var result = Container.Resolve <ObjectWithThreeProperties>(
                Override.Property(nameof(ObjectWithThreeProperties.Name), other)
                .OnType <ObjectWithThreeProperties>());

            // Assert
            Assert.IsNotNull(result);
            Assert.IsNotNull(result.Container);
            Assert.AreEqual <string>(result.Name, other);
        }
        public void Overrides_CanOverrideAttributedValueResolver()
        {
            var other    = "other";
            var resolver = new ValidatingResolver(other);

            // Act
            var result = Container.Resolve <ObjectWithThreeProperties>(
                Override.Property(nameof(ObjectWithThreeProperties.Name), resolver));

            // Assert
            Assert.IsNotNull(result);
            Assert.IsNotNull(result.Container);
            Assert.AreEqual(result.Name, other);
            Assert.AreEqual(typeof(string), resolver.Type);
        }
        public void InjectedPropertyWithPropertyOverride()
        {
            // Setup
            var noOverride   = "default";
            var propOverride = "custom-via-propertyoverride";

            Container.RegisterType <TestType>(Inject.Property(nameof(TestType.DependencyProperty), noOverride));
            // Act
            var defaultValue = Container.Resolve <TestType>().DependencyProperty;
            var propValue    = Container.Resolve <TestType>(Override.Property(nameof(TestType.DependencyProperty), propOverride))
                               .DependencyProperty;

            // Verify
            Assert.AreSame(noOverride, defaultValue);
            Assert.AreSame(propOverride, propValue);
        }
        public void CanOverridePropertyValueWithNullWithExplicitInjectionParameter()
        {
            // Setup
            Container
            .RegisterType <ObjectTakingASomething>(new InjectionProperty("MySomething"))
            .RegisterType <IService, Service1>()
            .RegisterType <IService, Service2>("other");

            // Act
            var result = Container.Resolve <ObjectTakingASomething>(
                Override.Property(nameof(ObjectTakingASomething.MySomething), Inject.Parameter <IService>(null))
                .OnType <ObjectTakingASomething>());

            // Verify
            Assert.IsNull(result.MySomething);
        }
        public void Overrides_CanOverrideNamedPropResolver()
        {
            // Arrange
            Container.RegisterType <ObjectWithNamedDependencyProperties>(
                new InjectionProperty(nameof(ObjectWithNamedDependencyProperties.Property), Name));

            // Act
            var other    = "other";
            var resolver = new ValidatingResolver(other);
            var result   = Container.Resolve <ObjectWithNamedDependencyProperties>(
                Override.Property(nameof(ObjectWithNamedDependencyProperties.Property), resolver));

            // Assert
            Assert.IsNotNull(result);
            Assert.IsNotNull(result.Property);
            Assert.AreEqual(other, result.Property);
            Assert.AreEqual(typeof(string), resolver.Type);
            Assert.AreEqual(Name, resolver.Name);
        }
Beispiel #9
0
        public void Overrides_CanOverridePropOnAttributed()
        {
            // Arrange
            Container.RegisterType <ObjectWithThreeProperties>(
                new InjectionProperty(nameof(ObjectWithThreeProperties.Property), Name));

            // Act
            var other  = "other";
            var result = Container.Resolve <ObjectWithThreeProperties>(
                Override.Property(nameof(ObjectWithThreeProperties.Property), other)
                .OnType <ObjectWithThreeProperties>());

            // Assert
            Assert.IsNotNull(result);
            Assert.IsNotNull(result.Name);
            Assert.IsNotNull(result.Container);
            Assert.IsNotNull(result.Property);
            Assert.AreEqual((object)other, result.Property);
        }
        public void InjectedPropertyWithDependencyOverride()
        {
            // Setup
            var noOverride  = "default";
            var depOverride = "custom-via-override";

            Container.RegisterType <TestType>(new InjectionConstructor(),
                                              new InjectionProperty(nameof(TestType.DependencyProperty), noOverride));

            // Act
            var theType      = Container.Resolve <TestType>();
            var defaultValue = theType.DependencyProperty;

            var depValue  = Container.Resolve <TestType>(Override.Dependency <string>(depOverride)).DependencyProperty;
            var propValue = Container.Resolve <TestType>(Override.Property(nameof(TestType.DependencyProperty), depOverride)).DependencyProperty;

            // Verify
            Assert.AreSame(noOverride, defaultValue);
            Assert.AreSame(depOverride, depValue);
            Assert.AreSame(depOverride, propValue);
        }