Exemple #1
0
        public void CreateTypeResolverReturnsCorrectResult()
        {
            var assemblyToScanForEvents =
                typeof(XmlContentSerializerTests).Assembly;
            var mappings =
                (from t in assemblyToScanForEvents.GetExportedTypes()
                 from a in t.GetCustomAttributes(
                     typeof(XmlRootAttribute), inherit: false)
                 .Cast <XmlRootAttribute>()
                 where t.IsDefined(a.GetType(), inherit: false)
                 select new TypeResolutionEntry(a.Namespace, a.ElementName, t))
                .ToArray();

            Assert.NotEmpty(mappings);
            var sut =
                XmlContentSerializer.CreateTypeResolver(
                    assemblyToScanForEvents);

            Array.ForEach(mappings, entry =>
            {
                var expected = entry.ResolvedType;
                var actual   = sut.Resolve(entry.LocalName, entry.XmlNamespace);
                Assert.Equal(expected, actual);
            });
        }
Exemple #2
0
        public void CreateTypeResolverWithAssemblyWithoutAnnotatedTypesThrows()
        {
            var assembly = typeof(Version).Assembly;

            Assert.Empty(
                from t in assembly.GetExportedTypes()
                from a in t.GetCustomAttributes(
                    typeof(XmlRootAttribute), inherit: false)
                .Cast <XmlRootAttribute>()
                where t.IsDefined(a.GetType(), inherit: false)
                select t);

            Assert.Throws <ArgumentException>(() =>
                                              XmlContentSerializer.CreateTypeResolver(assembly));
        }
Exemple #3
0
 public void CreateTypeResolverWithNullAssemblyThrows()
 {
     Assert.Throws <ArgumentNullException>(() =>
                                           XmlContentSerializer.CreateTypeResolver(null));
 }