public void Parse_BranchPreconditionsNotViolated_NoProblem()
        {
            List<AssignabilityPreCondition> preConditions = new List<AssignabilityPreCondition> { new AssignabilityPreCondition("x", Fragment.CreateNamed("SqlFragment")) };
              SymbolTable postConditions = new SymbolTable (_blacklistManager);
              List<int> successors = new List<int> { 1, 2 };
              BasicBlock initialNode = new BasicBlock (0, preConditions.ToArray(), postConditions, successors.ToArray(), c_EmptyAssignments);

              preConditions = new List<AssignabilityPreCondition> { new AssignabilityPreCondition("x", Fragment.CreateNamed("SqlFragment")) };
              postConditions = new SymbolTable (_blacklistManager);
              successors = new List<int>();
              BasicBlock firstBranch = new BasicBlock (1, preConditions.ToArray(), postConditions, successors.ToArray(), c_EmptyAssignments);

              preConditions = new List<AssignabilityPreCondition> { new AssignabilityPreCondition("x", Fragment.CreateNamed("SqlFragment")) };
              postConditions = new SymbolTable (_blacklistManager);
              successors = new List<int>();
              BasicBlock secondBranch = new BasicBlock (2, preConditions.ToArray(), postConditions, successors.ToArray(), c_EmptyAssignments);

              using (_mocks.Record())
              {
            _methodGraph.IsEmpty();
            LastCall.Return (false);

            SetupResult.For (_methodGraph.InitialBlock)
                   .Return (initialNode);

            SetupResult.For (_methodGraph.Blocks)
                    .Return(new BasicBlock[] {initialNode, firstBranch, secondBranch});

            _methodGraph.GetBasicBlockById (1);
            LastCall.Return (firstBranch);

            _methodGraph.GetBasicBlockById (2);
            LastCall.Return (secondBranch);

            _methodGraphBuilder.GetResult();
            LastCall.Return (_methodGraph);
            _parameterSymbolTableBuilder.GetResult();
            LastCall.Return(_methodPreConditions);
              }
              ProblemCollection result = ParseGraph();
              Assert.That (TestHelper.ContainsProblemID (c_InjectionCopRuleId, result), Is.False);
        }
 public BasicBlock Parse(Block block, int directSuccessorKey)
 {
     ArgumentUtility.CheckNotNull ("block", block);
       Reset();
       _successors.Add (directSuccessorKey);
       Inspect (block);
       BasicBlock basicBlock = new BasicBlock (
       block.UniqueKey, _preConditions.ToArray(), _symbolTableParser, _successors.ToArray(), _blockAssignments.ToArray());
       return basicBlock;
 }
        public void Parse_SingleNodePreconditionViolated_ReturnsProblem()
        {
            AssignabilityPreCondition[] preConditions = { new AssignabilityPreCondition("y", Fragment.CreateNamed("SqlFragment")) };
              SymbolTable postConditions = new SymbolTable (_blacklistManager);
              int[] successors = (new List<int>()).ToArray();

              BasicBlock node = new BasicBlock (0, preConditions, postConditions, successors, c_EmptyAssignments);

              using(_mocks.Record())
              {
            _methodGraph.IsEmpty();
            LastCall.Return (false);

            SetupResult.For(_methodGraph.InitialBlock)
              .Return(node);

            SetupResult.For(_methodGraph.Blocks)
                    .Return(new BasicBlock[] { node });

            _methodGraphBuilder.GetResult();
            LastCall.Return (_methodGraph);
            _parameterSymbolTableBuilder.GetResult();
            LastCall.Return(_methodPreConditions);
              }
              ProblemCollection result = ParseGraph();
              Assert.That (TestHelper.ContainsProblemID(c_InjectionCopRuleId, result), Is.True);
        }
        public void Parse_SingleNodeNoPrecondition_NoProblems()
        {
            AssignabilityPreCondition[] preConditions = (new List<AssignabilityPreCondition>()).ToArray();
              SymbolTable postConditions = new SymbolTable (_blacklistManager);
              int[] successors = (new List<int>()).ToArray();
              BasicBlock node = new BasicBlock (0, preConditions, postConditions, successors, c_EmptyAssignments);

              using(_mocks.Record())
              {
            _methodGraph.IsEmpty();
            LastCall.Return (false);

            SetupResult.For(_methodGraph.InitialBlock)
              .Return(node);

            SetupResult.For(_methodGraph.Blocks)
                    .Return(new BasicBlock[] { node });

            _methodGraphBuilder.GetResult();
            LastCall.Return (_methodGraph);
            _parameterSymbolTableBuilder.GetResult();
            LastCall.Return(_methodPreConditions);
              }
              ProblemCollection result = ParseGraph();
              Assert.That (result.Count, Is.EqualTo (0));
        }
        public void Parse_SequenceWithLocalAssignment_NoProblem()
        {
            List<AssignabilityPreCondition> preConditions = new List<AssignabilityPreCondition> { new AssignabilityPreCondition("x", Fragment.CreateNamed("SqlFragment")) };
              SymbolTable postConditions = new SymbolTable (_blacklistManager);
              List<int> successors = new List<int> { 1 };
              List<BlockAssignment> localAssignments = new List<BlockAssignment> { new BlockAssignment ("x", "y") };
              BasicBlock initialNode = new BasicBlock (0, preConditions.ToArray(), postConditions, successors.ToArray(), localAssignments.ToArray());

              preConditions = new List<AssignabilityPreCondition> { new AssignabilityPreCondition("x", Fragment.CreateNamed("SqlFragment")), new AssignabilityPreCondition("y", Fragment.CreateNamed("SqlFragment")) };
              postConditions = new SymbolTable (_blacklistManager);
              successors = new List<int>();
              BasicBlock terminatingNode = new BasicBlock (1, preConditions.ToArray(), postConditions, successors.ToArray(), c_EmptyAssignments);

              using (_mocks.Record())
              {
            _methodGraph.IsEmpty();
            LastCall.Return (false);

            SetupResult.For (_methodGraph.InitialBlock)
                   .Return (initialNode);

            SetupResult.For(_methodGraph.Blocks)
                    .Return(new BasicBlock[] { initialNode, terminatingNode });

            _methodGraph.GetBasicBlockById (1);
            LastCall.Return (terminatingNode);

            _methodGraphBuilder.GetResult();
            LastCall.Return (_methodGraph);
            _parameterSymbolTableBuilder.GetResult();
            LastCall.Return(_methodPreConditions);
              }
              ProblemCollection result = ParseGraph();
              Assert.That (TestHelper.ContainsProblemID (c_InjectionCopRuleId, result), Is.False);
        }
 private void Parse(IMethodGraph methodGraph, ISymbolTable context, BasicBlock currentBlock, Dictionary<int, int> visits)
 {
     UpdateVisits (currentBlock.Id, visits);
       bool loopIterationsExceeded = visits[currentBlock.Id] > 1;
       if(!loopIterationsExceeded)
       {
     CheckPreConditions (currentBlock.PreConditions, context);
     ISymbolTable adjustedContext = UpdateContext (context, currentBlock.PostConditionSymbolTable, currentBlock.BlockAssignments);
     ParseSuccessors (currentBlock.SuccessorKeys, visits, methodGraph, adjustedContext);
       }
 }