public void ShouldGatherMethodsWithAttributesFromSourceCode()
        {
            //GIVEN
            var dictionary = CSharpFileSyntaxTree.ParseText(@"
namespace Namespace1.Namespace2
{
  class Class1
  {
    class Class2
    {
      public void Lol1() {}
      [Test1, Test2]
      [Test3, Test4]
      private void Lol2() {}
      private static void Lol3() {}
    }
  }
}
", "").GetClassDeclarationSignatures();

            dictionary["Namespace1.Namespace2.Class1.Class2"].Methods.Should().BeEquivalentTo(
                new List <MethodDeclarationInfo>
            {
                new("Lol1", new List <string>()),
                new("Lol2", new List <string> {
                    "Test1", "Test2", "Test3", "Test4"
                }),
                new("Lol3", new List <string>())
            });
        public void ShouldGatherClassesWithTheirEnclosingNamespaces()
        {
            var dictionary = CSharpFileSyntaxTree.ParseText(@"
using static Namespace1.Namespace2.Class1.Class2;

class GlobalClass
{
  class GlobalNestedClass
  { 
  }
}

namespace Namespace1.Namespace2
{
  class Class1
  {
    class Class2
    {
    }
  }
}
", "").GetClassDeclarationSignatures();

            dictionary["Namespace1.Namespace2.Class1"].Namespace.Should().Be("Namespace1.Namespace2");
            dictionary["Namespace1.Namespace2.Class1"].Name.Should().Be("Class1");
            dictionary["Namespace1.Namespace2.Class1.Class2"].Namespace.Should().Be("Namespace1.Namespace2");
            dictionary["Namespace1.Namespace2.Class1.Class2"].Name.Should().Be("Class1.Class2");
            dictionary["GlobalClass"].Namespace.Should().Be("");
            dictionary["GlobalClass"].Name.Should().Be("GlobalClass");
            dictionary["GlobalClass.GlobalNestedClass"].Namespace.Should().Be("");
            dictionary["GlobalClass.GlobalNestedClass"].Name.Should().Be("GlobalClass.GlobalNestedClass");
        }
Beispiel #3
0
 public void ShouldCorrectlyRecognizeLocalStaticUsings()
 {
     CSharpFileSyntaxTree.ParseText(@"using static TddXt.AnyRoot.Root;", "").GetAllUsingsFrom(new Dictionary <string, ClassDeclarationInfo>
     {
         { "TddXt.AnyRoot.Root", new ClassDeclarationInfo("Root", "TddXt.AnyRoot") }
     })
     .Should().Contain("TddXt.AnyRoot");
 }
 public void ShouldParseTopmostNonNestedNamespaces()
 {
     CSharpFileSyntaxTree.ParseText(@"namespace Lolek {}", "").GetAllUniqueNamespaces().Should().Contain("Lolek").And.HaveCount(1);
     CSharpFileSyntaxTree.ParseText(@"namespace Lolek {} namespace Lolek {}", "").GetAllUniqueNamespaces().Should().Contain("Lolek").And.HaveCount(1);
     CSharpFileSyntaxTree.ParseText(@"namespace Lolek1 {} namespace Lolek2 {}", "").GetAllUniqueNamespaces().Should().Contain("Lolek1").And.Contain("Lolek2").And.HaveCount(2);
     CSharpFileSyntaxTree.ParseText(@"namespace Lolek.Lolek1 {}", "").GetAllUniqueNamespaces().Should().Contain("Lolek.Lolek1").And.HaveCount(1);
     CSharpFileSyntaxTree.ParseText(@"namespace Lolek { namespace Lolek1 {} }", "").GetAllUniqueNamespaces().Should().Contain("Lolek").And.Contain("Lolek1").And.HaveCount(2);
     CSharpFileSyntaxTree.ParseText(@"", "").GetAllUniqueNamespaces().Should().BeEmpty();
 }
Beispiel #5
0
        public void ShouldCorrectlyRecognizeLocalStaticGenericUsings()
        {
            var allUsings = CSharpFileSyntaxTree.ParseText(@"using static Functional.Maybe.Maybe<int, int>;", "").GetAllUsingsFrom(
                new Dictionary <string, ClassDeclarationInfo>
            {
                { "Functional.Maybe.Maybe<int,int>", new ClassDeclarationInfo("Maybe<int,int>", "Functional.Maybe.Maybe<int,int>") }
            });

            allUsings.Should().Contain("Functional.Maybe.Maybe<int,int>");
        }
Beispiel #6
0
        public void ShouldGatherNormalUsingsFromAllLevels()
        {
            CSharpFileSyntaxTree.ParseText(@"
using FluentAssertions;
using Microsoft.CodeAnalysis.CSharp;

namespace Lolek
{
  using Nunit;
  namespace Zenek
  {
    using Trolololo;
  }
}
", "").GetAllUsingsFrom(NoClassDeclarations).Should()
            .Contain("Microsoft.CodeAnalysis.CSharp")
            .And.Contain("Nunit")
            .And.Contain("Trolololo");
        }
        public void ShouldGatherBeAbleToDistinguishBetweenNonGenericClassAndGenericClassWithTheSameName()
        {
            var dictionary = CSharpFileSyntaxTree.ParseText(@"
namespace Namespace1.Namespace2
{
  class Class1
  {
  }

  class Class1<T1, T2>
  {
  }
}
", "").GetClassDeclarationSignatures();

            dictionary["Namespace1.Namespace2.Class1"].Namespace.Should().Be("Namespace1.Namespace2");
            dictionary["Namespace1.Namespace2.Class1"].Name.Should().Be("Class1");
            dictionary["Namespace1.Namespace2.Class1<T1,T2>"].Namespace.Should().Be("Namespace1.Namespace2");
            dictionary["Namespace1.Namespace2.Class1<T1,T2>"].Name.Should().Be("Class1<T1,T2>");
        }
Beispiel #8
0
 public void ShouldIgnoreForeignStaticUsings()
 {
     CSharpFileSyntaxTree.ParseText(@"using static TddXt.AnyRoot.Root;", "").GetAllUsingsFrom(NoClassDeclarations)
     .Should().BeEmpty();
 }
Beispiel #9
0
 public void ShouldCorrectlyRecognizeAliases()
 {
     CSharpFileSyntaxTree.ParseText(@"using trolololo = Microsoft.CodeAnalysis.CSharp;", "").GetAllUsingsFrom(NoClassDeclarations)
     .Should().Contain("Microsoft.CodeAnalysis.CSharp");
 }