public void ConfigurationIsFluent() { var container = new MicroIocContainer(); var config1 = container.GetConfiguration(); var config2 = config1.Configure <Bar>(new InjectedProperty <Foo>("Foo", new Foo())); Assert.AreSame(config1, config2); }
public void ConfigurationHoldsReferenceToContainer() { var container = new MicroIocContainer(); var configuration = container.GetConfiguration(); var configType = configuration.GetType(); var fieldInfo = configType.GetField("_container", BindingFlags.NonPublic | BindingFlags.Instance); Assert.AreSame(container, fieldInfo.GetValue(configuration)); }
public void BuildUpAppliesDependencyProperty() { var container = new MicroIocContainer(); container.GetConfiguration() .Property<TestClassWithProperty, string>(x => x.CustomerName, "TestCustomerName"); var obj = new TestClassWithProperty(); container.BuildUp(obj); Assert.AreEqual("TestCustomerName", obj.CustomerName); }
public void BuildUpAppliesDependencyProperty() { var container = new MicroIocContainer(); container.GetConfiguration() .Property <TestClassWithProperty, string>(x => x.CustomerName, "TestCustomerName"); var obj = new TestClassWithProperty(); container.BuildUp(obj); Assert.AreEqual("TestCustomerName", obj.CustomerName); }
public void BuildUpDoesNotApplyStandardProperty() { var container = new MicroIocContainer(); container.GetConfiguration() .Property<TestClassWithProperty, string>(x => x.CustomerName, "TestCustomerName") .Property<TestClassWithProperty, string>(x => x.NotInjected, "NotInjected"); var obj = new TestClassWithProperty(); container.BuildUp(obj); Assert.IsNull(obj.NotInjected, string.Format("Should have been null, but was {0}", obj.NotInjected)); }
public void ConfiguredConstructorParameterInjectionGetsResolved() { const string connectionString = "Data Source=myServerAddress;Initial Catalog=myDataBase;User Id=myUsername;Password=myPassword;"; var container = new MicroIocContainer(); container.GetConfiguration() .ConstructorParam <SampleRepository, string>("connectionString", connectionString); var instance = container.Resolve <SampleRepository>(); Assert.AreEqual(connectionString, instance.ConnectionString); }
public void ConfiguredPropertyInjectionGetsResolved() { const string customerName = "Bloggs & Co"; var container = new MicroIocContainer() .Register <IFirst, First>() .Register <ISecond, Second>(); container.GetConfiguration() .Property <TestClassWithProperties, string>(c => c.CustomerName, customerName); var instance = container.Resolve <TestClassWithProperties>(); Assert.AreEqual(customerName, instance.CustomerName); }
public void BuildUpDoesNotApplyStandardProperty() { var container = new MicroIocContainer(); container.GetConfiguration() .Property <TestClassWithProperty, string>(x => x.CustomerName, "TestCustomerName") .Property <TestClassWithProperty, string>(x => x.NotInjected, "NotInjected"); var obj = new TestClassWithProperty(); container.BuildUp(obj); Assert.IsNull(obj.NotInjected, string.Format("Should have been null, but was {0}", obj.NotInjected)); }
public void ContainerResolvesConfiguredPropertyIfSpecified() { var first = new First(); var container = new MicroIocContainer() .Register <IFirst, First>() .Register <ISecond, Second>(); container.GetConfiguration() .Configure <TestClassWithProperties>(new InjectedProperty <string>("CustomerName", "Anything")) .Configure <TestClassWithProperties>(new InjectedProperty <First>("FirstProperty", first)); container.GetConfiguration() .Configure <TestClassWithPropertiesAndConstructor>(new InjectedProperty <string>("CustomerName", "Whatever")); var instance = container.Resolve <TestClassWithProperties>(); Assert.AreSame(first, instance.FirstProperty); var otherInstance = container.Resolve <TestClassWithPropertiesAndConstructor>(); Assert.AreNotSame(first, otherInstance.FirstProperty); }
public void BuildUpResolvesAllInjectedProperties() { var container = new MicroIocContainer() .Register<IFirst, First>() .Register<ISecond, Second>(); container.GetConfiguration() .Property<TestClassWithProperties, string>(x => x.CustomerName, "TestCustomerName"); var obj = new TestClassWithProperties(); container.BuildUp(obj); Assert.AreEqual("TestCustomerName", obj.CustomerName); Assert.IsNotNull(obj.FirstProperty, "FirstProperty shouldn't be null"); Assert.IsInstanceOfType(obj.FirstProperty, typeof(First), "FirstProperty should a 'First' object"); Assert.IsNotNull(obj.SecondProperty, "SecondProperty shouldn't be null"); Assert.IsInstanceOfType(obj.SecondProperty, typeof(Second), "SecondProperty should a 'Second' object"); }
public void BuildUpResolvesAllInjectedProperties() { var container = new MicroIocContainer() .Register <IFirst, First>() .Register <ISecond, Second>(); container.GetConfiguration() .Property <TestClassWithProperties, string>(x => x.CustomerName, "TestCustomerName"); var obj = new TestClassWithProperties(); container.BuildUp(obj); Assert.AreEqual("TestCustomerName", obj.CustomerName); Assert.IsNotNull(obj.FirstProperty, "FirstProperty shouldn't be null"); Assert.IsInstanceOfType(obj.FirstProperty, typeof(First), "FirstProperty should a 'First' object"); Assert.IsNotNull(obj.SecondProperty, "SecondProperty shouldn't be null"); Assert.IsInstanceOfType(obj.SecondProperty, typeof(Second), "SecondProperty should a 'Second' object"); }