public void HandleViolation_ProblemMetadataGivenButNoViolation_NoProblemAdded()
        {
            var expectedFragment = Fragment.CreateNamed (c_expectedType);
              var givenFragment = Fragment.CreateNamed (c_expectedType);

              IPreCondition preCondition = new CustomInferencePreCondition(c_symbol, expectedFragment, _problemMetadata);
              var context = new SymbolTable(_blacklistManager);
              context.MakeSafe (c_symbol, givenFragment);
              IProblemPipe problemPipe = MockRepository.GenerateMock<IProblemPipe>();

              preCondition.HandleViolation (context, problemPipe);

              problemPipe.AssertWasNotCalled (pipe => pipe.AddProblem (Arg<ProblemMetadata>.Is.Anything));
        }
        public void Analyze(MethodCall methodCall, ISymbolTable context, List<IPreCondition> preConditions)
        {
            Method method = IntrospectionUtility.ExtractMethod (methodCall);
              if (Analyzes(method) && methodCall.Callee is MemberBinding)
              {
            MemberBinding memberBinding = (MemberBinding) methodCall.Callee;

            if (IsFragmentParameterInferenceMethod (method))
            {
              string variableName;
              if (IntrospectionUtility.IsVariable (memberBinding.TargetObject, out variableName))
              {
            Fragment parameterFragment = ParameterFragmentUtility.ParameterFragmentIntersection (methodCall, context);
            Fragment targetObjectFragment = context.GetFragmentType (variableName);
            if (targetObjectFragment == Fragment.CreateLiteral() || targetObjectFragment.Undefined)
            {
              context.MakeSafe (variableName, parameterFragment);
            }
            else
            {
              if (targetObjectFragment == Fragment.CreateEmpty() && parameterFragment != Fragment.CreateLiteral()) // && parameterFragment != Fragment.CreateEmpty()
              {
                ProblemMetadata problemMetadata = new ProblemMetadata(methodCall.UniqueKey, methodCall.SourceContext, parameterFragment, targetObjectFragment);
                IPreCondition precondition = new CustomInferencePreCondition(variableName, parameterFragment, problemMetadata);
                preConditions.Add(precondition);
              }
              else if (!FragmentUtility.FragmentTypesAssignable(parameterFragment, targetObjectFragment))
              {
                context.MakeUnsafe(variableName);
              }
            }

              }
            }
            else if (!IsSafeMethod(method))
            {
              string variableName;
              if (IntrospectionUtility.IsVariable(memberBinding.TargetObject, out variableName))
              {
            context.MakeUnsafe(variableName);
              }
            }
              }
        }
        public void HandleViolation_ViolationNotProvoked_KeepsSymbolFragment()
        {
            var expectedFragment = Fragment.CreateNamed (c_expectedType);
              var givenFragment = expectedFragment;

              IPreCondition preCondition = new CustomInferencePreCondition(c_symbol, expectedFragment, _problemMetadata);
              var context = new SymbolTable(_blacklistManager);
              context.MakeSafe (c_symbol, givenFragment);
              IProblemPipe problemPipe = MockRepository.GenerateMock<IProblemPipe>();

              preCondition.HandleViolation (context, problemPipe);

              bool symbolFragmentKept = context.GetFragmentType (c_symbol) == expectedFragment;
              Assert.That (symbolFragmentKept, Is.True);
        }
        public void IsViolated_NamedExpectedSymbolUnknown_ReturnsTrue()
        {
            var expectedFragment = Fragment.CreateNamed(c_expectedType);

              IPreCondition preCondition = new CustomInferencePreCondition(c_symbol, expectedFragment, _problemMetadata);
              var context = new SymbolTable(_blacklistManager);

              Assert.That (preCondition.IsViolated (context), Is.True);
        }
        public void IsViolated_NamedExpectedLiteralGiven_ReturnsFalse()
        {
            var expectedFragment = Fragment.CreateNamed (c_expectedType);
              var givenFragment = Fragment.CreateLiteral();

              IPreCondition preCondition = new CustomInferencePreCondition(c_symbol, expectedFragment, _problemMetadata);
              var context = new SymbolTable(_blacklistManager);
              context.MakeSafe (c_symbol, givenFragment);

              Assert.That (preCondition.IsViolated (context), Is.False);
        }