public void OrdersWithMethodWithinClass() { var root = CodeNamespace.InitRootNamespace(); var comparer = new CodeElementOrderComparer(); var codeClass = new CodeClass { Name = "Class" }; root.AddClass(codeClass); var method = new CodeMethod { Name = "Method" }; codeClass.AddMethod(method); method.AddParameter(new CodeParameter { Name = "param" }); var dataSet = new List <Tuple <CodeElement, CodeElement, int> > { new(null, null, 0), new(null, new CodeClass(), -1), new(new CodeClass(), null, 1), new(new CodeUsing(), new CodeProperty(), -1000), new(new CodeIndexer(), new CodeProperty(), 1000), new(method, new CodeProperty(), 1101), new(method, codeClass, -899) };
public CodeMethodWriterTests() { writer = LanguageWriter.GetLanguageWriter(GenerationLanguage.Ruby, DefaultPath, DefaultName); tw = new StringWriter(); writer.SetTextWriter(tw); root = CodeNamespace.InitRootNamespace(); parentClass = new CodeClass { Name = "parentClass" }; root.AddClass(parentClass); method = new CodeMethod { Name = MethodName, }; method.ReturnType = new CodeType { Name = ReturnTypeName }; voidMethod = new CodeMethod { Name = MethodName, }; voidMethod.ReturnType = new CodeType { Name = "void" }; parentClass.AddMethod(voidMethod); parentClass.AddMethod(method); }
public void ComparesWithDeclaration() { var root = CodeNamespace.InitRootNamespace(); var cUsing = new CodeUsing(root) { Name = "using1", }; cUsing.Declaration = new CodeType(cUsing) { Name = "type1" }; var cUsing2 = new CodeUsing(root) { Name = "using2", }; cUsing2.Declaration = new CodeType(cUsing2) { Name = "type2" }; var comparer = new CodeUsingComparer(true); Assert.False(comparer.Equals(cUsing, cUsing2)); Assert.NotEqual(0, comparer.GetHashCode(cUsing)); }
public void InheritsFrom() { var root = CodeNamespace.InitRootNamespace(); var child = root.AddNamespace(CodeNamespaceTests.ChildName); var baseClass = child.AddClass(new CodeClass { Name = "baseClass" }).First(); var baseClass2 = child.AddClass(new CodeClass { Name = "baseClass2" }).First(); baseClass2.StartBlock.Inherits = new CodeType { TypeDefinition = baseClass, }; var subClass = child.AddClass(new CodeClass { Name = "subclass" }).First(); var unrelatedClass = child.AddClass(new CodeClass { Name = "unrelatedClass" }).First(); subClass.StartBlock.Inherits = new CodeType { TypeDefinition = baseClass2, }; Assert.True(baseClass2.StartBlock.InheritsFrom(baseClass)); Assert.True(subClass.StartBlock.InheritsFrom(baseClass)); Assert.True(subClass.StartBlock.InheritsFrom(baseClass2)); Assert.False(subClass.StartBlock.InheritsFrom(unrelatedClass)); Assert.False(baseClass.StartBlock.InheritsFrom(baseClass2)); }
public void GetNamespaceImportSymbol() { var root = CodeNamespace.InitRootNamespace(); var main = root.AddNamespace("github.com/something"); Assert.Equal("i749ccebf37b522f21de9a46471b0aeb8823a49292ca8740fc820cf9bd340c846", GoNamespaceExtensions.GetNamespaceImportSymbol(main)); }
public void ThrowsOnAddingEmptyCollections() { var root = CodeNamespace.InitRootNamespace(); var child = root.AddNamespace(childName); Assert.Throws <ArgumentNullException>(() => { child.AddClass(null); }); Assert.Throws <ArgumentOutOfRangeException>(() => { child.AddClass(new CodeClass[] {}); }); Assert.Throws <ArgumentNullException>(() => { child.AddClass(new CodeClass[] { null }); }); Assert.Throws <ArgumentNullException>(() => { child.AddEnum(null); }); Assert.Throws <ArgumentOutOfRangeException>(() => { child.AddEnum(new CodeEnum[] {}); }); Assert.Throws <ArgumentNullException>(() => { child.AddEnum(new CodeEnum[] { null }); }); Assert.Throws <ArgumentNullException>(() => { child.AddUsing(null); }); Assert.Throws <ArgumentOutOfRangeException>(() => { child.AddUsing(new CodeUsing[] {}); }); Assert.Throws <ArgumentNullException>(() => { child.AddUsing(new CodeUsing[] { null }); }); }
public void AddsInnerElements() { var root = CodeNamespace.InitRootNamespace(); var child = root.AddNamespace(CodeNamespaceTests.childName); var codeClass = child.AddClass(new CodeClass(child) { Name = "class1" }).First(); codeClass.AddInnerClass(new CodeClass(codeClass) { Name = "subclass" }); Assert.Single(codeClass.GetChildElements(true)); codeClass.AddMethod(new CodeMethod(codeClass) { Name = "submethod" }); Assert.Equal(2, codeClass.GetChildElements(true).Count()); codeClass.AddProperty(new CodeProperty(codeClass) { Name = "subprop" }); Assert.Equal(3, codeClass.GetChildElements(true).Count()); }
public void ClonesTypeProperly() { var root = CodeNamespace.InitRootNamespace(); var type = new CodeType(root) { Name = "type1", ActionOf = true, CollectionKind = CodeTypeBase.CodeTypeCollectionKind.Array, IsExternal = true, IsNullable = true, }; type.TypeDefinition = new CodeClass(type) { Name = "class1" }; var clone = type.Clone() as CodeType; Assert.True(clone.ActionOf); Assert.True(clone.IsExternal); Assert.True(clone.IsNullable); Assert.Single(clone.AllTypes); Assert.Equal(CodeTypeBase.CodeTypeCollectionKind.Array, clone.CollectionKind); Assert.Equal(type.TypeDefinition.Name, clone.TypeDefinition.Name); }
public CodePropertyWriterTests() { writer = LanguageWriter.GetLanguageWriter(GenerationLanguage.CSharp, DefaultPath, DefaultName); tw = new StringWriter(); writer.SetTextWriter(tw); var root = CodeNamespace.InitRootNamespace(); parentClass = new CodeClass { Name = "parentClass" }; root.AddClass(parentClass); property = new CodeProperty { Name = PropertyName, Type = new CodeType { Name = TypeName }, }; parentClass.AddProperty(property, new() { Name = "pathParameters", Kind = CodePropertyKind.PathParameters, }, new() { Name = "requestAdapter", Kind = CodePropertyKind.RequestAdapter, }); }
public CodeIndexerWriterTests() { writer = LanguageWriter.GetLanguageWriter(GenerationLanguage.CSharp, defaultPath, defaultName); tw = new StringWriter(); writer.SetTextWriter(tw); var root = CodeNamespace.InitRootNamespace(); parentClass = new CodeClass(root) { Name = "parentClass" }; root.AddClass(parentClass); indexer = new CodeIndexer(parentClass) { Name = "idx", }; indexer.IndexType = new CodeType(indexer) { Name = "string", }; indexer.ReturnType = new CodeType(indexer) { Name = "SomeRequestBuilder" }; parentClass.SetIndexer(indexer); }
public void GetsParentAndGrandParent() { var root = CodeNamespace.InitRootNamespace(); var child = root.AddNamespace(CodeNamespaceTests.childName); var grandParent = child.AddClass(new CodeClass(child) { Name = "class1" }).First(); var parent = child.AddClass(new CodeClass(child) { Name = "parent" }).First(); var childClass = child.AddClass(new CodeClass(child) { Name = "child" }).First(); (childClass.StartBlock as CodeClass.Declaration).Inherits = new CodeType(childClass) { TypeDefinition = parent, }; (parent.StartBlock as CodeClass.Declaration).Inherits = new CodeType(parent) { TypeDefinition = grandParent, }; Assert.Equal(grandParent, parent.GetParentClass()); Assert.Equal(parent, childClass.GetParentClass()); Assert.Equal(grandParent, childClass.GetGreatestGrandparent()); }
public void ThrowsWhenAddingItemToRoot() { Assert.Throws <InvalidOperationException>(() => { var root = CodeNamespace.InitRootNamespace(); var item = root.EnsureItemNamespace(); }); }
public void SetsIndexer() { var root = CodeNamespace.InitRootNamespace(); var child = root.AddNamespace(CodeNamespaceTests.ChildName); var codeClass = child.AddClass(new CodeClass { Name = "class1" }).First(); codeClass.SetIndexer(new CodeIndexer { Name = "idx", SerializationName = "idx_smth" }); Assert.Single(codeClass.GetChildElements(true).OfType <CodeIndexer>()); Assert.Throws <ArgumentNullException>(() => { codeClass.SetIndexer(null); }); codeClass.SetIndexer(new CodeIndexer { Name = "idx2", SerializationName = "idx-2" }); Assert.Empty(codeClass.GetChildElements(true).OfType <CodeIndexer>()); var methods = codeClass.GetChildElements(true).OfType <CodeMethod>().Where(x => x.IsOfKind(CodeMethodKind.IndexerBackwardCompatibility)).ToArray(); Assert.Equal(2, methods.Length); Assert.Equal("ByIdx_smth", methods.FirstOrDefault(x => x.OriginalIndexer.Name.Equals("idx")).Name); Assert.Equal("ByIdx2", methods.FirstOrDefault(x => x.OriginalIndexer.Name.Equals("idx2")).Name); }
public CodeMethodWriterTests() { languageWriter = LanguageWriter.GetLanguageWriter(GenerationLanguage.PHP, DefaultPath, DefaultName); stringWriter = new StringWriter(); languageWriter.SetTextWriter(stringWriter); root = CodeNamespace.InitRootNamespace(); root.Name = "Microsoft\\Graph"; _codeMethodWriter = new CodeMethodWriter(new PhpConventionService()); parentClass = new CodeClass() { Name = "parentClass" }; root.AddClass(parentClass); method = new CodeMethod() { Name = MethodName, IsAsync = true, Description = "This is a very good method to try all the good things" }; method.ReturnType = new CodeType() { Name = ReturnTypeName }; _refiner = new PhpRefiner(new GenerationConfiguration { Language = GenerationLanguage.PHP }); parentClass.AddMethod(method); }
public void Defensive() { var root = CodeNamespace.InitRootNamespace(); var child = new NeverBlock(root); child.AddRange(); Assert.Empty(child.GetChildElements(true)); }
public void FindsNamespaceByName() { var root = CodeNamespace.InitRootNamespace(); var child = root.AddNamespace(ChildName); var result = root.FindNamespaceByName(ChildName); Assert.Equal(child, result); }
public void IsParentOf() { var root = CodeNamespace.InitRootNamespace(); var child = root.AddNamespace(ChildName); var grandchild = child.AddNamespace(ChildName + ".four"); Assert.True(child.IsParentOf(grandchild)); Assert.False(grandchild.IsParentOf(child)); }
public TypeScriptLanguageRefinerTests() { root = CodeNamespace.InitRootNamespace(); graphNS = root.AddNamespace("graph"); parentClass = new () { Name = "parentClass" }; graphNS.AddClass(parentClass); }
public void DoesntThrowOnRootInitialization() { var root = CodeNamespace.InitRootNamespace(); Assert.NotNull(root); Assert.Null(root.Parent); Assert.NotNull(root.StartBlock); Assert.NotNull(root.EndBlock); }
public void Defensive() { var root = CodeNamespace.InitRootNamespace(); var property = new CodeProperty(root) { Name = "prop", }; Assert.False(property.IsOfKind((CodePropertyKind[])null)); Assert.False(property.IsOfKind(new CodePropertyKind[] { })); }
public void ThrowsWhenAddingANamespaceWithEmptyName() { var root = CodeNamespace.InitRootNamespace(); Assert.Throws <ArgumentNullException>(() => { root.AddNamespace(null); }); Assert.Throws <ArgumentNullException>(() => { root.AddNamespace(string.Empty); }); }
public void Defensive() { var codeMethodWriter = new CodeMethodWriter(new RubyConventionService()); Assert.Throws <ArgumentNullException>(() => codeMethodWriter.WriteCodeElement(null, writer)); Assert.Throws <ArgumentNullException>(() => codeMethodWriter.WriteCodeElement(method, null)); var originalParent = method.Parent; method.Parent = CodeNamespace.InitRootNamespace(); Assert.Throws <InvalidOperationException>(() => codeMethodWriter.WriteCodeElement(method, writer)); }
public CodeNamespaceWriterTests() { codeElementWriter = new CodeNamespaceWriter(new RubyConventionService()); writer = LanguageWriter.GetLanguageWriter(GenerationLanguage.Ruby, DefaultPath, DefaultName); tw = new StringWriter(); writer.SetTextWriter(tw); var root = CodeNamespace.InitRootNamespace(); parentNamespace = root.AddNamespace("parentNamespace"); childNamespace = parentNamespace.AddNamespace("childNamespace"); }
public void Defensive() { var root = CodeNamespace.InitRootNamespace(); var parameter = new CodeParameter(root) { Name = "class", }; Assert.False(parameter.IsOfKind((CodeParameterKind[])null)); Assert.False(parameter.IsOfKind(new CodeParameterKind[] { })); }
public void Defensive() { var root = CodeNamespace.InitRootNamespace(); var method = new CodeMethod(root) { Name = "class", }; Assert.False(method.IsOfKind((CodeMethodKind[])null)); Assert.False(method.IsOfKind(new CodeMethodKind[] { })); }
public CodeTypeWriterTests() { writer = LanguageWriter.GetLanguageWriter(GenerationLanguage.TypeScript, defaultPath, defaultName); tw = new StringWriter(); writer.SetTextWriter(tw); var root = CodeNamespace.InitRootNamespace(); currentType = new (root) { Name = typeName }; }
public CodeEnumWriterTests() { writer = LanguageWriter.GetLanguageWriter(GenerationLanguage.Go, DefaultPath, DefaultName); tw = new StringWriter(); writer.SetTextWriter(tw); var root = CodeNamespace.InitRootNamespace(); currentEnum = root.AddEnum(new CodeEnum { Name = EnumName, }).First(); }
private static CodeClass GetParentClassInStaticContext() { CodeClass parent = new CodeClass() { Name = "parent" }; CodeNamespace rootNamespace = CodeNamespace.InitRootNamespace(); rootNamespace.AddClass(parent); return(parent); }
public CodeClassDeclarationWriterTests() { codeElementWriter = new CodeClassDeclarationWriter(new GoConventionService()); writer = LanguageWriter.GetLanguageWriter(GenerationLanguage.Go, DefaultPath, DefaultName); tw = new StringWriter(); writer.SetTextWriter(tw); root = CodeNamespace.InitRootNamespace(); parentClass = new () { Name = "parentClass" }; root.AddClass(parentClass); }
public void DefensiveProgramming() { var comparer = new CodeParameterOrderComparer(); Assert.NotNull(comparer); var root = CodeNamespace.InitRootNamespace(); var mockParameter = new Mock <CodeParameter>().Object; Assert.Equal(0, comparer.Compare(null, null)); Assert.Equal(-1, comparer.Compare(null, mockParameter)); Assert.Equal(1, comparer.Compare(mockParameter, null)); }