public void when_retrieving_by_try_get_instance_for_instance_that_does_exist() { var theService = new ColorService("red"); var session = BuildSession.Empty(new ExplicitArguments().Set <IService>(theService)); session.TryGetInstance <IService>().ShouldBeTheSameAs(theService); }
public void Read_in_a_dictionary_type_from_an_attribute_normalized_memento() { string xml = @" <root> <dictionary> <Pair Key='color' Value='red'/> <Pair Key='state' Value='texas'/> <Pair Key='direction' Value='north'/> </dictionary> </root> "; XmlElement element = DataMother.BuildDocument(xml).DocumentElement; element.SetAttribute("PluggedType", typeof(ClassWithDictionary).AssemblyQualifiedName); var memento = new XmlAttributeInstanceMemento(element); Instance instance = memento.ReadInstance(new SimplePluginFactory(), typeof(ClassWithDictionary)); var theObject = (ClassWithDictionary)instance.Build(typeof(ClassWithDictionary), BuildSession.Empty()); theObject.Dictionary["color"].ShouldEqual("red"); theObject.Dictionary["state"].ShouldEqual("texas"); theObject.Dictionary["direction"].ShouldEqual("north"); }
public void SetUp() { TheDefaultGateway = new DefaultGateway(); var args = new ExplicitArguments(); args.Set <IGateway>(TheDefaultGateway); builder = new Plugin(typeof(ClassWithMixOfSetters)).CreateBuilder(); instance = new SmartInstance <ClassWithMixOfSetters>().Ctor <int>("Age").Is(34); _session = BuildSession.Empty(args); _target = null; }
public BuildUpTester() { theDefaultGateway = new DefaultGateway(); var args = new ExplicitArguments(); args.Set <IGateway>(theDefaultGateway); session = BuildSession.Empty(args); theDependencies = new DependencyCollection { { "Age", 34 } }; target = null; }
public void SetUp() { TheDefaultGateway = new DefaultGateway(); var args = new ExplicitArguments(); args.Set <IGateway>(TheDefaultGateway); _session = BuildSession.Empty(args); theDependencies = new DependencyCollection { { "Age", 34 } }; _target = null; }
public void when_building_an_instance_use_the_register_the_stack_frame() { var recordingInstance = new BuildSessionInstance1(); ConfiguredInstance instance = new ConfiguredInstance(typeof(ClassWithRule)).Ctor <Rule>("rule").Is(recordingInstance); var session = BuildSession.Empty(); session.FindObject(typeof(IClassWithRule), instance); recordingInstance.Root.ConcreteType.ShouldEqual(typeof(ClassWithRule)); recordingInstance.Root.RequestedType.ShouldEqual(typeof(IClassWithRule)); recordingInstance.Root.Name.ShouldEqual(instance.Name); recordingInstance.Current.ConcreteType.ShouldEqual(typeof(ColorRule)); recordingInstance.Current.RequestedType.ShouldEqual(typeof(Rule)); recordingInstance.Current.Name.ShouldEqual(recordingInstance.Name); }
public void Return_the_same_object_everytime_an_object_is_requested() { var count = 0; var session = BuildSession.Empty(); var instance = new LambdaInstance <ColorRule>("counting", () => { count++; return(new ColorRule("Red")); }); var result1 = session.FindObject(typeof(ColorRule), instance); var result2 = session.FindObject(typeof(ColorRule), instance); var result3 = session.FindObject(typeof(ColorRule), instance); var result4 = session.FindObject(typeof(ColorRule), instance); Assert.AreEqual(1, count); Assert.AreSame(result1, result2); Assert.AreSame(result1, result3); Assert.AreSame(result1, result4); }
public void Get_a_unique_value_for_each_individual_buildsession() { var count = 0; var session = BuildSession.Empty(); var session2 = BuildSession.Empty(); var instance = new LambdaInstance <ColorRule>("counting", () => { count++; return(new ColorRule("Red")); }); var result1 = session.FindObject(typeof(ColorRule), instance); var result2 = session.FindObject(typeof(ColorRule), instance); var result3 = session2.FindObject(typeof(ColorRule), instance); var result4 = session2.FindObject(typeof(ColorRule), instance); Assert.AreEqual(2, count); Assert.AreSame(result1, result2); Assert.AreNotSame(result1, result3); Assert.AreSame(result3, result4); }
public void Get_a_unique_value_for_each_individual_buildsession() { var count = 0; var session = BuildSession.Empty(); var session2 = BuildSession.Empty(); var instance = new LambdaInstance <ColorRule>("counting", () => { count++; return(new ColorRule("Red")); }); var result1 = session.FindObject(typeof(ColorRule), instance); var result2 = session.FindObject(typeof(ColorRule), instance); var result3 = session2.FindObject(typeof(ColorRule), instance); var result4 = session2.FindObject(typeof(ColorRule), instance); count.ShouldBe(2); result1.ShouldBeTheSameAs(result2); result1.ShouldNotBeTheSameAs(result3); result3.ShouldBeTheSameAs(result4); }
public void when_retrieving_by_try_get_named_instance_with_type_that_does_not_exist() { var session = BuildSession.Empty(); session.TryGetInstance(typeof(IService), "yo").ShouldBeNull(); }
public void when_retrieving_with_try_get_instance_for_instance_that_does_not_exists() { var session = BuildSession.Empty(); session.TryGetInstance <IService>().ShouldBeNull(); }
public void when_retrieving_by_try_get_named_instance_that_does_not_exist() { var session = BuildSession.Empty(); session.TryGetInstance <IService>("red").ShouldBeNull(); }