public void TypeNodeFactory_Interface_ReturnsInterfaceTypeNode() { Type sampleType = typeof(IntrospectionUtility_InterfaceSample); TypeNode result = IntrospectionUtility.TypeNodeFactory(sampleType); Assert.That(result.FullName, Is.EqualTo(sampleType.FullName)); }
public void GetNestedType_NonExistingNestedType_ReturnsNestedType() { TypeNode parent = IntrospectionUtility.TypeNodeFactory <IntrospectionUtility_ClassSample>(); TypeNode nestedType = IntrospectionUtility.GetNestedType(parent, "DoesNotExist"); Assert.That(nestedType, Is.Null); }
public void Parse_ParameterSampleType_NoProblem() { TypeNode sample = IntrospectionUtility.TypeNodeFactory <SampleAttribute>(); ProblemCollection result = _typeParser.Check(sample); Assert.That(TestHelper.ContainsProblemID(c_InjectionCopRuleId, result), Is.False); }
private Method GetMethodFromSampleClass <T> () { var method = IntrospectionUtility.MethodFactory <T> ( "Foo", IntrospectionUtility.TypeNodeFactory <int>(), IntrospectionUtility.TypeNodeFactory <string>()); return(method); }
public void SetUp() { _blacklistManager = new IDbCommandBlacklistManagerStub(); _environment = new SymbolTable(_blacklistManager); _floatType = IntrospectionUtility.TypeNodeFactory <float>(); _objectType = IntrospectionUtility.TypeNodeFactory <object>(); }
public void CreateFrom_UsesConfigurationFileLocator() { var config1Location = Path.Combine(Path.GetDirectoryName(GetType().Assembly.Location), "config.injectioncop"); var config2Location = Path.Combine(Path.GetDirectoryName(typeof(ConfigurationFactory).Assembly.Location), "config.injectioncop"); var emptyConfig = @"<?xml version=""1.0"" encoding=""utf-8"" ?> <Blacklist xmlns=""http://injectioncop.codeplex.com/""> </Blacklist>"; var typeNode = IntrospectionUtility.TypeNodeFactory <ConfigurationFileLocatorTest>(); var configurationFileLocatorMock = MockRepository.GenerateStrictMock <IConfigurationFileLocator>(); configurationFileLocatorMock.Expect(mock => mock.GetFilesFromCurrentAssembly()).Return(new[] { config1Location }); configurationFileLocatorMock.Expect(mock => mock.GetFilesFromParsedType(typeNode)).Return(new[] { config2Location }); configurationFileLocatorMock.Replay(); try { File.WriteAllText(config1Location, emptyConfig); File.WriteAllText(config2Location, emptyConfig); ConfigurationFactory.CreateFrom(typeNode, configurationFileLocatorMock); configurationFileLocatorMock.VerifyAllExpectations(); } finally { File.Delete(config1Location); File.Delete(config2Location); } }
public void Infers_CoveredMethod_ReturnsTrue() { TypeNode stringTypeNode = IntrospectionUtility.TypeNodeFactory <string>(); Method sample = IntrospectionUtility.MethodFactory <string> ("Concat", stringTypeNode, stringTypeNode); Assert.That(_customInferenceController.Infers(sample), Is.True); }
public void CreateFrom_CreatesLayeredConfiguration() { var config1Location = Path.Combine(Path.GetDirectoryName(GetType().Assembly.Location), "config.injectioncop"); var config2Location = Path.Combine(Path.GetDirectoryName(typeof(ConfigurationFactory).Assembly.Location), "config.injectioncop"); var emptyConfig = @"<?xml version=""1.0"" encoding=""utf-8"" ?> <Blacklist xmlns=""http://injectioncop.codeplex.com/""> </Blacklist>"; var typeNode = IntrospectionUtility.TypeNodeFactory <ConfigurationFileLocatorTest>(); var configurationFileLocatorStub = MockRepository.GenerateStub <IConfigurationFileLocator>(); configurationFileLocatorStub.Stub(mock => mock.GetFilesFromCurrentAssembly()).Return(new[] { config1Location }); configurationFileLocatorStub.Stub(mock => mock.GetFilesFromParsedType(typeNode)).Return(new[] { config2Location }); try { File.WriteAllText(config1Location, emptyConfig); File.WriteAllText(config2Location, emptyConfig); var configuration = ConfigurationFactory.CreateFrom(typeNode, configurationFileLocatorStub); Assert.That(configuration, Is.InstanceOf <LayeredConfigurationAdapter>()); var layeredConfigurationAdapter = (LayeredConfigurationAdapter)configuration; Assert.That(layeredConfigurationAdapter.Configurations.Length, Is.EqualTo(2)); } finally { File.Delete(config1Location); File.Delete(config2Location); } }
public void IsFragment_ContainsNonFragmentParameter_False() { TypeNode stringTypeNode = IntrospectionUtility.TypeNodeFactory <string>(); Method sample = TestHelper.GetSample <FragmentUtilitySample>("ContainsNonFragmentParameter", stringTypeNode); bool isResult = FragmentUtility.IsFragment(sample.Parameters[0].Attributes[0]); Assert.That(isResult, Is.False); }
public void ContainsFragment_ContainsStronglyTypedSqlFragmentParameter_True() { TypeNode stringTypeNode = IntrospectionUtility.TypeNodeFactory <string>(); Method sample = TestHelper.GetSample <FragmentUtilitySample>("ContainsStronglyTypedSqlFragmentParameter", stringTypeNode); bool isResult = FragmentUtility.ContainsFragment(sample.Parameters[0].Attributes); Assert.That(isResult, Is.True); }
public void IsPropertySetter_DummyMethod_ReturnsFalse() { TypeNode stringTypeNode = IntrospectionUtility.TypeNodeFactory <string>(); Method sample = TestHelper.GetSample <IntrospectionUtility_ClassSample> ("Dummy", stringTypeNode); bool isPropertySetter = IntrospectionUtility.IsPropertySetter(sample); Assert.That(isPropertySetter, Is.False); }
public void GetFragmentType_ContainsStronglyTypedSqlFragmentParameter_True() { TypeNode stringTypeNode = IntrospectionUtility.TypeNodeFactory <string>(); Method sample = TestHelper.GetSample <FragmentUtilitySample>("ContainsStronglyTypedSqlFragmentParameter", stringTypeNode); var fragmentType = FragmentUtility.GetFragmentType(sample.Parameters[0].Attributes); Assert.That(fragmentType, Is.EqualTo(Fragment.CreateNamed("SqlFragment"))); }
public void IsPropertySetter_PropertySetter_ReturnsTrue() { TypeNode objectTypeNode = IntrospectionUtility.TypeNodeFactory <Object>(); Method sample = TestHelper.GetSample <IntrospectionUtility_ClassSample> ("set_AnyProperty", objectTypeNode); bool isPropertyGetter = IntrospectionUtility.IsPropertySetter(sample); Assert.That(isPropertyGetter, Is.True); }
public void IsPropertyGetter_MethodWithParameterNamedLikeGetter_ReturnsFalse() { TypeNode stringTypeNode = IntrospectionUtility.TypeNodeFactory <string>(); Method sample = TestHelper.GetSample <IntrospectionUtility_ClassSample> ("get_NonExistingProperty", stringTypeNode); bool isPropertyGetter = IntrospectionUtility.IsPropertyGetter(sample); Assert.That(isPropertyGetter, Is.False); }
public void GetFragmentType_ContainsNonFragmentParameter_ThrowsException() { TypeNode stringTypeNode = IntrospectionUtility.TypeNodeFactory <string>(); Method sample = TestHelper.GetSample <FragmentUtilitySample>("ContainsNonFragmentParameter", stringTypeNode); var returnedFragment = FragmentUtility.GetFragmentType(sample.Parameters[0].Attributes); Assert.That(returnedFragment, Is.EqualTo(Fragment.CreateEmpty())); }
public void Check_CustomFragmentGeneratorAnnotationTest_NoProblem() { TypeNode sample = IntrospectionUtility.TypeNodeFactory <CustomFragmentGeneratorAnnotationTest>(); _typeParser.Check(sample); ProblemCollection result = _typeParser.Problems; Assert.That(TestHelper.ContainsProblemID(c_InjectionCopRuleId, result), Is.False); }
public void Check_InterfaceSample_NoProblem() { TypeNode sample = IntrospectionUtility.TypeNodeFactory <InterfaceSample>(); _typeParser.Check(sample); ProblemCollection result = _typeParser.Problems; Assert.That(TestHelper.ContainsProblemID(c_InjectionCopRuleId, result), Is.False); }
public void GetFilesFromParsedType_NoConfigFilesFound() { var typeNodeFactory = IntrospectionUtility.TypeNodeFactory <ConfigurationFileLocatorTest>(); var configurationFileLocator = new ConfigurationFileLocator(); var files = configurationFileLocator.GetFilesFromParsedType(typeNodeFactory); Assert.That(files, Is.Empty); }
public void MethodGraph_ValidReturnWithIfBlockWithLocalAssignment_ReturnsLocalAssignment() { TypeNode stringTypeNode = IntrospectionUtility.TypeNodeFactory <string>(); Method sampleMethod = TestHelper.GetSample <BlockParserSample> ("ValidReturnWithLiteralAssignmentInsideIf", stringTypeNode); Block preReturnBlock = sampleMethod.Body.Statements[2] as Block; BasicBlock preReturnBasicBlock = _blockParser.Parse(preReturnBlock); Assert.That(preReturnBasicBlock.BlockAssignments.Length, Is.EqualTo(1)); }
public void Parse_ValidReturnWithParameterResetAndAssignmentInsideIf_ReturnsNoLocalAssignment() { TypeNode stringTypeNode = IntrospectionUtility.TypeNodeFactory <string>(); Method sampleMethod = TestHelper.GetSample <BlockParserSample> ("ValidReturnWithParameterResetAndAssignmentInsideIf", stringTypeNode); Block ifBlock = sampleMethod.Body.Statements[1] as Block; BasicBlock ifBasicBlock = _blockParser.Parse(ifBlock); Assert.That(ifBasicBlock.BlockAssignments.Length, Is.EqualTo(0)); }
public void Parse_ConstructorSample_ReturnsProblem() { TypeNode sample = IntrospectionUtility.TypeNodeFactory <ConstructorSample>(); _typeParser.Check(sample); ProblemCollection result = _typeParser.Problems; Assert.That(TestHelper.ContainsProblemID(c_InjectionCopRuleId, result), Is.True); }
public void MethodFactory_MethodWithParametersWrongParameterType_ReturnsNull() { Type sampleType = typeof(IntrospectionUtility_InterfaceSample); TypeNode stringTypeNode = IntrospectionUtility.TypeNodeFactory <string>(); string sampleMethodname = "MethodWithParameter"; Method result = IntrospectionUtility.MethodFactory(sampleType, sampleMethodname, stringTypeNode); Assert.That(result, Is.Null); }
public void Parse_ConstructorChainingViolation_ReturnsProblem() { TypeNode stringTypeNode = IntrospectionUtility.TypeNodeFactory <string>(); Method sample = TestHelper.GetSample <ConstructorSample> (".ctor", stringTypeNode, stringTypeNode, stringTypeNode, stringTypeNode, stringTypeNode); _typeParser.Parse(sample); ProblemCollection result = _typeParser.Problems; Assert.That(TestHelper.ContainsProblemID(c_InjectionCopRuleId, result), Is.True); }
public void Parse_GetValidIdentifier_NoProblem() { TypeNode stringTypeNode = IntrospectionUtility.TypeNodeFactory <string>(); Method sample = TestHelper.GetSample <LostAndFoundSample> ("GetValidIdentifier", stringTypeNode); _typeParser.Parse(sample); ProblemCollection result = _typeParser.Problems; Assert.That(TestHelper.ContainsProblemID(c_InjectionCopRuleId, result), Is.False); }
public void Parse_ConstructorWithFragmentParameterOnlyValidCalls_NoProblem() { TypeNode stringTypeNode = IntrospectionUtility.TypeNodeFactory <string>(); Method sample = TestHelper.GetSample <ConstructorSample> (".ctor", stringTypeNode, stringTypeNode); _typeParser.Parse(sample); ProblemCollection result = _typeParser.Problems; Assert.That(TestHelper.ContainsProblemID(c_InjectionCopRuleId, result), Is.False); }
public void Parse_ConstructorChainingWithBaseClassCorrectFragment_NoProblem() { TypeNode sampleTypeNode = IntrospectionUtility.TypeNodeFactory <InheritanceSampleConstructor>(); Method sample = IntrospectionUtility.MethodFactory(sampleTypeNode, ".ctor"); _typeParser.Parse(sample); ProblemCollection result = _typeParser.Problems; Assert.That(TestHelper.ContainsProblemID(c_InjectionCopRuleId, result), Is.False); }
public void Parse_SafeFragmentOutParameterInsideWhile_NoProblem() { TypeNode stringTypeNode = IntrospectionUtility.TypeNodeFactory <string>(); Method sample = TestHelper.GetSample <OutSample> ("SafeFragmentOutParameterInsideWhile", stringTypeNode.GetReferenceType()); _typeParser.Parse(sample); ProblemCollection result = _typeParser.Problems; Assert.That(TestHelper.ContainsProblemID(c_InjectionCopRuleId, result), Is.False); }
public void Parse_FragmentRefParameterUnsafeReturn_ReturnsProblem() { TypeNode stringTypeNode = IntrospectionUtility.TypeNodeFactory <string>(); Method sample = TestHelper.GetSample <CallByReferenceSample> ("FragmentRefParameterUnsafeReturn", stringTypeNode.GetReferenceType()); _typeParser.Parse(sample); ProblemCollection result = _typeParser.Problems; Assert.That(TestHelper.ContainsProblemID(c_InjectionCopRuleId, result), Is.True); }
public void Parse_UnsafeCallWithSingleVariableSetSafeByIndexer_ReturnsProblem() { TypeNode stringTypeNode = IntrospectionUtility.TypeNodeFactory <string>(); Method sample = TestHelper.GetSample <IndexerSample>("UnsafeCallWithSingleVariableSetSafeByIndexer", stringTypeNode.GetArrayType(1)); _typeParser.Parse(sample); ProblemCollection result = _typeParser.Problems; Assert.That(TestHelper.ContainsProblemID(c_InjectionCopRuleId, result), Is.True); }
public void Parse_SafeCallUsingIndexer_NoProblem() { TypeNode stringTypeNode = IntrospectionUtility.TypeNodeFactory <string>(); Method sample = TestHelper.GetSample <IndexerSample>("SafeCallUsingIndexer", stringTypeNode.GetArrayType(1)); _typeParser.Parse(sample); ProblemCollection result = _typeParser.Problems; Assert.That(TestHelper.ContainsProblemID(c_InjectionCopRuleId, result), Is.False); }