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); }
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); }
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); }
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); }
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); }
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); }
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); }
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); }
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); }
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); }
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); }
public DiBindingActionBuilder(DiBinding binding) { this.binding = binding; }
private DiBindingActionBuilder <T> AddBinding(DiBinding binding) { containerBuilder.AddBinding(binding); return(new DiBindingActionBuilder <T>(binding)); }