Exemplo n.º 1
0
        public void Validation_NoReuse()
        {
            // Arrange
            var field = Inject.Field(nameof(DependencyInjectedType.NormalField), "test");

            // Act
            Container.RegisterType <DependencyInjectedType>("1", field)
            .RegisterType <DependencyInjectedType>("2", field);
        }
Exemplo n.º 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);
        }
        public virtual void ValueNull()
        {
            // Setup
            Container.RegisterType <ObjectWithThreeFields>(
                Inject.Field(nameof(ObjectWithThreeFields.Name), null));

            // Act
            var result = Container.Resolve <ObjectWithThreeFields>();

            // Verify
            Assert.IsNotNull(result);
            Assert.IsNull(result.Field);
            Assert.IsNull(result.Name);
            Assert.IsNotNull(result.Container);
        }
        public void ResolverOverAttribute()
        {
            // Setup
            Container.RegisterType <ObjectWithAttributes>(
                Inject.Field(nameof(ObjectWithAttributes.Dependency), Resolve.Parameter(Name1)));

            // Act
            var result = Container.Resolve <ObjectWithAttributes>();

            // Verify
            Assert.IsNotNull(result);
            Assert.IsNotNull(result.Dependency);
            Assert.AreEqual(result.Dependency, Name1);
            Assert.IsNull(result.Optional);
        }
Exemplo n.º 5
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 ByNameValue()
        {
            // Setup
            var test = "test";

            Container.RegisterType <ObjectWithThreeFields>(
                Inject.Field(nameof(ObjectWithThreeFields.Field), test));

            // Act
            var result = Container.Resolve <ObjectWithThreeFields>();

            // Verify
            Assert.IsNotNull(result);
            Assert.IsNotNull(result.Field);
            Assert.AreSame(result.Field, test);
            Assert.AreEqual(result.Name, Name);
            Assert.IsNotNull(result.Container);
        }
Exemplo n.º 7
0
 public void Validation_InjectStaticField()
 {
     // Act
     Container.RegisterType <DependencyInjectedType>(
         Inject.Field(nameof(DependencyInjectedType.StaticField), "test"));
 }
Exemplo n.º 8
0
 public void Validation_InjectProtectedField()
 {
     // Act
     Container.RegisterType <DependencyInjectedType>(
         Inject.Field("ProtectedField", "test"));
 }
Exemplo n.º 9
0
 public void InjectPrivateField()
 {
     // Act
     Container.RegisterType <DependencyInjectedType>(
         Inject.Field("PrivateField", "test"));
 }
Exemplo n.º 10
0
 public void InjectReadOnlyField()
 {
     // Act
     Container.RegisterType <DependencyInjectedType>(
         Inject.Field(nameof(DependencyInjectedType.ReadonlyField), "test"));
 }
Exemplo n.º 11
0
 public void Validation_ReadOnlyProperty()
 {
     // Act
     Container.RegisterType <ObjectWithFourFields>(
         Inject.Field(nameof(ObjectWithFourFields.ReadOnlyField), "test"));
 }
Exemplo n.º 12
0
 public void Validation_InvalidValue()
 {
     // Act
     Container.RegisterType <ObjectWithThreeFields>(
         Inject.Field(nameof(ObjectWithThreeFields.Container), Name));
 }
Exemplo n.º 13
0
 public void InvalidValue()
 {
     // Act
     Container.RegisterType <Specification.Field.Injection.ObjectWithThreeFields>(
         Inject.Field(nameof(Specification.Field.Injection.ObjectWithThreeFields.Container), Name));
 }