public static void AddNotTransformBeforeHavingParent() { var rect = new Mux.Markup.RectTransform { BindingContext = 0 }; var beforeHavingParent = new NotTransform(); var afterHavingParent = new NotTransform(); SynchronizationContextWaiter.Execute(() => rect.Add(beforeHavingParent)); Assert.AreEqual(0, beforeHavingParent.BindingContext); Assert.Null(beforeHavingParent.gameObject); Assert.AreEqual(0, beforeHavingParent.awakeCount); var gameObject = new UnityEngine.GameObject(); try { rect.AddToInMainThread(gameObject); Assert.AreEqual(rect.Body.gameObject, beforeHavingParent.gameObject); Assert.AreEqual(0, beforeHavingParent.awakeCount); rect.Add(afterHavingParent); Assert.AreEqual(rect.Body.gameObject, afterHavingParent.gameObject); Assert.AreEqual(0, afterHavingParent.awakeCount); rect.AwakeInMainThread(); Assert.AreEqual(1, beforeHavingParent.awakeCount); Assert.AreEqual(1, afterHavingParent.awakeCount); } finally { UnityEngine.Object.Destroy(gameObject); } }
public static void AddTransform() { var rect = new Mux.Markup.RectTransform { BindingContext = 0 }; var afterHavingParent = new Mux.Markup.RectTransform(); var beforeHavingParent = new Mux.Markup.RectTransform(); rect.Add(beforeHavingParent); Assert.AreEqual(rect, ((IInternalTransform)beforeHavingParent).Parent); CollectionAssert.Contains(rect, beforeHavingParent); var gameObject = new UnityEngine.GameObject(); try { rect.AddToInMainThread(gameObject); Assert.AreEqual(gameObject.transform, rect.Body.parent); Assert.AreEqual(rect.Body, beforeHavingParent.Body.parent); Assert.False(beforeHavingParent.Body.gameObject.activeSelf); rect.Add(afterHavingParent); Assert.AreEqual(rect, ((IInternalTransform)afterHavingParent).Parent); Assert.AreEqual(rect.Body, afterHavingParent.Body.parent); Assert.False(afterHavingParent.Body.gameObject.activeSelf); rect.AwakeInMainThread(); Assert.True(beforeHavingParent.Body.gameObject.activeSelf); Assert.True(afterHavingParent.Body.gameObject.activeSelf); } finally { UnityEngine.Object.Destroy(gameObject); } }
public static void ClearToDestroyNotTransform() { var source = new Source { Property = 0 }; var notTransform = new NotTransform(); var binding = new Binding("Property", BindingMode.OneWay, null, null, null, source); var rect = new Mux.Markup.RectTransform(); try { notTransform.SetBinding(NotTransform.BindingContextProperty, binding); rect.Add(notTransform); ((IInternalTransform)rect).Clear(); CollectionAssert.IsEmpty(rect); source.Property = 1; Assert.AreEqual(0, notTransform.BindingContext); } finally { rect.Destroy(); } }
public static void DestroyImmediate() { var source = new Source { Property = 0 }; var binding = new Binding("Property", BindingMode.OneWay, null, null, null, source); var gameObject = new UnityEngine.GameObject(); try { var parent = new Mux.Markup.RectTransform(); parent.AddTo(gameObject); var rect = new Mux.Markup.RectTransform(); parent.Add(rect); SynchronizationContextWaiter.Execute(() => { rect.SetBinding(Mux.Markup.RectTransform.BindingContextProperty, binding); rect.DestroyImmediate(); source.Property = 1; Assert.AreEqual(0, rect.BindingContext); }); Assert.AreEqual(0, parent.Body.childCount); CollectionAssert.DoesNotContain(parent, rect); } finally { UnityEngine.Object.Destroy(gameObject); } }
public static void GetEnumerator() { var rect = new Mux.Markup.RectTransform(); try { var nodes = new Mux.Markup.Node[] { new NotTransform(), new Mux.Markup.RectTransform() }; rect.Add(nodes[1]); rect.Add(nodes[0]); CollectionAssert.AreEqual(nodes, rect); } finally { rect.Destroy(); } }
public static void ReloadWithoutTransformsSource() { var rect = new Mux.Markup.RectTransform(); try { rect.Add(new Mux.Markup.RectTransform()); ((IInternalTransform)rect).Clear(); CollectionAssert.IsEmpty(rect); } finally { rect.Destroy(); } }
public static void DestroyNodeMuxInMainThread() { var rect = new Mux.Markup.RectTransform(); var source = new Source { Property = 0 }; var binding = new Binding("Property", BindingMode.OneWay, null, null, null, source); var child = new Mux.Markup.RectTransform(); rect.Add(child); child.SetBinding(Mux.Markup.RectTransform.BindingContextProperty, binding); rect.DestroyMuxInMainThread(); source.Property = 1; Assert.AreEqual(0, child.BindingContext); }
public static void SetInheritedBindingContextToChildren() { var rect = new Mux.Markup.RectTransform { BindingContext = 0 }; try { var children = new[] { new Mux.Markup.RectTransform(), new Mux.Markup.RectTransform() }; children[0].BindingContextChanged += (sender, args) => { if ((int)((Mux.Markup.RectTransform)sender).BindingContext == 1) { children[1].Destroy(); } }; foreach (var child in children) { rect.Add(child); } foreach (var child in children) { Assert.AreEqual(0, child.BindingContext); } rect.BindingContext = 1; CollectionAssert.AreEqual(new[] { children[0] }, rect); Assert.AreEqual(1, children[0].BindingContext); Assert.AreEqual(1, children[1].BindingContext); } finally { rect.Destroy(); } }
public static void AddNotTransformAfterHavingParent() { var gameObject = new UnityEngine.GameObject(); try { var rect = new Mux.Markup.RectTransform { BindingContext = 0 }; rect.AddTo(gameObject); var child = new NotTransform(); SynchronizationContextWaiter.Execute(() => rect.Add(child)); Assert.AreEqual(0, child.BindingContext); Assert.AreEqual(rect.Body.gameObject, child.gameObject); Assert.AreEqual(1, child.awakeCount); } finally { UnityEngine.Object.Destroy(gameObject); } }