Esempio n. 1
0
        public static void AssertCompilationUnit(CompilationUnitExpectation expected, CompilationUnitSyntax actual)
        {
            // Compare usings.
            IEnumerator <string> expectedUsingEnumerator             = expected.Usings.GetEnumerator();
            IEnumerator <UsingDirectiveSyntax> actualUsingEnumerator = ((IEnumerable <UsingDirectiveSyntax>)actual.Usings).GetEnumerator();

            while (expectedUsingEnumerator.MoveNext())
            {
                Assert.IsTrue(actualUsingEnumerator.MoveNext());

                Assert.AreEqual(expectedUsingEnumerator.Current, actualUsingEnumerator.Current.ToString());
            }

            Assert.IsFalse(actualUsingEnumerator.MoveNext());

            // Compare namespaces.
            IEnumerator <NamespaceExpectation>    expectedMemberEnumerator = expected.Namespaces.GetEnumerator();
            IEnumerator <MemberDeclarationSyntax> actualMemberEnumerator   = ((IEnumerable <MemberDeclarationSyntax>)actual.Members).GetEnumerator();

            while (expectedMemberEnumerator.MoveNext())
            {
                Assert.IsTrue(actualMemberEnumerator.MoveNext());

                if (actualMemberEnumerator.Current is NamespaceDeclarationSyntax actualNamespace)
                {
                    AssertNamespaceDeclaration(expectedMemberEnumerator.Current, actualNamespace);
                }

                Assert.IsInstanceOfType(actualMemberEnumerator.Current, typeof(NamespaceDeclarationSyntax));
            }

            Assert.IsFalse(actualMemberEnumerator.MoveNext());
        }
Esempio n. 2
0
        public static void ReadExpectation(ApiTypeReader typeReader, Type type, CompilationUnitExpectation expectation)
        {
            var typeNameResolver = new TypeNameResolver
            {
                SimplifyNamespaces = true,
            };

            // Act
            var compilationUnit = typeReader.ReadCompilationUnit(type, typeNameResolver);

            // Assert
            AssertCompilationUnit(expectation, compilationUnit);
        }