public void ComponentResourceManagerCreated() { CreatedInstance expectedInstance = new CreatedInstance(typeof(ResourceManager), new object[0], "resources", false); CreatedInstance instance = base.ComponentCreator.CreatedInstances[0]; Assert.AreEqual(expectedInstance, instance); }
public void AddedComponentsContainsTextBox() { CreatedInstance instance = ComponentCreator.GetCreatedInstance(typeof(TextBox)); AddedComponent component = new AddedComponent(instance.Object as IComponent, "textBox1"); Assert.Contains(component, ComponentCreator.AddedComponents); }
public void InstanceType() { List <object> args = new List <object>(); int width = 300; int height = 400; args.Add(width); args.Add(height); CreatedInstance expectedInstance = new CreatedInstance(typeof(Size), args, null, false); Assert.AreEqual(expectedInstance, ComponentCreator.CreatedInstances[0]); }
public void LocalVariableInstance() { string s = "abc"; CreatedInstance instance = new CreatedInstance(typeof(string), new object[0], "localVariable", false); instance.Object = s; componentCreator.CreatedInstances.Add(instance); List <object> expectedArgs = new List <object>(); expectedArgs.Add(s); string code = "TestClass(localVariable)"; CallExpression callExpression = PythonParserHelper.GetCallExpression(code); List <object> args = deserializer.GetArguments(callExpression); Assert.AreEqual(expectedArgs, args); }
// -------------------------------------------------------------------- /// <summary> /// Create an instance of a the 'Instance' class based on the /// Node type passed in information. Then populate the instance based /// on the child XML nodes. /// </summary> /// <param name="Node"></param> /// <param name="Parent"></param> /// <param name="ParentInstance"></param> /// <param name="HostComponent"></param> /// <returns></returns> // -------------------------------------------------------------------- private Instance CreateInstance(XmlNode Node, XmlNode Parent, Instance ParentInstance, ApsimComponent ParentComponent) { Type ClassType = GetTypeOfChild(Node, ParentInstance); if (ClassType == null) { throw new Exception("Cannot find a class called: " + Node.Name); } object Model = Activator.CreateInstance(ClassType); Instance CreatedInstance; if (Model.GetType().IsSubclassOf(typeof(Instance))) { CreatedInstance = (Instance)Model; } else { CreatedInstance = new Instance(Model); } //if (CreatedInstance.GetType().IsSubclassOf(typeof(DerivedInstance))) //{ // ((DerivedInstance)CreatedInstance).Initialise(Node, ParentInstance, ParentComponent); //} if (CreatedInstance != null) { CreatedInstance.Initialise(XmlHelper.Name(Node), ParentInstance, ParentComponent); GetAllProperties(CreatedInstance, Parent); GetAllEventHandlers(CreatedInstance); GetAllEvents(CreatedInstance); PopulateParams(CreatedInstance, Node, ParentComponent); } else { throw new Exception("Class " + Node.Name + " must be derived from the \"Instance\" class"); } return(CreatedInstance); }
public void TextBoxObjectMatchesObjectAddedToComponentCreator() { CreatedInstance instance = ComponentCreator.GetCreatedInstance(typeof(TextBox)); Assert.AreSame(TextBox, instance.Object as TextBox); }
public void ButtonInstance() { CreatedInstance expectedInstance = new CreatedInstance(typeof(Button), new object[0], "button1", false); Assert.AreEqual(expectedInstance, ComponentCreator.CreatedInstances[0]); }
public void TextBoxInstanceCreated() { CreatedInstance instance = new CreatedInstance(typeof(TextBox), new List <object>(), "textBox1", false); Assert.Contains(instance, ComponentCreator.CreatedInstances); }