public void Setup() { AnalyzerResult = new AnalyzerResult(); var conditionMetadata = new ConditionMetadata(); _conditionThatIsAlwaysTrue = new Mock <Condition>(conditionMetadata); _conditionThatIsAlwaysTrue.Setup(x => x.IsConditionMet(AnalyzerResult)).Returns(true); _conditionThatIsAlwaysFalse = new Mock <Condition>(conditionMetadata); _conditionThatIsAlwaysFalse.Setup(x => x.IsConditionMet(AnalyzerResult)).Returns(false); ConditionMetadata = new ConditionMetadata { Type = ConditionType.XmlFileQuery, Properties = new Dictionary <string, object> { { "FileNamePatterns", new[] { "SomeFile", "SomeOtherFile" } }, { "XmlElementPath", "path/to/element" } } }; ConditionGroupMetadata = new ConditionGroupMetadata { JoinOperator = JoinOperator.All, Conditions = new[] { ConditionMetadata, ConditionMetadata } }; ConditionGroupsMetadata = new[] { ConditionGroupMetadata, ConditionGroupMetadata }; }
/// <summary> /// Get instance of a condition from condition metadata /// </summary> /// <param name="conditionMetadata">Metadata specifying the type of condition to instantiate and its property values</param> /// <returns>Condition instance</returns> public static Condition GetCondition(ConditionMetadata conditionMetadata) { var assembly = Assembly.GetAssembly(typeof(Condition)); var className = ConditionTypeEnumToClassName(conditionMetadata.Type); var conditionType = assembly.GetTypes().SingleOrDefault(t => t.Name == className); if (conditionType == null) { throw new ClassNotFoundException(assembly, className); } if (!(Activator.CreateInstance(conditionType, conditionMetadata) is Condition conditionInstance)) { throw new InvalidCastException($"Type {className} cannot be cast to {typeof(Condition)}"); } return(conditionInstance); }
public void IsConditionMet_Returns_True_If_Attribute_Values_Are_Found() { var testXmlFileDirectory = Path.Combine(_testProjectDirectory, "Examples", "XmlFiles"); var conditionMetadata = new ConditionMetadata { Type = ConditionType.XmlFileQuery, MatchType = true, Properties = new Dictionary <string, object> { { "FileNamePatterns", new [] { "TestAppConfig1.xml" } }, { "SearchPath", testXmlFileDirectory }, { "SearchOption", SearchOption.AllDirectories }, { "IgnoreCase", RegexOptions.IgnoreCase }, { "XmlElementPath", "configuration/connectionStrings/add" }, { "XmlElementAttributes", new Dictionary <string, object> { { "providerName", "System.Data.SqlClient" } } } } }; var xmlFileQueryCondition = new XmlFileQueryCondition(conditionMetadata); Assert.True(xmlFileQueryCondition.IsConditionMet(null)); }
protected Condition(ConditionMetadata conditionMetadata) { MatchType = conditionMetadata.MatchType; PopulateProperties(conditionMetadata.Properties); }
/// <summary> /// Factory method that dynamically instantiates a configured feature using condition metadata /// </summary> /// <param name="featureScope">The scope in which to look for this feature</param> /// <param name="name">Name of the feature</param> /// <param name="conditionMetadata">Metadata defining the feature condition</param> /// <returns>Instance of the defined feature</returns> public static ConfiguredFeature GetInstance(FeatureScope featureScope, string name, ConditionMetadata conditionMetadata) { var condition = ConditionFactory.GetCondition(conditionMetadata); return(new ConfiguredFeature(featureScope, name, condition)); }
public XmlFileQueryCondition(ConditionMetadata conditionMetadata) : base(conditionMetadata) { }