Ejemplo n.º 1
0
    public void DIBinding_To_IsReferenceTypeException()
    {
        // Arrange
        var actual    = false;
        var instance  = new TestStruct();
        var reflector = new Reflector();
        var container = new DiContainer();
        var key       = typeof(Test);
        var binding   = new DiBinding(reflector, container, key, null, null);

        binding.InGlobal();

        // Act
        try
        {
            binding.To(instance);
        }
        catch (ArgumentException)
        {
            actual = true;
        }

        // Assert
        Assert.IsTrue(actual);
    }
Ejemplo n.º 2
0
    public void DIBinding_ToFactory_IsInvalidOperationException()
    {
        // Arrange
        var actual    = false;
        var instance  = new TestFactory();
        var reflector = new Reflector();
        var container = new DiContainer();
        var key       = typeof(TestFactory);
        var binding   = new DiBinding(reflector, container, key, null, null);

        binding.InGlobal().ToFactory(instance);

        // Act
        try
        {
            binding.ToFactory(instance);
        }
        catch (InvalidOperationException)
        {
            actual = true;
        }

        // Assert
        Assert.IsTrue(actual);
    }
Ejemplo n.º 3
0
    public void DIBinding_ToFactoryGeneric_ReturnIDIBinder()
    {
        // Arrange
        var reflector = new Reflector();
        var container = new DiContainer();
        var key       = typeof(TestFactory);
        var binding   = new DiBinding(reflector, container, key, null, null);

        // Act
        var actual = binding.InGlobal().ToFactory <TestFactory>();

        // Assert
        Assert.AreEqual(binding, actual);
    }
Ejemplo n.º 4
0
    public void DIBinding_InLocal()
    {
        // Arrange
        var reflector = new Reflector();
        var container = new DiContainer();
        var key       = typeof(Test);
        var binding   = new DiBinding(reflector, container, key, null, null);

        // Act
        binding.InLocal();
        var actual = binding.LifeTime;

        // Assert
        Assert.AreEqual(LifeTime.Local, actual);
    }
Ejemplo n.º 5
0
    public void DIBinding_ToFactoryGenericAndToSingletonAndGetValues()
    {
        // Arrange
        var expected  = typeof(InstanceProviderSingleton);
        var reflector = new Reflector();
        var container = new DiContainer();
        var key       = typeof(TestFactory);
        var binding   = new DiBinding(reflector, container, key, null, null);

        // Act
        binding.InGlobal().ToFactory <TestFactory>().ToSingleton();
        var provider = binding.Values.FirstOrDefault();
        var actual   = provider?.GetType();

        // Assert
        Assert.AreEqual(expected, actual);
    }
Ejemplo n.º 6
0
    public void DIBinding_ToFactoryGeneric_Resolver()
    {
        // Arrange
        var actual    = false;
        var reflector = new Reflector();
        var container = new DiContainer();
        var key       = typeof(TestFactory);
        var binding   = new DiBinding(reflector, container, key, null, Resolver);

        // Act
        binding.InGlobal().ToFactory <TestFactory>();

        void Resolver(IBinding unused) => actual = true;

        // Assert
        Assert.IsTrue(actual);
    }
Ejemplo n.º 7
0
    public void DIBinding_ToAndGetValues()
    {
        // Arrange
        var expected  = typeof(InstanceProvider);
        var instance  = new Test(null);
        var reflector = new Reflector();
        var container = new DiContainer();
        var key       = typeof(Test);
        var binding   = new DiBinding(reflector, container, key, null, null);

        // Act
        binding.InGlobal().To(instance);
        var provider = binding.Values.FirstOrDefault();
        var actual   = provider?.GetType();

        // Assert
        Assert.AreEqual(expected, actual);
    }
Ejemplo n.º 8
0
    public void DIBinding_ConstructorParam3_Exception()
    {
        // Arrange
        var actual    = false;
        var reflector = new Reflector();
        var container = new DiContainer();

        // Act
        try
        {
            var unused = new DiBinding(reflector, container, null, null, null);
        }
        catch (ArgumentNullException)
        {
            actual = true;
        }

        // Assert
        Assert.IsTrue(actual);
    }
Ejemplo n.º 9
0
    public void DIBinding_ConstructorParam2_Exception()
    {
        // Arrange
        var actual    = false;
        var reflector = new Reflector();
        var key       = typeof(Test);

        // Act
        try
        {
            var unused = new DiBinding(reflector, null, key, null, null);
        }
        catch (ArgumentNullException)
        {
            actual = true;
        }

        // Assert
        Assert.IsTrue(actual);
    }
Ejemplo n.º 10
0
    public void DIBinding_ToGeneric_NotLifeTimeException()
    {
        // Arrange
        var actual    = false;
        var reflector = new Reflector();
        var container = new DiContainer();
        var key       = typeof(Test);
        var binding   = new DiBinding(reflector, container, key, null, null);

        // Act
        try
        {
            binding.To <Test>();
        }
        catch (InvalidOperationException)
        {
            actual = true;
        }

        // Assert
        Assert.IsTrue(actual);
    }
Ejemplo n.º 11
0
    public void DIBinding_ToFactory_IsNotNullException()
    {
        // Arrange
        var actual    = false;
        var reflector = new Reflector();
        var container = new DiContainer();
        var key       = typeof(TestFactory);
        var binding   = new DiBinding(reflector, container, key, null, null);

        binding.InGlobal();

        // Act
        try
        {
            binding.ToFactory(null);
        }
        catch (ArgumentNullException)
        {
            actual = true;
        }

        // Assert
        Assert.IsTrue(actual);
    }
Ejemplo n.º 12
0
 public DiBindingActionBuilder(DiBinding binding)
 {
     this.binding = binding;
 }
Ejemplo n.º 13
0
        private DiBindingActionBuilder <T> AddBinding(DiBinding binding)
        {
            containerBuilder.AddBinding(binding);

            return(new DiBindingActionBuilder <T>(binding));
        }