public SpanishMergedExtractorConfiguration(IDateTimeOptionsConfiguration config) : base(config) { DateExtractor = new BaseDateExtractor(new SpanishDateExtractorConfiguration(this)); TimeExtractor = new BaseTimeExtractor(new SpanishTimeExtractorConfiguration(this)); DateTimeExtractor = new BaseDateTimeExtractor(new SpanishDateTimeExtractorConfiguration(this)); DatePeriodExtractor = new BaseDatePeriodExtractor(new SpanishDatePeriodExtractorConfiguration(this)); TimePeriodExtractor = new BaseTimePeriodExtractor(new SpanishTimePeriodExtractorConfiguration(this)); DateTimePeriodExtractor = new BaseDateTimePeriodExtractor(new SpanishDateTimePeriodExtractorConfiguration(this)); DurationExtractor = new BaseDurationExtractor(new SpanishDurationExtractorConfiguration(this)); SetExtractor = new BaseSetExtractor(new SpanishSetExtractorConfiguration(this)); DateTimeAltExtractor = new BaseDateTimeAltExtractor(new SpanishDateTimeAltExtractorConfiguration(this)); HolidayExtractor = new BaseHolidayExtractor(new SpanishHolidayExtractorConfiguration(this)); TimeZoneExtractor = new BaseTimeZoneExtractor(new SpanishTimeZoneExtractorConfiguration(this)); var numOptions = NumberOptions.None; if ((config.Options & DateTimeOptions.NoProtoCache) != 0) { numOptions = NumberOptions.NoProtoCache; } var numConfig = new BaseNumberOptionsConfiguration(config.Culture, numOptions); IntegerExtractor = Number.Spanish.IntegerExtractor.GetInstance(numConfig); AmbiguityFiltersDict = DefinitionLoader.LoadAmbiguityFilters(DateTimeDefinitions.AmbiguityFiltersDict); }
public void CohesivenessMeasurementTest() { Type[] types = Assembly.GetExecutingAssembly().GetTypes(); ExpectedCohesivenessAttribute expectedCoh; double coh; foreach (Type type in types) { if (0 == type.GetCustomAttributes(typeof(ExpectedCohesivenessAttribute), false).Length) { continue; } expectedCoh = (ExpectedCohesivenessAttribute) type.GetCustomAttributes( typeof(ExpectedCohesivenessAttribute), false)[0]; AvoidLackOfCohesionOfMethodsRule rule = new AvoidLackOfCohesionOfMethodsRule(); coh = rule.GetCohesivenessForType( DefinitionLoader.GetTypeDefinition(type)); Assert.IsTrue( Math.Abs(coh - expectedCoh.Value) <= expectedCoh.Delta, "Cohesiveness for type '{0}' is {1} but should have been {2} +/- {3}.", type, coh, expectedCoh.Value, expectedCoh.Delta); } }
public void Ignores() { AssemblyDefinition assembly = DefinitionLoader.GetAssemblyDefinition <BadIgnore> (); int expected = assembly.MainModule.HasSymbols ? 2 : 1; AssertRuleFailure <BadIgnore> (expected); }
public DutchMergedExtractorConfiguration(IDateTimeOptionsConfiguration config) : base(config) { DateExtractor = new BaseDateExtractor(new DutchDateExtractorConfiguration(this)); TimeExtractor = new BaseTimeExtractor(new DutchTimeExtractorConfiguration(this)); DateTimeExtractor = new BaseDateTimeExtractor(new DutchDateTimeExtractorConfiguration(this)); DatePeriodExtractor = new BaseDatePeriodExtractor(new DutchDatePeriodExtractorConfiguration(this)); TimePeriodExtractor = new BaseTimePeriodExtractor(new DutchTimePeriodExtractorConfiguration(this)); DateTimePeriodExtractor = new BaseDateTimePeriodExtractor(new DutchDateTimePeriodExtractorConfiguration(this)); DurationExtractor = new BaseDurationExtractor(new DutchDurationExtractorConfiguration(this)); SetExtractor = new BaseSetExtractor(new DutchSetExtractorConfiguration(this)); HolidayExtractor = new BaseHolidayExtractor(new DutchHolidayExtractorConfiguration(this)); TimeZoneExtractor = new BaseTimeZoneExtractor(new DutchTimeZoneExtractorConfiguration(this)); DateTimeAltExtractor = new BaseDateTimeAltExtractor(new DutchDateTimeAltExtractorConfiguration(this)); var numOptions = NumberOptions.None; if ((config.Options & DateTimeOptions.NoProtoCache) != 0) { numOptions = NumberOptions.NoProtoCache; } var numConfig = new BaseNumberOptionsConfiguration(config.Culture, numOptions); IntegerExtractor = Number.Dutch.IntegerExtractor.GetInstance(numConfig); AmbiguityFiltersDict = DefinitionLoader.LoadAmbiguityFilters(DateTimeDefinitions.AmbiguityFiltersDict); if ((Options & DateTimeOptions.EnablePreview) != 0) { SuperfluousWordMatcher.Init(DateTimeDefinitions.SuperfluousWordList); } }
/// <summary> /// Asserts that the rule has failed to execute successfully for each method in the type. /// </summary> /// <typeparam name="T">Type containing the methods.</typeparam> /// <param name="expectedCount">Expected defect count for each method.</param> protected void AssertRuleFailure <T> (int expectedCount) { foreach (MethodDefinition method in DefinitionLoader.GetTypeDefinition <T> ().Methods) { base.AssertRuleFailure(method, expectedCount); } }
public ChineseMergedExtractorConfiguration(IDateTimeOptionsConfiguration config) { this.config = config; AmbiguityFiltersDict = DefinitionLoader.LoadAmbiguityFilters(DateTimeDefinitions.AmbiguityFiltersDict); HolidayExtractor = new BaseHolidayExtractor(new ChineseHolidayExtractorConfiguration(config)); }
/// <summary> /// Asserts that the rule has been executed successfully for each method in the type. /// </summary> /// <typeparam name="T">Type containing the methods.</typeparam> protected void AssertRuleSuccess <T> () { foreach (MethodDefinition method in DefinitionLoader.GetTypeDefinition <T> ().Methods) { base.AssertRuleSuccess(method); } }
public void FixtureSetUp() { assembly = AssemblyDefinition.CreateAssembly(new AssemblyNameDefinition("CLSCompliant", new Version()), "CLSCompliant", ModuleKind.Dll); comvisible = new CustomAttribute(DefinitionLoader.GetMethodDefinition <ComVisibleAttribute> (".ctor")); clscompliant = new CustomAttribute(DefinitionLoader.GetMethodDefinition <CLSCompliantAttribute> (".ctor")); Runner.Engines.Subscribe("Gendarme.Framework.Engines.SuppressMessageEngine"); }
public void SetUp() { // A type always has a method (implicit constructor) so we have to hack our own // methodless class. DoesNotApplyClassSpecial = DefinitionLoader.GetTypeDefinition <DoesNotApplyClass1> (); DoesNotApplyClassSpecial.Methods.Clear(); }
public void FxCop_GloballySuppressed() { AssemblyDefinition assembly = DefinitionLoader.GetAssemblyDefinition(this.GetType()); // see GlobalSuppressions.cs AssertRuleDoesNotApply(assembly); }
public void FxCop_ManuallySuppressed() { AssemblyDefinition assembly = CreateAssembly("SuppressedVersion", ModuleKind.Dll); TypeDefinition type = DefinitionLoader.GetTypeDefinition <SuppressMessageAttribute> (); MethodDefinition ctor = DefinitionLoader.GetMethodDefinition(type, ".ctor", new Type [] { typeof(string), typeof(string) }); CustomAttribute ca = new CustomAttribute(assembly.MainModule.Import(ctor)); ca.ConstructorArguments.Add( new CustomAttributeArgument( assembly.MainModule.TypeSystem.String, "Microsoft.Design")); ca.ConstructorArguments.Add( new CustomAttributeArgument( assembly.MainModule.TypeSystem.String, "CA1016:MarkAssembliesWithAssemblyVersion")); assembly.CustomAttributes.Add(ca); var stream = new MemoryStream(); assembly.Write(stream); stream.Position = 0; assembly = AssemblyDefinition.ReadAssembly(stream); AssertRuleDoesNotApply(assembly); }
private void AssertClass <T> () { TestRunner runner; bool failed = false; RuleResult result; // // We assert that exactly 1 error is raised among all the methods in the class // runner = new TestRunner(new DelegatesPassedToNativeCodeMustIncludeExceptionHandlingRule()); foreach (MethodDefinition method in DefinitionLoader.GetTypeDefinition <T> ().Methods) { result = runner.CheckMethod(method); if (result == RuleResult.Failure) { Assert.IsFalse(failed); Assert.AreEqual(1, runner.Defects.Count); failed = true; } } Assert.IsTrue(failed); }
/// <summary> /// Asserts that the rule does not apply to all methods of the type. /// </summary> /// <typeparam name="T">Type containing the methods.</typeparam> protected void AssertRuleDoesNotApply <T> () { foreach (MethodDefinition method in DefinitionLoader.GetTypeDefinition <T> ().Methods) { base.AssertRuleDoesNotApply(method); } }
public void AnonymousMethodTest() { MethodDefinition method = null; // compiler generated code is compiler dependant, check for [g]mcs (inner type) TypeDefinition type = DefinitionLoader.GetTypeDefinition(typeof(AvoidUnusedParametersTest).Assembly, "AvoidUnusedParametersTest/<>c__CompilerGenerated0"); if (type != null) { method = DefinitionLoader.GetMethodDefinition(type, "<AnonymousMethodWithUnusedParameters>c__2", null); } // otherwise try for csc (inside same class) if (method == null) { type = DefinitionLoader.GetTypeDefinition <AvoidUnusedParametersTest> (); foreach (MethodDefinition md in type.Methods) { if (md.Name.StartsWith("<AnonymousMethodWithUnusedParameters>")) { method = md; break; } } } Assert.IsNotNull(method, "method not found!"); AssertRuleDoesNotApply(method); }
public void StaticType() { // the nice generic-based test syntax won't work on static types :( Assembly a = typeof(AvoidConstructorsInStaticTypesTest).Assembly; TypeDefinition type = DefinitionLoader.GetTypeDefinition(a, "Test.Rules.Correctness.AvoidConstructorsInStaticTypesTest/StaticClass"); AssertRuleDoesNotApply(type); }
public void FixtureSetUp() { AssemblyDefinition assembly = DefinitionLoader.GetAssemblyDefinition <AvoidLongMethodsTest> (); if (!assembly.MainModule.HasSymbols) { Assert.Ignore("Debugging symbols non-available to compute SLOC."); } }
public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer) { // There should not be an existing value, but if there is it will be overwritten. Debug.Assert(objectType == typeof(Type)); string s = (string)reader.Value; return(DefinitionLoader.FindType(s)); }
public void RaiseAnalyzeModuleEvent() { if (raisedAnalyzeModuleEvent) { return; } raisedAnalyzeModuleEvent = true; ((TestRunner)Runner).OnModule(DefinitionLoader.GetTypeDefinition <PreferXmlAbstractionsTest> ().Module); }
public void Cecil() { // Cecil reports what being set on the type, not how the runtime treats it TypeDefinition nse = DefinitionLoader.GetTypeDefinition <NonSerializableEnum> (); Assert.IsFalse(nse.IsSerializable, "NonSerializableEnum"); TypeDefinition se = DefinitionLoader.GetTypeDefinition <SerializableEnum> (); Assert.IsTrue(se.IsSerializable, "SerializableEnum"); }
public void IsComVisible() { TypeDefinition type = DefinitionLoader.GetTypeDefinition <ExplicitComVisibleClass> (); Assert.IsTrue(type.IsComVisible() ?? false, "true"); type = SimpleTypes.Class; Assert.IsNull(type.IsComVisible(), "null"); type = DefinitionLoader.GetTypeDefinition <ExplicitComInvisibleClass> (); Assert.IsFalse(type.IsComVisible() ?? true, "false"); }
protected JapaneseNumberWithUnitExtractorConfiguration(CultureInfo ci) { this.CultureInfo = ci; this.UnitNumExtractor = new NumberExtractor(CJKNumberExtractorMode.ExtractAll); this.BuildPrefix = NumbersWithUnitDefinitions.BuildPrefix; this.BuildSuffix = NumbersWithUnitDefinitions.BuildSuffix; this.ConnectorToken = NumbersWithUnitDefinitions.ConnectorToken; AmbiguityFiltersDict = DefinitionLoader.LoadAmbiguityFilters(NumbersWithUnitDefinitions.AmbiguityFiltersDict); }
public ChinesePhoneNumberExtractorConfiguration(SequenceOptions options) : base(options) { WordBoundariesRegex = PhoneNumbersDefinitions.WordBoundariesRegex; NonWordBoundariesRegex = PhoneNumbersDefinitions.NonWordBoundariesRegex; EndWordBoundariesRegex = PhoneNumbersDefinitions.EndWordBoundariesRegex; ColonPrefixCheckRegex = new Regex(PhoneNumbersDefinitions.ColonPrefixCheckRegex); ForbiddenPrefixMarkers = (List <char>)PhoneNumbersDefinitions.ForbiddenPrefixMarkers; AmbiguityFiltersDict = AmbiguityFiltersDict = DefinitionLoader.LoadAmbiguityFilters(BasePhoneNumbers.AmbiguityFiltersDict); }
public void Yield() { AssertRuleSuccess <CompilerGeneratedInnerIterator> ("TypesInside"); TypeDefinition inner = (DefinitionLoader.GetTypeDefinition <CompilerGeneratedInnerIterator> ().NestedTypes [0] as TypeDefinition); foreach (MethodDefinition method in inner.Methods) { AssertRuleDoesNotApply(method); } }
public void RaiseAnalyzeModuleEvent() { if (raisedAnalyzeModuleEvent) { return; } raisedAnalyzeModuleEvent = true; ((TestRunner)Runner).OnModule(DefinitionLoader.GetTypeDefinition <XmlCases> ().Module); }
protected HindiNumberWithUnitExtractorConfiguration(CultureInfo ci) { this.CultureInfo = ci; this.UnitNumExtractor = NumberExtractor.GetInstance(NumberMode.Unit); this.BuildPrefix = NumbersWithUnitDefinitions.BuildPrefix; this.BuildSuffix = NumbersWithUnitDefinitions.BuildSuffix; this.ConnectorToken = string.Empty; AmbiguityFiltersDict = DefinitionLoader.LoadAmbiguityFilters(NumbersWithUnitDefinitions.AmbiguityFiltersDict); }
public void Unrestricted_Boolean() { TypeDefinition t = DefinitionLoader.GetTypeDefinition <UnrestrictedTrue> (); PermissionSet ps = t.SecurityDeclarations [0].ToPermissionSet(); Assert.IsTrue(ps.IsUnrestricted(), "IsUnrestricted"); t = DefinitionLoader.GetTypeDefinition <UnrestrictedFalse> (); ps = t.SecurityDeclarations [0].ToPermissionSet(); Assert.IsFalse(ps.IsUnrestricted(), "!IsUnrestricted"); }
public JapaneseDurationExtractorConfiguration(IDateTimeOptionsConfiguration config, bool merge = true) : base(config) { this.merge = merge; InternalExtractor = new NumberWithUnitExtractor(new DurationExtractorConfiguration()); UnitMap = DateTimeDefinitions.ParserConfigurationUnitMap.ToDictionary(k => k.Key, k => k.Value); UnitValueMap = DateTimeDefinitions.DurationUnitValueMap; AmbiguityDurationFiltersDict = DefinitionLoader.LoadAmbiguityFilters(DateTimeDefinitions.AmbiguityDurationFiltersDict); }
public void Bad() { MethodDefinition m = DefinitionLoader.GetMethodDefinition <ProvideMessageOnAssertCallsTest> ("BadTestAttribute"); m.AddTestAttribute(); AssertRuleFailure(m, 2); m = DefinitionLoader.GetMethodDefinition <ProvideMessageOnAssertCallsTest> ("FourBadAsserts"); m.AddTestAttribute(); AssertRuleFailure(m, 4); }
public void DoesNotApplyGeneratedCode() { var declaring_type = DefinitionLoader.GetTypeDefinition <HasFinalizer> (); Assert.IsTrue(declaring_type.HasNestedTypes, "HasFinalizer-HasNestedTypes"); Assert.AreEqual(1, declaring_type.NestedTypes.Count, "HasFinalized-NestedTypesCount-1"); var type = declaring_type.NestedTypes [0]; Assert.IsTrue(type.IsGeneratedCode(), "NestedType-IsGeneratedCode-True"); AssertRuleDoesNotApply(type); }
public void EntryPoint() { MethodDefinition main = DefinitionLoader.GetMethodDefinition <InstantiatedInternalClass> ("Main"); try { main.DeclaringType.Module.Assembly.EntryPoint = main; AssertRuleSuccess(main.DeclaringType.Resolve()); } finally { main.DeclaringType.Module.Assembly.EntryPoint = null; } }
public DefinitionsService() { _defLoader = new DefinitionLoader(this); _propLoader = new PropertyLoader(this); _taxLoader = new TaxonLoader(this); }