Ejemplo n.º 1
0
        public void FromType_generic_type_definition_nested_generic()
        {
            var      ti   = typeof(C <,> .D <,>).GetTypeInfo();
            TypeName name = TypeName.FromType(typeof(C <,> .D <,>));

            // proof, for reference:
            Assume.HasCount(4, ti.GetGenericArguments());
            Assume.Equal("D`2", ti.Name);
            Assume.Equal("Carbonfrost.UnitTests.DotNet.TypeNameTests+C`2+D`2", ti.FullName);

            Assert.True(name.IsGenericType);
            Assert.True(name.IsGenericTypeDefinition);
            Assert.Equal("Carbonfrost.UnitTests.DotNet.TypeNameTests+C`2+D`2", name.FullName);
            Assert.Equal(4, name.GenericParameterCount); // inherited generics
        }
Ejemplo n.º 2
0
        public void FromType_should_get_closed_inherited_generic_arguments()
        {
            var s = new C <int, long> .D <string, string>();

            // proof, for reference:
            var args = s.GetType().GetTypeInfo().GetGenericArguments();

            Assume.Equal(new [] { typeof(int), typeof(long), typeof(string), typeof(string) }, args);

            var t = (GenericInstanceTypeName)TypeName.FromType(s.GetType());

            Assert.HasCount(4, t.GenericArguments);
            Assert.Equal(new [] { "Int32", "Int64", "String", "String" },
                         t.GenericArguments.Select(u => u.Name).ToArray());
        }
Ejemplo n.º 3
0
        public void Xmlns_should_update_name_on_ancestor_taking_name_context(string newOwner)
        {
            var doc = new DomDocument();

            doc.NameContext = DomNameContext.Xml;
            var element = doc.AppendElement("ancestor").AppendElement("parent").AppendElement("a:b");

            Assume.Equal("a:b", element.LocalName);

            doc.QuerySelector(newOwner).Attribute("xmlns:a", "namespace-a");

            // The name gets rewritten to use the namespace semantics
            Expect(element.NameContext).ToBe.InstanceOf(typeof(XmlNameContext));
            Expect(element.Name).ToBe.InstanceOf(typeof(DomName.QName));
            Expect(element.NamespaceUri).ToBe.EqualTo("namespace-a");
            Expect(element.LocalName).ToBe.EqualTo("b");
        }
Ejemplo n.º 4
0
        public void Xmlns_should_update_name_on_taking_as_a_descendant_from_unlinked_ownership(string newOwner)
        {
            var doc = new DomDocument();

            doc.NameContext = DomNameContext.Xml;
            doc.AppendElement("ancestor").AppendElement("parent");
            doc.DocumentElement.Attribute("xmlns:a", "namespace-a");

            var orphan = doc.CreateElement("a:b");

            Assume.Equal("a:b", orphan.LocalName);

            doc.QuerySelector(newOwner).Append(orphan);

            // The name gets rewritten to use the namespace semantics
            Expect(orphan.LocalName).ToBe.EqualTo("b");
            Expect(orphan.NamespaceUri).ToBe.EqualTo("namespace-a");
        }
Ejemplo n.º 5
0
        public void Glob_assumptions_for_fileobject()
        {
            // Sanity checks on the implementation of FileObject

            var e = Fixture1Enumerator();
            var f = Fixture1();

            string[] results = Glob.FilterDirectory(Glob.Anything,
                                                    "\\",
                                                    e.FileExists,
                                                    e).ToArray();
            Assume.Equal(new [] {
                "/",
                "/a",
                "/a/b.txt",
                "/a/c.csv",
                "/a/d.txt",
                "/a/e",
                "/a/e/f",
                "/a/e/f/g",
                "/a/e/f/g/h.txt",
                "/a/e/f/g/i.txt",
                "/a/e/f/j",
                "/a/e/.k",
                "/a/e/l.csv",
            }.Sorted(), f.Visit().Keys.Sorted().ToArray(), FileNameComparison);

            Assume.Equal(new [] {
                "/a"
            },
                         e.EnumerateDirectories("/").ToArray(), FileNameComparison);

            Assume.Equal(new [] {
                "/a/e"
            },
                         e.EnumerateDirectories("/a").ToArray(),
                         FileNameComparison);
            Assume.Equal(new [] {
                "/a/b.txt",
                "/a/c.csv",
                "/a/d.txt"
            }, e.EnumerateFiles("/a").ToArray(), FileNameComparison);
        }
Ejemplo n.º 6
0
        public void BaseUri_should_inherit_on_base_uri_nulled_out() {
            var example1 = new Uri("https://example.com");
            var example2 = new Uri("https://test.example");

            DomDocument doc = new DomDocument();
            var html = doc.CreateElement("html");
            html.BaseUri = example1;

            var body = doc.CreateElement("body");
            body.BaseUri = example2;

            doc.Append(html);
            html.Append(body);

            // Setting this explicitly show return to the inherited balue
            Assume.Equal(example2, body.BaseUri);
            body.BaseUri = null;

            Assert.Equal(example1, body.BaseUri);
        }