public void PropertyWithInfo() { // Register Item mapper.RegisterItem <DebugItem, DebugItemState, DebugItemInfo>(extensionPack, "Debug"); // Register Property mapper.RegisterItemPropertyI <DebugItemProperty1, DebugItemInfoProperty1>(extensionPack, "Debug"); // Attach Property mapper.AttachItemProperty <DebugItem, DebugItemProperty1>(extensionPack, "Debug"); DebugItem item = new DebugItem(mapper, Vector2.Zero, Angle.Right); DebugItem item2 = new DebugItem(mapper, Vector2.Zero, Angle.Right); Assert.AreEqual(1, item.Properties.Count()); var prop = item.GetProperty <DebugItemProperty1>(); Assert.IsNotNull(prop); var state = item.GetState(); Assert.AreEqual(0, state.Properties.Count()); var stateProp = state.GetProperty <DebugItemStateProperty1>(); Assert.IsNull(stateProp); var info = item.GetItemInfo(item2); Assert.AreEqual(1, info.Properties.Count()); var infoProp = info.GetProperty <DebugItemInfoProperty1>(); Assert.IsNotNull(infoProp); }
public void CreateInstance() { mapper.RegisterItem <DebugItem, DebugItemState, DebugItemInfo>(extensionPack, "Debug"); Assert.AreEqual(1, mapper.Items.Count()); DebugItem item = new DebugItem(mapper, Vector2.Zero, Angle.Right); DebugItem item2 = new DebugItem(mapper, Vector2.Zero, Angle.Right); var state = item.GetState(); Assert.AreEqual(typeof(DebugItemState), state.GetType()); var info = item.GetItemInfo(item2); Assert.AreEqual(typeof(DebugItemInfo), info.GetType()); }
public void PropertyWithInfoAndDelegateWrongType() { // Register Item mapper.RegisterItem <DebugItem, DebugItemState, DebugItemInfo>(extensionPack, "Debug"); // Register Property int caller = 0; mapper.RegisterItemPropertyI <DebugItemProperty1, DebugItemInfoProperty1>(extensionPack, "Debug", (i, p, o) => { caller++; return(new DebugItemInfoProperty1Specialized(i, (DebugItemProperty1)p, o)); }); // Attach Property mapper.AttachItemProperty <DebugItem, DebugItemProperty1>(extensionPack, "Debug"); DebugItem item = new DebugItem(mapper, Vector2.Zero, Angle.Right); DebugItem item2 = new DebugItem(mapper, Vector2.Zero, Angle.Right); Assert.AreEqual(1, item.Properties.Count()); var prop = item.GetProperty <DebugItemProperty1>(); Assert.IsNotNull(prop); var state = item.GetState(); Assert.AreEqual(0, state.Properties.Count()); var stateProp = state.GetProperty <DebugItemStateProperty1>(); Assert.IsNull(stateProp); try { var info = item.GetItemInfo(item2); Assert.Fail(); } catch (NotSupportedException) { } Assert.AreEqual(1, caller); }
public void PropertyOnlyDelegateNull() { // Register Item mapper.RegisterItem <DebugItem, DebugItemState, DebugItemInfo>(extensionPack, "Debug"); // Register Property mapper.RegisterItemProperty <DebugItemProperty1>(extensionPack, "Debug"); // Attach Property int caller = 0; mapper.AttachItemProperty <DebugItem, DebugItemProperty1>(extensionPack, "Debug", (i) => { caller++; return(null); }); DebugItem item = new DebugItem(mapper, Vector2.Zero, Angle.Right); DebugItem item2 = new DebugItem(mapper, Vector2.Zero, Angle.Right); Assert.AreEqual(2, caller); Assert.AreEqual(0, item.Properties.Count()); var prop = item.GetProperty <DebugItemProperty1>(); Assert.IsNull(prop); var state = item.GetState(); Assert.AreEqual(0, state.Properties.Count()); var stateProp = state.GetProperty <DebugItemStateProperty1>(); Assert.IsNull(stateProp); var info = item.GetItemInfo(item2); Assert.AreEqual(0, info.Properties.Count()); var infoProp = info.GetProperty <DebugItemInfoProperty1>(); Assert.IsNull(infoProp); }