Beispiel #1
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);
    }
Beispiel #2
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);
    }
Beispiel #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);
    }
Beispiel #4
0
    public void DIBinding_InGlobal()
    {
        // Arrange
        var reflector = new Reflector();
        var container = new DiContainer();
        var key       = typeof(Test);
        var binding   = new DiBinding(reflector, container, key, null, null);


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

        // Assert
        Assert.AreEqual(LifeTime.Global, actual);
    }
Beispiel #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);
    }
Beispiel #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);
    }
Beispiel #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);
    }
Beispiel #8
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);
    }