示例#1
0
        public void PropertyElement_WithNullFields_CreatesNullElement()
        {
            var container = new Container();
            var element   = new PropertyElement();

            element.SetTarget(container);

            Assert.That(element.Query <NullElement <SomeType> >().ToList().Count, Is.EqualTo(1));
            Assert.That(element.Query <NullElement <SomeOtherType> >().ToList().Count, Is.EqualTo(1));
        }
示例#2
0
        public void PropertyElement_FieldWithHideInInspector_AreNotShown()
        {
            var withHideInInspectorField = new PropertyElement();

            withHideInInspectorField.SetTarget(new Types.FieldWithHideInInspector());
            var customInspectorElements = withHideInInspectorField.Query <CustomInspectorElement>().ToList();

            Assert.That(customInspectorElements.Count, Is.EqualTo(0));
            Assert.That(withHideInInspectorField.childCount, Is.EqualTo(2));
            Assert.That(withHideInInspectorField.Query <IntegerField>().First(), Is.Null);
        }
示例#3
0
        public void CodeInspector_WithBindings_GetsValuesSet()
        {
            var fieldInspector = new PropertyElement();

            fieldInspector.SetTarget(new Types.CodeInspectorType()
            {
                Float  = 25.0f,
                Int    = 15,
                String = "Yup"
            });

            var customInspectorElements = fieldInspector.Query <CustomInspectorElement>().ToList();

            Assert.That(customInspectorElements.Count, Is.EqualTo(1));
            var customInspectorElement = customInspectorElements[0].ElementAt(0);

            Assert.That(customInspectorElement.childCount, Is.EqualTo(3));
            var floatField = customInspectorElement.ElementAt(0) as FloatField;

            Assert.That(floatField.value, Is.EqualTo(25.0f));
            var intField = customInspectorElement.ElementAt(1) as IntegerField;

            Assert.That(intField.value, Is.EqualTo(15));
            var stringField = customInspectorElement.ElementAt(2) as TextField;

            Assert.That(stringField.value, Is.EqualTo("Yup"));
        }
示例#4
0
        public void CustomInspector_CallingDefaultOnEachField_MimicsGenericInspector()
        {
            var noInspector = new PropertyElement();

            noInspector.SetTarget(new Types.NoInspectorType());
            Assert.That(noInspector.Query <CustomInspectorElement>().ToList().Count, Is.EqualTo(0));
            Assert.That(noInspector.childCount, Is.EqualTo(3));

            var allDefaultInspector = new PropertyElement();

            allDefaultInspector.SetTarget(new Types.AllDefaultInspectorType());
            var customInspectorElements = allDefaultInspector.Query <CustomInspectorElement>().ToList();

            Assert.That(customInspectorElements.Count, Is.EqualTo(1));
            var customInspectorElement = customInspectorElements[0].ElementAt(0);

            Assert.That(customInspectorElement.childCount, Is.EqualTo(3));

            for (var i = 0; i < 3; ++i)
            {
                var lhs = noInspector.ElementAt(i);
                var rhs = customInspectorElement.ElementAt(i);
                Assert.That(lhs.GetType(), Is.EqualTo(rhs.GetType()));
                Assert.That(lhs.childCount, Is.EqualTo(rhs.childCount));
                Assert.That((lhs as BindableElement)?.bindingPath, Is.EqualTo((rhs as BindableElement)?.bindingPath));
            }
        }
示例#5
0
        public void DefaultInspector_ForField_MimicsGenericInspector()
        {
            var fieldInspector = new PropertyElement();

            fieldInspector.SetTarget(new Types.DefaultFieldInspector()
            {
                NoInspectorType      = new Types.NoInspectorType(),
                DefaultInspectorType = new Types.DefaultInspectorType()
            });

            var noInspector =
                fieldInspector.Q <Foldout>(nameof(Types.DefaultFieldInspector.NoInspectorType));

            Assert.That(noInspector.Query <CustomInspectorElement>().ToList().Count, Is.EqualTo(0));
            Assert.That(noInspector.childCount, Is.EqualTo(3));

            var customInspectorElements = fieldInspector.Query <CustomInspectorElement>().ToList();

            Assert.That(customInspectorElements.Count, Is.EqualTo(1));
            var customInspectorElement = customInspectorElements[0].Q <Foldout>(nameof(Types.DefaultFieldInspector.DefaultInspectorType));

            Assert.That(customInspectorElement.childCount, Is.EqualTo(3));

            for (var i = 0; i < 3; ++i)
            {
                var lhs = noInspector.ElementAt(i);
                var rhs = customInspectorElement.ElementAt(i);
                Assert.That(lhs.GetType(), Is.EqualTo(rhs.GetType()));
                Assert.That(lhs.childCount, Is.EqualTo(rhs.childCount));
                Assert.That((lhs as BindableElement)?.bindingPath, Is.EqualTo((rhs as BindableElement)?.bindingPath));
            }
        }
        public void ResettingTargets_FromCustomInspector_ShouldNotThrow()
        {
            var value   = new NestedPropertyElementWithInterfaces();
            var element = new PropertyElement();

            Assert.DoesNotThrow(() => element.SetTarget(value));
            Assert.DoesNotThrow(() => element.Query <CustomInspectorElement>().ForEach(i => (i as IBinding).Update()));
        }
示例#7
0
        public void NullInspector_ForRootType_HasNoChildren()
        {
            var noOverrideInspector = new PropertyElement();

            noOverrideInspector.SetTarget(new Types.NullInspectorType());
            var customInspectorElements = noOverrideInspector.Query <CustomInspectorElement>().ToList();

            Assert.That(customInspectorElements.Count, Is.EqualTo(1));
            var customInspectorElement = customInspectorElements[0];

            Assert.That(customInspectorElement.childCount, Is.EqualTo(0));
        }
        public void DefaultInspector_ForCollectionField_MimicsGenericInspector()
        {
            var fieldInspector = new PropertyElement();

            fieldInspector.SetTarget(new Types.TypeWithCollections());

            var customInspectorElements = fieldInspector.Query <CustomInspectorElement>().ToList();

            Assert.That(customInspectorElements[0].childCount, Is.EqualTo(1));
            Assert.That(customInspectorElements[0][0], Is.TypeOf <Label>());
            Assert.That(customInspectorElements[1].childCount, Is.EqualTo(1));
            Assert.That(customInspectorElements[1][0], Is.TypeOf <CustomInspectorElement.DefaultInspectorElement>());
            Assert.That(customInspectorElements[2].childCount, Is.EqualTo(0));
        }
示例#9
0
        public void NullElement_WithUnderlyingDataNotNullAnymore_UpdatesCorrectly()
        {
            var container = new Container();
            var element   = new PropertyElement();

            element.SetTarget(container);

            var someTypes = new List <NullElement <SomeType> >();

            element.Query <NullElement <SomeType> >().ToList(someTypes);
            Assert.That(someTypes.Count, Is.EqualTo(1));

            var someOtherTypes = new List <NullElement <SomeOtherType> >();

            element.Query <NullElement <SomeOtherType> >().ToList(someOtherTypes);
            Assert.That(someOtherTypes.Count, Is.EqualTo(1));

            container.NonNullFieldWithNestedNullField.NestedField = new SomeOtherType();
            foreach (IBinding binding in someTypes)
            {
                binding.Update();
            }

            foreach (IBinding binding in someOtherTypes)
            {
                binding.Update();
            }
            someTypes.Clear();
            someOtherTypes.Clear();

            element.Query <NullElement <SomeType> >().ToList(someTypes);
            Assert.That(someTypes.Count, Is.EqualTo(1));

            element.Query <NullElement <SomeOtherType> >().ToList(someOtherTypes);
            Assert.That(someOtherTypes.Count, Is.EqualTo(0));

            container.NullField = new SomeType {
                NestedField = new SomeOtherType()
            };
            foreach (IBinding binding in someTypes)
            {
                binding.Update();
            }

            foreach (IBinding binding in someOtherTypes)
            {
                binding.Update();
            }
            someTypes.Clear();
            someOtherTypes.Clear();

            element.Query <NullElement <SomeType> >().ToList(someTypes);
            Assert.That(someTypes.Count, Is.EqualTo(0));

            element.Query <NullElement <SomeOtherType> >().ToList(someOtherTypes);
            Assert.That(someOtherTypes.Count, Is.EqualTo(0));
        }
示例#10
0
        public void NullInspector_ForField_HasNoChildren()
        {
            var fieldInspector = new PropertyElement();

            fieldInspector.SetTarget(new Types.NullFieldInspector
            {
                NullInspectorType = new Types.NullInspectorType()
            });

            var customInspectorElements = fieldInspector.Query <CustomInspectorElement>().ToList();

            Assert.That(customInspectorElements.Count, Is.EqualTo(1));
            var customInspectorElement = customInspectorElements[0];

            Assert.That(customInspectorElement.childCount, Is.EqualTo(0));
        }
        public void EnumFields_WhenUnderlyingTypeIsLong_AreSkipped()
        {
            var element = new PropertyElement();

            element.SetTarget(new TypeWithLargeEnums());
#if !UNITY_2020_2_OR_NEWER
            Assert.That(element.Query <EnumField>().ToList().Count, Is.EqualTo(0));
            Assert.That(element.Query <EnumFlagsField>().ToList().Count, Is.EqualTo(0));
#else
            Assert.That(element.Query <EnumField>().ToList().Count, Is.EqualTo(1));
            Assert.That(element.Query <EnumFlagsField>().ToList().Count, Is.EqualTo(1));
#endif

            element.SetTarget(new TypeWithLargeAndRegularEnums());
#if !UNITY_2020_2_OR_NEWER
            Assert.That(element.Query <EnumField>().ToList().Count, Is.EqualTo(1));
            Assert.That(element.Query <EnumFlagsField>().ToList().Count, Is.EqualTo(1));
#else
            Assert.That(element.Query <EnumField>().ToList().Count, Is.EqualTo(2));
            Assert.That(element.Query <EnumFlagsField>().ToList().Count, Is.EqualTo(2));
#endif
        }