Example #1
0
        public void Overrides_FieldOverrideAttribute()
        {
            // Act
            var result = Container.Resolve <ObjectWithAttributes>(
                Override.Field(nameof(ObjectWithAttributes.Dependency), null),
                Override.Field(nameof(ObjectWithAttributes.Optional), Name1));

            // Verify
            Assert.IsNotNull(result);
            Assert.IsNull(result.Dependency);
            Assert.IsNotNull(result.Optional);
            Assert.AreEqual(result.Optional, Name1);
        }
Example #2
0
        public void Overrides_NullOverAttribute()
        {
            // Setup
            Container.RegisterType <ObjectWithAttributes>(
                Inject.Field(nameof(ObjectWithAttributes.Dependency), Name2));

            // Act
            var result = Container.Resolve <ObjectWithAttributes>(Override.Field(nameof(ObjectWithAttributes.Dependency), null));

            // Verify
            Assert.IsNotNull(result);
            Assert.IsNull(result.Dependency);
            Assert.IsNull(result.Optional);
        }
Example #3
0
        public void Overrides_DependencyOverrideFieldValue()
        {
            var other = "other";

            // Act
            var result = Container.Resolve <ObjectWithAttributes>(
                Override.Field(nameof(ObjectWithAttributes.Dependency), null),
                Override.Dependency(other, other));

            // Verify
            Assert.IsNotNull(result);
            Assert.IsNull(result.Dependency);
            Assert.IsNotNull(result.Optional);
            Assert.AreEqual(result.Optional, other);
        }
Example #4
0
        public void InjectedFieldWithFieldOverride()
        {
            // Setup
            var noOverride    = "default";
            var fieldOverride = "custom-via-fieldoverride";

            Container.RegisterType <TestType>(Inject.Field(nameof(TestType.DependencyField), noOverride));
            // Act
            var defaultValue = Container.Resolve <TestType>().DependencyField;
            var fieldValue   = Container.Resolve <TestType>(Override.Field(nameof(TestType.DependencyField), fieldOverride))
                               .DependencyField;

            // Verify
            Assert.AreSame(noOverride, defaultValue);
            Assert.AreSame(fieldOverride, fieldValue);
        }
        public void Overrides_DependencyOverrideFieldValueResolver()
        {
            var other     = "other";
            var resolver1 = new ValidatingResolver(Name);

            // Act
            var result = Container.Resolve <ObjectWithAttributes>(
                Override.Field(nameof(ObjectWithAttributes.Dependency), resolver1),
                Override.Dependency(other, other));

            // Verify
            Assert.IsNotNull(result);
            Assert.AreEqual(result.Dependency, Name);
            Assert.AreEqual(result.Optional, other);

            Assert.AreEqual(typeof(string), resolver1.Type);
        }
        public void Overrides_FieldOverrideAttributeResolver()
        {
            // Act
            var resolver1 = new ValidatingResolver(Name);
            var resolver2 = new ValidatingResolver(Name1);
            var result    = Container.Resolve <ObjectWithAttributes>(
                Override.Field(nameof(ObjectWithAttributes.Dependency), resolver1),
                Override.Field(nameof(ObjectWithAttributes.Optional), resolver2));

            // Verify
            Assert.IsNotNull(result);
            Assert.AreEqual(result.Dependency, Name);
            Assert.AreEqual(result.Optional, Name1);

            Assert.AreEqual(typeof(string), resolver1.Type);
            Assert.AreEqual(typeof(string), resolver2.Type);
        }