コード例 #1
0
        public void DeserializeInvalidJson_ShouldNotThrowException()
        {
            var container = TestComponentContainer.CreateInstance();

            LogAssert.Expect(LogType.Error, $"Failed to deserialize memory container of type '{typeof(TestComponentContainer).FullName}':\nInput json was invalid. ExpectedType=[Value] ActualType=[EndObject] ActualChar=['}}'] at Line=[1] at Character=[47]");
            TestComponentContainer.DeserializeFromJson(container, "{\"Dependencies\": [], \"Components\": [{\"$type\": }, {\"$type\": }]}");
        }
        public void DeserializeInvalidJson_ShouldNotThrowException()
        {
            var container = ScriptableObject.CreateInstance <TestComponentContainer>();

            LogAssert.Expect(LogType.Error, "Input json was invalid. ExpectedType=[Value] ActualType=[EndObject] ActualChar=['}'] at Line=[1] at Character=[47]");
            TestComponentContainer.DeserializeFromJson(container, "{\"Dependencies\": [], \"Components\": [{\"$type\": }, {\"$type\": }]}");
        }
コード例 #3
0
        public void DeserializeInvalidDependency_ShouldNotResetEntireBuildSettings()
        {
            var container = TestComponentContainer.CreateInstance();

            TestComponentContainer.DeserializeFromJson(container, $"{{\"Dependencies\": [null, \"\", \"bleh\"], \"Components\": [{{\"$type\": \"{typeof(ComponentA).FullName}, {typeof(ComponentA).Assembly.GetName().Name}\"}}]}}");
            Assert.That(container.HasComponent <ComponentA>(), Is.True);
            Assert.That(container.Dependencies.Count, Is.Zero);
        }
コード例 #4
0
        public void DeserializeInvalidComponent_ShouldNotResetEntireBuildSettings()
        {
            var container = TestComponentContainer.CreateInstance();

            LogAssert.Expect(LogType.Error, $"Failed to deserialize memory container of type '{typeof(TestComponentContainer).FullName}':\nSystem.InvalidOperationException: PropertyContainer.Construct failed to construct DstType=[{typeof(ITestComponent).FullName}]. Could not resolve type from TypeName=[Some.InvalidComponent.Name, Unknown.Assembly].");
            TestComponentContainer.DeserializeFromJson(container, $"{{\"Dependencies\": [], \"Components\": [{{\"$type\": \"{typeof(ComponentA).FullName}, {typeof(ComponentA).Assembly.GetName().Name}\"}}, {{\"$type\": \"Some.InvalidComponent.Name, Unknown.Assembly\"}}]}}");
            Assert.That(container.HasComponent <ComponentA>(), Is.True);
        }
        public void DeserializeInvalidDependency_ShouldNotResetEntireBuildSettings()
        {
            var container = ScriptableObject.CreateInstance <TestComponentContainer>();

            TestComponentContainer.DeserializeFromJson(container, "{\"Dependencies\": [null, \"\"], \"Components\": [{\"$type\": \"Unity.Build.Tests.ComponentA, Unity.Build.Tests\"}]}");
            Assert.That(container.HasComponent <ComponentA>(), Is.True);
            Assert.That(container.GetDependencies().Count, Is.EqualTo(2));
        }
        public void DeserializeInvalidComponent_ShouldNotResetEntireBuildSettings()
        {
            var container = ScriptableObject.CreateInstance <TestComponentContainer>();

            LogAssert.Expect(LogType.Error, new Regex("Encountered problems while deserializing in memory container of type TestComponentContainer:.*"));
            TestComponentContainer.DeserializeFromJson(container, "{\"Dependencies\": [], \"Components\": [{\"$type\": \"Unity.Build.Tests.ComponentA, Unity.Build.Tests\"}, {\"$type\": \"Some.InvalidComponent.Name, Unknown.Assembly\"}]}");
            Assert.That(container.HasComponent <ComponentA>(), Is.True);
        }
コード例 #7
0
        public void DeserializeMultipleTimes_ShouldNotAppendData()
        {
            var container = TestComponentContainer.CreateInstance();

            Assert.That(container.HasComponent <ComponentA>(), Is.False);
            Assert.That(container.Components.Count, Is.Zero);
            TestComponentContainer.DeserializeFromJson(container, $"{{\"Dependencies\": [], \"Components\": [{{\"$type\": \"{typeof(ComponentA).FullName}, {typeof(ComponentA).Assembly.GetName().Name}\"}}]}}");
            Assert.That(container.HasComponent <ComponentA>(), Is.True);
            Assert.That(container.Components.Count, Is.EqualTo(1));
            TestComponentContainer.DeserializeFromJson(container, $"{{\"Dependencies\": [], \"Components\": [{{\"$type\": \"{typeof(ComponentA).FullName}, {typeof(ComponentA).Assembly.GetName().Name}\"}}]}}");
            Assert.That(container.HasComponent <ComponentA>(), Is.True);
            Assert.That(container.Components.Count, Is.EqualTo(1));
        }
        public void DeserializeMultipleTimes_ShouldNotAppendData()
        {
            var container = ScriptableObject.CreateInstance <TestComponentContainer>();

            Assert.That(container.HasComponent <ComponentA>(), Is.False);
            Assert.That(container.Components.Count, Is.Zero);
            TestComponentContainer.DeserializeFromJson(container, "{\"Dependencies\": [], \"Components\": [{\"$type\": \"Unity.Build.Tests.ComponentA, Unity.Build.Tests\"}]}");
            Assert.That(container.HasComponent <ComponentA>(), Is.True);
            Assert.That(container.Components.Count, Is.EqualTo(1));
            TestComponentContainer.DeserializeFromJson(container, "{\"Dependencies\": [], \"Components\": [{\"$type\": \"Unity.Build.Tests.ComponentA, Unity.Build.Tests\"}]}");
            Assert.That(container.HasComponent <ComponentA>(), Is.True);
            Assert.That(container.Components.Count, Is.EqualTo(1));
        }
コード例 #9
0
        public void ComponentSerialization()
        {
            var container = TestComponentContainer.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 = TestComponentContainer.CreateInstance();

            TestComponentContainer.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));
        }