コード例 #1
0
        public void UnknownDeclarationUseLoadingTest()
        {
            var walker = SetupDeclarationUseWalker();

            var node = SyntaxTreeHelper.GetTypeSyntax("Unknown");

            var declarationUse = walker.Visit(node);

            Assert.NotNull(declarationUse);
            Assert.IsType <UnknownDeclarationUse>(declarationUse);
            Assert.NotNull(declarationUse.Declaration);
            Assert.IsType <UnknownDeclaration>(declarationUse.Declaration);
        }
コード例 #2
0
        public void GenericParameterDeclarationUseLoadingTest()
        {
            var declarationUseStatement = "TName";
            IGenericParameterDeclaration genericParameterDeclaration = null;

            var walker = SetupDeclarationUseWalker(ctx =>
            {
                genericParameterDeclaration = SetupGenericParameterDeclaration(ctx, declarationUseStatement);
            });

            var node = SyntaxTreeHelper.GetTypeSyntax(declarationUseStatement);

            var declarationUse = walker.Visit(node);

            Assert.NotNull(declarationUse);
            Assert.IsType <GenericParameterDeclarationUse>(declarationUse);
            Assert.Same(genericParameterDeclaration, declarationUse.Declaration);
        }
コード例 #3
0
        public void GenericDeclarationUseLoadingTest(string declarationName, string genericParametersText, int genericParams)
        {
            var declarationMock = new Mock <IClassDeclaration>();

            var walker = SetupDeclarationUseWalker(resolverSetup: resolver =>
            {
                if (genericParams == 0)
                {
                    resolver
                    .Setup(r => r.Resolve(declarationName, It.IsAny <IDeclaration <SyntaxNode> >()))
                    .Returns(declarationMock.Object);
                    resolver
                    .Setup(r => r.Resolve(declarationName, Array.Empty <IDeclarationUse <SyntaxNode> >(), It.IsAny <IDeclaration <SyntaxNode> >()))
                    .Returns(declarationMock.Object);
                }
                else
                {
                    resolver
                    .Setup(r => r.Resolve(declarationName, It.IsAny <IReadOnlyList <IDeclarationUse <SyntaxNode> > >(), It.IsAny <IDeclaration <SyntaxNode> >()))
                    .Returns(declarationMock.Object);
                }
            });

            var node = SyntaxTreeHelper.GetTypeSyntax($"{declarationName}{genericParametersText}");

            var declarationUse = walker.Visit(node);

            Assert.NotNull(declarationUse);
            Assert.Same(declarationMock.Object, declarationUse.Declaration);

            var genericDeclarationUse = Assert.IsType <GenericDeclarationUse>(declarationUse);

            Assert.NotNull(genericDeclarationUse.GenericParameters);
            Assert.Equal(genericParams, genericDeclarationUse.GenericParameters.Count);

            foreach (var genericParameter in genericDeclarationUse.GenericParameters)
            {
                Assert.IsType <PredefinedDeclarationUse>(genericParameter);
            }
        }
コード例 #4
0
        public void ArrayDeclarationUseLoadingTest(string declarationName, string arrayText, int dimCount)
        {
            var declaration = Mock.Of <IClassDeclaration>();

            var walker = SetupDeclarationUseWalker(resolverSetup: resolver =>
            {
                resolver
                .Setup(r => r.Resolve(declarationName, It.IsAny <IDeclaration <SyntaxNode> >()))
                .Returns(declaration);
            });

            var node = SyntaxTreeHelper.GetTypeSyntax($"{declarationName}{arrayText}");

            var declarationUse = walker.Visit(node);

            Assert.NotNull(declarationUse);
            Assert.Same(declaration, declarationUse.Declaration);

            Assert.NotNull(declarationUse.ArraySpecification);
            Assert.NotNull(declarationUse.ArraySpecification.SyntaxNodeProvider);

            Assert.Equal(dimCount, declarationUse.ArraySpecification.ArrayCount);
        }