public void InitType_ShouldNotInitializeXContainerTypes()
        {
            var cache = new XmlSerializerCache();

            cache.InitType(typeof(XElement));

            Assert.IsFalse(cache.typeMembers.ContainsKey(typeof(XElement)));
        }
Exemplo n.º 2
0
        public void InitType_ShouldNotInfinitelyInitializeRecursiveTypes()
        {
            var cache = new XmlSerializerCache();

            cache.InitType(typeof(RecursiveType));

            var members = cache.typeMembers[typeof(RecursiveType)];

            Assert.AreEqual(typeof(RecursiveType), members.Item1.Single().FieldType);
            Assert.AreEqual(typeof(RecursiveType), members.Item2.Single().PropertyType);
        }
        public void InitType_ShouldHandleConcurrentInitializations()
        {
            var cache = new XmlSerializerCache();

            Parallel.For(0, 10, _ =>
            {
                cache.InitType(typeof(SimpleType));

                var members = cache.typeMembers[typeof(SimpleType)];
                Assert.NotNull(members);
                Assert.AreEqual(nameof(SimpleType.SimpleField), members.Item1.Single().Name);
                Assert.AreEqual(nameof(SimpleType.SimpleProperty), members.Item2.Single().Name);
            });
        }