Exemplo n.º 1
0
        public void Create_DecoratesAndReThrowsExceptions()
        {
            // Arrange
            const string code = @"
namespace Ns1
{
  class MyClass
  {
    void DoStuff(){}
  }
}
";

            var(syntaxTree, semanticModel) = TestHelper.Compile(code);
            var factory = new UcfgFactory(semanticModel);

            var methodNode = syntaxTree.GetRoot()
                             .DescendantNodes()
                             .OfType <MethodDeclarationSyntax>()
                             .First();
            var methodSymbol = (IMethodSymbol)semanticModel.GetDeclaredSymbol(methodNode);

            var mockCFG = new Mock <IControlFlowGraph>(MockBehavior.Strict); // strict -> throw on any usage

            Action act = () => factory.Create(methodNode, methodSymbol, mockCFG.Object);

            // Act
            act.Should().ThrowExactly <UcfgException>().And.Message.Should().ContainAll("Error processing method: DoStuff", "Inner exception: ");
        }
Exemplo n.º 2
0
        private static UCFG BuildUcfg(CSharpSyntaxNode cfgStartNode, CSharpSyntaxNode ucfgStartNode,
                                      IMethodSymbol methodSymbol, SemanticModel semanticModel)
        {
            var builder = new UcfgFactory(semanticModel);
            var cfg     = CSharpControlFlowGraph.Create(cfgStartNode, semanticModel);
            var ucfg    = builder.Create(ucfgStartNode, methodSymbol, cfg);

            //var serializedCfg = CfgSerializer.Serialize(methodName, cfg);
            //var serializedUcfg = UcfgSerializer.Serialize(ucfg);

            return(ucfg);
        }