Пример #1
0
        public override bool Equals(object obj)
        {
            SimpleTreeType other = obj as SimpleTreeType;

            if (other == null ||
                this.Id != other.Id ||
                this.Name != other.Name ||
                this.Children.Count != other.Children.Count)
            {
                return(false);
            }

            for (int i = 0; i < this.Children.Count; i++)
            {
                if (!object.Equals(this.Children[i], other.Children[i]))
                {
                    return(false);
                }
            }

            return(true);
        }
        public void SimpleTreePopulation()
        {
            List<Tuple<SimpleTreeType, string>> testCases = new List<Tuple<SimpleTreeType, string>>() {
                new Tuple<SimpleTreeType, string>(new SimpleTreeType(), "{\"Name\":null,\"Children\":[]}"),
                new Tuple<SimpleTreeType, string>(new SimpleTreeType(setValues:true), "{\"id\":5,\"name\":\"Root\",\"children\":[{\"id\":6,\"name\":\"Child1\",\"children\":[]},{\"id\":7,\"name\":\"Child2\",\"children\":[]}]}"),
            };

            // Need to ensure that the type is registered as a table to force the id property check
            DefaultSerializer.SerializerSettings.ContractResolver.ResolveTableName(typeof(SimpleTreeType));

            foreach (var testCase in testCases)
            {
                var input = testCase.Item2;
                var expected = testCase.Item1;

                SimpleTreeType actual = new SimpleTreeType();
                actual.Name = "Not the original name";
                DefaultSerializer.Deserialize(input, actual);

                Assert.AreEqual(actual, expected);
            }
        }