public void LoadExtendsTest(string className, string baseClassName) { var csFile = new CSharpFile( className.ToBasicPath(), DeclarationHelper.CreateDeclarationFactory(this.testOutputHelper)); csFile.Load(); var declaration = Assert.Single(csFile.Declarations); var declarationResolver = this.SetupDeclarationResolver( declaration, baseClassName); var classDecl = Assert.IsType <ClassDeclaration>(declaration); classDecl.Load(declarationResolver); Assert.NotNull(classDecl.GenericParameters); Assert.NotNull(classDecl.Extends); var extendsSingle = Assert.Single(classDecl.Extends); var genDeclUse = Assert.IsType <GenericDeclarationUse>(extendsSingle); Assert.Equal(baseClassName, genDeclUse.Declaration.Name); }
private IDeclarationResolver SetupDeclarationResolver(IDeclaration <SyntaxNode> contextDeclaration, params string[] classNames) { var declarationResolverMock = new Mock <IDeclarationResolver>(); foreach (var className in classNames) { var classFile = new CSharpFile( className.ToBasicPath(), DeclarationHelper.CreateDeclarationFactory(this.testOutputHelper)); classFile.Load(); var classDeclarationSingle = Assert.Single(classFile.Declarations); if (classDeclarationSingle is IGenericDeclaration <SyntaxNode> genericDeclaration && genericDeclaration.TypeParameterListSyntaxProvider.SyntaxNode != null) { declarationResolverMock .Setup(dr => dr.Resolve(genericDeclaration.Name, It.IsAny <IReadOnlyList <IDeclarationUse <SyntaxNode> > >(), contextDeclaration)) .Returns(genericDeclaration); } else { declarationResolverMock .Setup(dr => dr.Resolve(classDeclarationSingle.Name, contextDeclaration)) .Returns(classDeclarationSingle); } } return(declarationResolverMock.Object); }
public void LoadClassAttributes() { var className = nameof(AttributedClass); var file = className.ToBasicPath(); var csFile = new CSharpFile( file, DeclarationHelper.CreateDeclarationFactory(this.testOutputHelper)); csFile.Load(); var declaration = Assert.Single(csFile.Declarations); var declarationResolver = this.SetupDeclarationResolver(declaration); var decl = Assert.IsType <ClassDeclaration>(declaration); decl.Load(declarationResolver); Assert.NotEmpty(decl.Attributes); var attribute = Assert.Single(decl.Attributes); Assert.Equal(nameof(PatternAttribute), attribute.Name); Assert.NotNull(attribute.SyntaxNodeProvider); }
public void LoadCSharpFileNameSpaceDeclarationTest() { var file = "./Resources/Workspace/MultiNameSapces.cs"; var csFile = new CSharpFile(file, DeclarationHelper.CreateDeclarationFactory(this.testOutputHelper)); csFile.Load(); Assert.Equal(3, csFile.Declarations.Count); Assert.Single(csFile.Declarations.Where(d => string.IsNullOrEmpty(d.DeclarationNameSpace))); Assert.Single(csFile.Declarations.Where(d => d.DeclarationNameSpace == "SoloX.GeneratorTools.Core.CSharp.UTest.Resources.Workspace")); Assert.Single(csFile.Declarations.Where(d => d.DeclarationNameSpace == "SoloX.GeneratorTools.Core.CSharp.UTest.Resources.Workspace.Test")); }
public void LoadCSharpFileTest(string declarationFile, string name, Type expectedDeclarationType) { var csFile = new CSharpFile( declarationFile, DeclarationHelper.CreateDeclarationFactory(this.testOutputHelper)); csFile.Load(); Assert.Single(csFile.Declarations); var decl = csFile.Declarations.Single(); Assert.Equal(expectedDeclarationType, decl.GetType()); Assert.Equal(name, decl.Name); }
public void LoadMemberListTest(string className, bool isArray) { var file = className.ToBasicPath(); var csFile = new CSharpFile( file, DeclarationHelper.CreateDeclarationFactory(this.testOutputHelper)); csFile.Load(); var declaration = Assert.Single(csFile.Declarations); var declarationResolver = this.SetupDeclarationResolver( declaration, nameof(SimpleClass)); var decl = Assert.IsType <ClassDeclaration>(declaration); decl.Load(declarationResolver); Assert.Empty(decl.GenericParameters); Assert.Empty(decl.Extends); Assert.NotEmpty(decl.Members); Assert.Equal(2, decl.Members.Count); var mClass = Assert.Single(decl.Members.Where(m => m.Name == nameof(ClassWithProperties.PropertyClass))); var pClass = Assert.IsType <PropertyDeclaration>(mClass); Assert.IsType <GenericDeclarationUse>(pClass.PropertyType); Assert.Equal(nameof(SimpleClass), pClass.PropertyType.Declaration.Name); var mInt = Assert.Single(decl.Members.Where(m => m.Name == nameof(ClassWithProperties.PropertyInt))); var pInt = Assert.IsType <PropertyDeclaration>(mInt); Assert.IsType <PredefinedDeclarationUse>(pInt.PropertyType); Assert.Equal("int", pInt.PropertyType.Declaration.Name); if (isArray) { Assert.NotNull(pClass.PropertyType.ArraySpecification); Assert.NotNull(pInt.PropertyType.ArraySpecification); } else { Assert.Null(pClass.PropertyType.ArraySpecification); Assert.Null(pInt.PropertyType.ArraySpecification); } }
public void LoadCSharpClassTest(string className, string typeParameterName, string baseClassName) { var location = className.ToBasicPath(); var csFile = new CSharpFile( location, DeclarationHelper.CreateDeclarationFactory(this.testOutputHelper)); csFile.Load(); Assert.Single(csFile.Declarations); var declaration = csFile.Declarations.Single(); Assert.Equal(location, declaration.Location); var classDecl = Assert.IsType <ClassDeclaration>(declaration); classDecl.Load(Mock.Of <IDeclarationResolver>()); Assert.NotNull(classDecl.GenericParameters); Assert.NotNull(classDecl.Extends); if (string.IsNullOrEmpty(typeParameterName)) { Assert.Empty(classDecl.GenericParameters); } else { var paramDecl = Assert.Single(classDecl.GenericParameters); Assert.Equal(typeParameterName, paramDecl.Name); } if (string.IsNullOrEmpty(baseClassName)) { Assert.Empty(classDecl.Extends); } else { var baseClass = Assert.Single(classDecl.Extends); Assert.Equal(baseClassName, baseClass.Declaration.Name); } }
public void LoadGetterSetterPropertyTest() { var className = nameof(ClassWithGetterSetterProperties); var file = className.ToBasicPath(); var csFile = new CSharpFile( file, DeclarationHelper.CreateDeclarationFactory(this.testOutputHelper)); csFile.Load(); var declaration = Assert.Single(csFile.Declarations); var declarationResolver = this.SetupDeclarationResolver(declaration); var decl = Assert.IsType <ClassDeclaration>(declaration); decl.Load(declarationResolver); Assert.NotEmpty(decl.Properties); Assert.Equal(3, decl.Properties.Count); var rwp = Assert.Single(decl.Properties.Where(p => p.Name == nameof(ClassWithGetterSetterProperties.ReadWriteProperty))); Assert.True(rwp.HasGetter); Assert.True(rwp.HasSetter); var rop = Assert.Single(decl.Properties.Where(p => p.Name == nameof(ClassWithGetterSetterProperties.ReadOnlyProperty))); Assert.True(rop.HasGetter); Assert.False(rop.HasSetter); var wop = Assert.Single(decl.Properties.Where(p => p.Name == nameof(ClassWithGetterSetterProperties.WriteOnlyProperty))); Assert.False(wop.HasGetter); Assert.True(wop.HasSetter); }