Ejemplo n.º 1
0
        public void ComponentValues_AreValid()
        {
            var container = TestHierarchicalComponentContainer.CreateInstance();
            var component = new ComplexComponent
            {
                Integer = 1,
                Float   = 123.456f,
                String  = "test",
                Nested  = new ComponentA
                {
                    Integer = 42
                },
                ListInteger = new List <int> {
                    1, 1, 2, 3, 5, 8, 13
                }
            };

            container.SetComponent(component);

            var value = container.GetComponent <ComplexComponent>();

            Assert.That(value.Integer, Is.EqualTo(1));
            Assert.That(value.Float, Is.EqualTo(123.456f));
            Assert.That(value.String, Is.EqualTo("test"));
            Assert.That(value.Nested.Integer, Is.EqualTo(42));
            Assert.That(value.ListInteger, Is.EquivalentTo(new List <int> {
                1, 1, 2, 3, 5, 8, 13
            }));
        }
Ejemplo n.º 2
0
        public void CopyVisitor_DoesNotCopyCollectionReferences()
        {
            var list = new List <int> {
                1, 2, 3
            };
            var component = new ComplexComponent {
                ListInteger = list
            };
            var container = TestHierarchicalComponentContainer.CreateInstance(c => c.SetComponent(component));
            var value     = container.GetComponent <ComplexComponent>();

            Assert.That(value, Is.Not.SameAs(component));
            Assert.That(value, Is.EqualTo(component));
            Assert.That(value.ListInteger, Is.Not.SameAs(list));
            Assert.That(value.ListInteger, Is.EqualTo(list));

            list.AddRange(new int[] { 4, 5, 6 });
            Assert.That(value.ListInteger, Is.Not.SameAs(list));
            Assert.That(value.ListInteger, Is.Not.EqualTo(list));

            value = container.GetComponent <ComplexComponent>();
            Assert.That(value.ListInteger, Is.Not.SameAs(list));
            Assert.That(value.ListInteger, Is.Not.EqualTo(list));

            container.SetComponent(component);
            value = container.GetComponent <ComplexComponent>();
            Assert.That(value.ListInteger, Is.Not.SameAs(list));
            Assert.That(value.ListInteger, Is.EqualTo(list));
        }