public void TestExtendingTypeAtRunrimeAndAddOpenEngSBModelEntries() { Type type = HelpMethods.ImplementTypeDynamicly(typeof(Entry1), typeof(IOpenEngSBModel)); Object entryObject = Activator.CreateInstance(type); Entry1 entry = (Entry1)entryObject; entry.key = "test"; entry.value = 1; List <openEngSBModelEntry> elements = new List <openEngSBModelEntry>(); openEngSBModelEntry osbEntry = new openEngSBModelEntry(); osbEntry.key = "key"; osbEntry.type = "type"; osbEntry.value = "value"; elements.Add(osbEntry); IOpenEngSBModel entryOpenEngSB = (IOpenEngSBModel)entry; entryOpenEngSB.OpenEngSBModelTail = elements; String objString = marshaller.MarshallObject(entry); IOpenEngSBModel objUnmarshalled = (IOpenEngSBModel)marshaller.UnmarshallObject(objString, type); Entry1 entryUnmarshalled = (Entry1)objUnmarshalled; Assert.IsTrue(objString.ToUpper().Contains("OPENENGSBMODELTAIL")); Assert.IsTrue(entryObject is Entry1); Assert.IsTrue(entryObject is IOpenEngSBModel); Assert.AreEqual(elements.Count, objUnmarshalled.OpenEngSBModelTail.Count); Assert.AreEqual(objUnmarshalled.OpenEngSBModelTail[0].key, osbEntry.key); Assert.AreEqual(objUnmarshalled.OpenEngSBModelTail[0].type, osbEntry.type); Assert.AreEqual(objUnmarshalled.OpenEngSBModelTail[0].value, osbEntry.value); Assert.AreEqual(entryUnmarshalled.key, entry.key); Assert.AreEqual(entryUnmarshalled.value, entry.value); }
/// <summary> /// Add a OpenEngSBModel to an Object /// </summary> /// <typeparam name="ReturnTyp">The Type that gets exptendet with the OpenEngSBModel Interface</typeparam> /// <param name="element">The object, which gets extended</param> /// <param name="models">The OpenEngSBEntries</param> /// <returns>The object with the OpenEngSBModel</returns> public static ReturnTyp AddOpenEngSBModel <ReturnTyp>(this ReturnTyp element, List <openEngSBModelEntry> models) { Type openEngSBModelType = HelpMethods.ImplementTypeDynamicly(element.GetType(), typeof(IOpenEngSBModel)); IOpenEngSBModel tmpElement = element.ConvertOSBType(openEngSBModelType) as IOpenEngSBModel; tmpElement.OpenEngSBModelTail = models; return((ReturnTyp)tmpElement); }
public void TestExtendMethodThatAddsOpenEngSBModel() { Entry1 testentry = new Entry1(); testentry.key = "Test"; testentry.value = 2; List <openEngSBModelEntry> elements = new List <openEngSBModelEntry>(); openEngSBModelEntry osbEntry = new openEngSBModelEntry(); osbEntry.key = "key"; osbEntry.type = "type"; osbEntry.value = "value"; elements.Add(osbEntry); testentry = testentry.AddOpenEngSBModel <Entry1>(elements); IOpenEngSBModel objUnmarshalled = testentry as IOpenEngSBModel; Assert.AreEqual(elements.Count, objUnmarshalled.OpenEngSBModelTail.Count); Assert.AreEqual(objUnmarshalled.OpenEngSBModelTail[0].key, osbEntry.key); Assert.AreEqual(objUnmarshalled.OpenEngSBModelTail[0].type, osbEntry.type); Assert.AreEqual(objUnmarshalled.OpenEngSBModelTail[0].value, osbEntry.value); Assert.AreEqual(((Entry1)objUnmarshalled).key, testentry.key); Assert.AreEqual(((Entry1)objUnmarshalled).value, testentry.value); }