Example #1
0
        public void ExportInterfacesAndImportJson()
        {
            // assert
            var input = new InterfaceRepository();

            input.Add(new TestClassA());
            input.Add(new TestClassB());
            input.Add(new TestClassA());
            input.Add(new TestClassA());

            var binder = new TypedSerializationBinder(new List <Type> {
                typeof(TestClassA),
                typeof(TestClassB)
            });

            string json = JsonIO.ToJsonString(input, binder);

            // act
            var output = JsonIO.FromJsonString <InterfaceRepository>(json, binder);

            // Assert
            for (int i = 0; i < output.Count; i++)
            {
                Assert.AreEqual(output[i].Name, input[i].Name, $"Name property at {i} is not equal");
                Assert.AreEqual(output[i].Id, input[i].Id, $"Id property at {i} is not equal");
            }
        }