Пример #1
0
        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();
            }
        }
Пример #2
0
        public static void Destroy()
        {
            var source = new Source {
                Property = 0
            };
            var binding    = new Binding("Property", BindingMode.OneWay, null, null, null, source);
            var gameObject = new UnityEngine.GameObject();

            try
            {
                SynchronizationContextWaiter.Execute(() =>
                {
                    var parent = new Mux.Markup.RectTransform();
                    parent.AddTo(gameObject);
                    var rect = new Mux.Markup.RectTransform();
                    parent.Add(rect);

                    rect.SetBinding(Mux.Markup.RectTransform.BindingContextProperty, binding);
                    rect.Destroy();
                    source.Property = 1;
                    Assert.AreEqual(0, rect.BindingContext);
                    CollectionAssert.DoesNotContain(parent, rect);
                });
            }
            finally
            {
                UnityEngine.Object.Destroy(gameObject);
            }
        }
Пример #3
0
        public static void Y()
        {
            var former = new Mux.Markup.Sized();
            var later  = new Mux.Markup.Sized();
            var rect   = new Mux.Markup.RectTransform {
                BindingContext = 0
            };

            try
            {
                Assert.AreEqual(1, ((Mux.Markup.Sized)rect.Y).Index);
                Assert.AreEqual(100, ((Mux.Markup.Sized)rect.Y).SizeDelta);

                rect.Y = former;
                Assert.AreEqual(rect.Body, former.Body);
                Assert.AreEqual(0, former.BindingContext);

                rect.Y = later;
                Assert.IsNull(former.Body);
                Assert.AreEqual(rect.Body, later.Body);
                Assert.AreEqual(0, later.BindingContext);
            }
            finally
            {
                rect.Destroy();
            }
        }
Пример #4
0
        public static void ReplaceTransformsSource()
        {
            var bindingSource = new Source {
                Property = 1
            };
            var binding = new Binding("Property", BindingMode.OneWay, null, null, null, bindingSource);
            var rect    = new Mux.Markup.RectTransform();

            try
            {
                var selector         = new DataTemplateSelector();
                var templated        = new WithProperty();
                var transformsSource = new ObservableCollection <int> {
                    2
                };
                templated.SetBinding(WithProperty.PropertyProperty, binding);

                selector.template      = new DataTemplate(() => templated);
                rect.TransformsSource  = transformsSource;
                rect.TransformTemplate = selector;
                var oldTemplated = templated;
                templated              = new WithProperty();
                selector.template      = new DataTemplate(() => templated);
                transformsSource[0]    = 3;
                bindingSource.Property = 4;

                Assert.AreEqual(1, oldTemplated.Property);
                Assert.AreEqual(3, templated.BindingContext);
            }
            finally
            {
                rect.Destroy();
            }
        }
Пример #5
0
        public static void RemoveTransformsSource()
        {
            var bindingSource = new Source {
                Property = 1
            };
            var binding = new Binding("Property", BindingMode.OneWay, null, null, null, bindingSource);
            var rect    = new Mux.Markup.RectTransform();

            try
            {
                var templated        = new WithProperty();
                var transformsSource = new ObservableCollection <int> {
                    2
                };
                templated.SetBinding(WithProperty.PropertyProperty, binding);

                rect.TransformsSource  = transformsSource;
                rect.TransformTemplate = new DataTemplate(() => templated);
                transformsSource.RemoveAt(0);
                bindingSource.Property = 3;

                Assert.AreEqual(1, templated.Property);
            }
            finally
            {
                rect.Destroy();
            }
        }
Пример #6
0
        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();
            }
        }
Пример #7
0
        public static void SetNullToTransformsSource()
        {
            var rect = new Mux.Markup.RectTransform();

            try
            {
                rect.TransformTemplate = new DataTemplate(() => new Mux.Markup.RectTransform());
                rect.TransformsSource  = new[] { 0 };
                rect.TransformsSource  = null;
            }
            finally
            {
                rect.Destroy();
            }
        }
Пример #8
0
        public static void SetInheritedBindingContextToY()
        {
            var rect = new Mux.Markup.RectTransform {
                BindingContext = 0
            };

            try
            {
                Assert.AreEqual(0, rect.Y.BindingContext);
                rect.BindingContext = 1;
                Assert.AreEqual(1, rect.Y.BindingContext);
            }
            finally
            {
                rect.Destroy();
            }
        }
Пример #9
0
        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();
            }
        }
Пример #10
0
        public static void InsertTransformsSourceWithoutParent()
        {
            var rect = new Mux.Markup.RectTransform();

            try
            {
                var templated        = new Mux.Markup.RectTransform();
                var transformsSource = new ObservableCollection <int>();

                rect.TransformsSource  = transformsSource;
                rect.TransformTemplate = new DataTemplate(() => templated);
                transformsSource.Add(0);

                Assert.AreEqual(0, templated.BindingContext);
            }
            finally
            {
                rect.Destroy();
            }
        }
Пример #11
0
        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();
            }
        }
Пример #12
0
        public static void LocalEulerAngles()
        {
            var rect = new Mux.Markup.RectTransform();

            try
            {
                SynchronizationContextWaiter.Execute(() =>
                {
                    Assert.AreEqual(UnityEngine.Vector3.zero, rect.LocalEulerAngles);

                    rect.LocalEulerAngles = new UnityEngine.Vector3(7, 8, 9);
                    var expectedEuler     = new UnityEngine.Vector3(7, 8, 9);
                    Assert.That(rect.LocalEulerAngles, Is.EqualTo(expectedEuler).Using(Vector3EqualityComparer.Instance));
                });

                var expectedRotation = new UnityEngine.Quaternion(0.1f, 0.1f, 0.1f, 1f);
                Assert.That(rect.LocalRotation, Is.EqualTo(expectedRotation).Using(QuaternionEqualityComparer.Instance));
            }
            finally
            {
                rect.Destroy();
            }
        }