Пример #1
0
        public void DeserializeInvalidDependencies_ComponentsArePreserved()
        {
            var container = TestHierarchicalComponentContainer.CreateInstance();

            TestHierarchicalComponentContainer.DeserializeFromJson(container, $"{{\"Dependencies\": [123, \"abc\"], \"Components\": [{{\"$type\": {typeof(ComponentA).GetFullyQualifedAssemblyTypeName().DoubleQuotes()}}}]}}");
            Assert.That(container.HasComponent <ComponentA>(), Is.True);
        }
Пример #2
0
        public void DeserializeNullDependencies_DependenciesArePreserved()
        {
            var container = TestHierarchicalComponentContainer.CreateInstance();

            TestHierarchicalComponentContainer.DeserializeFromJson(container, $"{{\"Dependencies\": [null, \"GlobalObjectId_V1-0-00000000000000000000000000000000-0-0\"], \"Components\": []}}");
            Assert.That(container.Dependencies, Is.EqualTo(new ITestComponent[] { null, null }));
        }
Пример #3
0
        public void DeserializeInvalidJson_DoesNotThrow()
        {
            var container = TestHierarchicalComponentContainer.CreateInstance();

            LogAssert.Expect(LogType.Error, $"Failed to deserialize memory container of type '{typeof(TestHierarchicalComponentContainer).FullName}':\nInput json was invalid. ExpectedType=[Value] ActualType=[EndObject] ActualChar=['}}'] at Line=[1] at Character=[47]");
            TestHierarchicalComponentContainer.DeserializeFromJson(container, "{\"Dependencies\": [], \"Components\": [{\"$type\": }, {\"$type\": }]}");
        }
Пример #4
0
        public void DeserializeInvalidJson_DoesNotThrow()
        {
            var container = TestHierarchicalComponentContainer.CreateInstance();

            LogAssert.Expect(LogType.Exception, new Regex("InvalidJsonException: Input json was invalid.*"));
            TestHierarchicalComponentContainer.DeserializeFromJson(container, "{\"Dependencies\": [], \"Components\": [{\"$type\": }, {\"$type\": }]}");
        }
        public void DeserializeInvalidComponents_OtherComponentsArePreserved()
        {
            var container = TestHierarchicalComponentContainer.CreateInstance();

            TestHierarchicalComponentContainer.DeserializeFromJson(container, $"{{\"Dependencies\": [], \"Components\": [{{\"$type\": {typeof(ComponentA).GetQualifedAssemblyTypeName().DoubleQuotes()}}}, {{\"$type\": \"Some.InvalidComponent.Name, Unknown.Assembly\"}}]}}");
            Assert.That(container.HasComponent <ComponentA>(), Is.True);
        }
        public void DeserializeInvalidJson_DoesNotThrow()
        {
            var container = TestHierarchicalComponentContainer.CreateInstance();

            LogAssert.Expect(LogType.Error, new Regex("Failed to deserialize memory container.*"));
            TestHierarchicalComponentContainer.DeserializeFromJson(container, "{\"Dependencies\": [], \"Components\": [{\"$type\": }, {\"$type\": }]}");
        }
Пример #7
0
        public void DeserializeInvalidComponents_OtherComponentsArePreserved()
        {
            var container = TestHierarchicalComponentContainer.CreateInstance();

            LogAssert.Expect(LogType.Error, $"Failed to deserialize memory container of type '{typeof(TestHierarchicalComponentContainer).FullName}':\nSystem.InvalidOperationException: PropertyContainer.Construct failed to construct DstType=[{typeof(ITestComponent).FullName}]. Could not resolve type from TypeName=[Some.InvalidComponent.Name, Unknown.Assembly].");
            TestHierarchicalComponentContainer.DeserializeFromJson(container, $"{{\"Dependencies\": [], \"Components\": [{{\"$type\": {typeof(ComponentA).GetFullyQualifedAssemblyTypeName().DoubleQuotes()}}}, {{\"$type\": \"Some.InvalidComponent.Name, Unknown.Assembly\"}}]}}");
            Assert.That(container.HasComponent <ComponentA>(), Is.True);
        }
Пример #8
0
        public void DeserializeInvalidDependencies_ComponentsArePreserved()
        {
            var container = TestHierarchicalComponentContainer.CreateInstance();

            LogAssert.Expect(LogType.Error, new Regex("While deserializing memory container of type.*"));
            TestHierarchicalComponentContainer.DeserializeFromJson(container, $"{{\"Dependencies\": [123, \"abc\"], \"Components\": [{{\"$type\": {typeof(ComponentA).GetAssemblyQualifiedTypeName().DoubleQuotes()}}}]}}");
            Assert.That(container.HasComponent <ComponentA>(), Is.True);
        }
        public void DeserializeInvalidDependencies_ComponentsArePreserved()
        {
            var container = TestHierarchicalComponentContainer.CreateInstance();

#if UNITY_2020_1_OR_NEWER
            LogAssert.Expect(LogType.Error, new Regex("Failed to deserialize memory container.*"));
#endif
            TestHierarchicalComponentContainer.DeserializeFromJson(container, $"{{\"Dependencies\": [123, \"abc\"], \"Components\": [{{\"$type\": {typeof(ComponentA).GetQualifedAssemblyTypeName().DoubleQuotes()}}}]}}");
            Assert.That(container.HasComponent <ComponentA>(), Is.True);
        }
        public void DeserializeNullDependencies_DependenciesArePreserved()
        {
            var container = TestHierarchicalComponentContainer.CreateInstance();

            TestHierarchicalComponentContainer.DeserializeFromJson(container, $"{{\"Dependencies\": [null, \"GlobalObjectId_V1-0-00000000000000000000000000000000-0-0\"], \"Components\": []}}");
#if UNITY_2020_1_OR_NEWER
            Assert.That(container.Dependencies.Select(d => d.asset), Is.EqualTo(new TestHierarchicalComponentContainer[] { null, null }));
#else
            Assert.That(container.Dependencies, Is.EqualTo(new TestHierarchicalComponentContainer[] { null, null }));
#endif
        }
Пример #11
0
        public void DeserializeMultipleTimes_ShouldNotAppendData()
        {
            var container = TestHierarchicalComponentContainer.CreateInstance();

            Assert.That(container.HasComponent <ComponentA>(), Is.False);
            Assert.That(container.Components.Count, Is.Zero);
            TestHierarchicalComponentContainer.DeserializeFromJson(container, $"{{\"Dependencies\": [], \"Components\": [{{\"$type\": {typeof(ComponentA).GetFullyQualifedAssemblyTypeName().DoubleQuotes()}}}]}}");
            Assert.That(container.HasComponent <ComponentA>(), Is.True);
            Assert.That(container.Components.Count, Is.EqualTo(1));
            TestHierarchicalComponentContainer.DeserializeFromJson(container, $"{{\"Dependencies\": [], \"Components\": [{{\"$type\": {typeof(ComponentA).GetFullyQualifedAssemblyTypeName().DoubleQuotes()}}}]}}");
            Assert.That(container.HasComponent <ComponentA>(), Is.True);
            Assert.That(container.Components.Count, Is.EqualTo(1));
        }
Пример #12
0
        public void ComponentSerialization()
        {
            var container = TestHierarchicalComponentContainer.CreateInstance();

            container.SetComponent(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
                }
            });

            var json = container.SerializeToJson();

            Assert.That(json.Length, Is.GreaterThan(3));

            var deserializedContainer = TestHierarchicalComponentContainer.CreateInstance();

            TestHierarchicalComponentContainer.DeserializeFromJson(deserializedContainer, json);

            var component = deserializedContainer.GetComponent <ComplexComponent>();

            Assert.That(component.Integer, Is.EqualTo(1));
            Assert.That(component.Float, Is.EqualTo(123.456f));
            Assert.That(component.String, Is.EqualTo("test"));
            Assert.That(component.Nested.Integer, Is.EqualTo(42));
            Assert.That(component.ListInteger, Is.EquivalentTo(new List <int> {
                1, 1, 2, 3, 5, 8, 13
            }));

            var reserializedJson = deserializedContainer.SerializeToJson();

            Assert.That(reserializedJson, Is.EqualTo(json));
        }