private static void TestScriptNamespaceOnParameter(string source, bool withSemanticModel, string expectedFullName)
        {
            var tree = CSharpSyntaxTree.ParseText(source);

            // Loading MSCoreLib
            var semanticModel = withSemanticModel
                ? (CSharpCompilation.Create("TestAssembly")
                   .AddReferences(
                       MetadataReference.CreateFromFile(
                           typeof(object).Assembly.Location))
                   .AddSyntaxTrees(tree).AddScriptNamespaceReference().GetSemanticModel(tree))
                : null;

            var node = new NodeLocator(tree).LocateFirst(typeof(ConstructorDeclarationSyntax));

            Assert.IsNotNull(node);

            var ctorDeclarationNode = node as ConstructorDeclarationSyntax;

            Assert.IsNotNull(ctorDeclarationNode);

            var translationUnitFactory = new ConstructorDefinitionTranslationUnitFactory(ctorDeclarationNode, semanticModel, true).Create();

            Assert.IsNotNull(translationUnitFactory, "Translation unit expected to be created!");

            var ctorTranslationUnit = (translationUnitFactory as ConstructorDefinitionTranslationUnit);

            Assert.IsNotNull(ctorTranslationUnit, $"Expecting a translation unit of type {typeof(ConstructorDefinitionTranslationUnit).Name}!");

            var translationUnit = MockedConstructorDefinitionTranslationUnit.Create(ctorTranslationUnit);

            Assert.IsNotNull(translationUnit.Arguments);
            Assert.AreEqual(1, translationUnit.Arguments.Count(), "Expecting 1 argument!");

            var argumentTranslationUnit = translationUnit.Arguments.ElementAt(0) as ArgumentDefinitionTranslationUnit;

            Assert.IsNotNull(argumentTranslationUnit, $"Expected argument to be of type {typeof(ArgumentDefinitionTranslationUnit).Name}");

            var mockedArgumentTranslationUnit = MockedArgumentDefinitionTranslationUnit.Create(argumentTranslationUnit);

            Assert.IsNotNull(mockedArgumentTranslationUnit.VariableDeclaration);

            var variableDeclarationTranslationUnit = mockedArgumentTranslationUnit.VariableDeclaration as VariableDeclarationTranslationUnit;

            Assert.IsNotNull(variableDeclarationTranslationUnit);

            var mockedVariableDeclarationTranslationUnit = MockedVariableDeclarationTranslationUnit.Create(variableDeclarationTranslationUnit);

            Assert.IsNotNull(mockedVariableDeclarationTranslationUnit.Type, "Expecting a type!");

            var typeIdentifierTranslationUnit = mockedVariableDeclarationTranslationUnit.Type as TypeIdentifierTranslationUnit;

            Assert.IsNotNull(typeIdentifierTranslationUnit, $"Expected argument to be of type {typeof(TypeIdentifierTranslationUnit).Name}");

            var typeFullName = typeIdentifierTranslationUnit.Translate();

            Assert.AreEqual(expectedFullName, typeFullName, "Expected ScriptNamespace overriden type to be used!");
        }
예제 #2
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="node"></param>
        public override void VisitConstructorDeclaration(ConstructorDeclarationSyntax node)
        {
            var constructorDefinitionTranslationUnit = new ConstructorDefinitionTranslationUnitFactory(node, this.semanticModel, this.generateTranslationUniOnProtectedMembers).Create();

            if (constructorDefinitionTranslationUnit == null)
            {
                // When the factory returns null, then the member is not exposed, thus we do not generate it in the translation tree
                return;
            }

            this.classDeclaration.AddConstructorDeclaration(constructorDefinitionTranslationUnit);

            this.InvokeConstructorDeclarationVisited(this, new WalkerEventArgs());
        }