public void TestConfiguration() { try { var injector = SimpleDiFactory.Load <DefaultInjector>(typeof(Configuration.Program.GenericTestLoader)); injector.AssertParameterNotNull(nameof(injector), "inject was not created."); if (injector.Constructors.Count > 0 && injector.Constructors[0].Count > 0) { injector.Constructors[0][0].Value = "test".ToCharArray(); var output = injector.MakeObject(injector.Constructors[0]); output.GetType() .AssertEquals <ApplicationException>(typeof(System.String), "output is not a System.String"); ((System.String)output).AssertEquals <ApplicationException>("test", $"output has wrong value ({output})."); } else { throw new ApplicationException("Could not load configuration into injector."); } Console.WriteLine("Successfully instantiated the object defined in the config file!"); } catch (Exception ex) { Console.WriteLine(ex.ToString()); } finally { Console.ReadKey(); } }
public void JsonLoadTestDefaultConstructor() { var jsonInjectableBase = SimpleDiFactory.Load <JsonInjectableBase>(typeof(JsonDependencyLoader)); Assert.IsNotNull(jsonInjectableBase, "Loader returned null."); Assert.IsInstanceOfType(jsonInjectableBase, typeof(JsonInjectableBase), "Returned object is not of type JsonInjectableBase"); Assert.AreEqual("GPS.SimpleDI", jsonInjectableBase.TypeNamespace); var instance = jsonInjectableBase.MakeObject(); Assert.IsNotNull(instance, "Could not create instance of JsonInjectableBase."); Assert.IsInstanceOfType(instance, typeof(JsonInjectableBase)); }
public void JsonLoadTestDefaultStringConstructor() { string json = @" { 'TypeNamespace': 'GPS.SimpleDI', 'TypeName': 'GPS.SimpleDI.JsonInjectableBase' } "; var jsonInjectableBase = SimpleDiFactory.Load <JsonInjectableBase>(typeof(JsonDependencyLoader), json); Assert.IsNotNull(jsonInjectableBase, "Loader returned null."); Assert.IsInstanceOfType(jsonInjectableBase, typeof(JsonInjectableBase)); Assert.AreEqual("GPS.SimpleDI", jsonInjectableBase.TypeNamespace); var instance = jsonInjectableBase.MakeObject(); Assert.IsNotNull(instance, "Could not create instance of JsonInjectableBase."); Assert.IsInstanceOfType(instance, typeof(JsonInjectableBase)); }
public void LoadSample() { var sampleInjectable = SimpleDiFactory.Load <SampleInjectable>(typeof(SampleLoader)); Assert.IsNotNull(sampleInjectable, "Loader returned null."); Assert.IsInstanceOfType(sampleInjectable, typeof(SampleInjectable)); var instance = sampleInjectable.MakeObject(new List <Parameter> { new Parameter { TypeNamespace = "mscorlib", TypeName = "System.String", Name = "value", Value = "Created!" } }) as Test.Test; Assert.IsNotNull(instance, "Could not create instance of JsonInjectableBase."); Assert.IsInstanceOfType(instance, typeof(Test.Test)); Assert.AreEqual("Created!", instance.value); }