Esempio n. 1
0
        public void SqlFlagListOptionBehaviour_WhenWePassValidItems_TheyAssignedCorrectly()
        {
            var optionValueFactory = new OptionValueFactory();
            var optionValue        = optionValueFactory.Create(OptionValueType.String);
            var query        = Fake <string>();
            var value        = Fake <string>();
            var displayValue = Fake <string>();

            var actual = new SqlFlagListOptionBehaviour(optionValue, query, value, displayValue);

            Assert.That(actual.Query, Is.EqualTo(query));
            Assert.That(actual.ValueMember, Is.EqualTo(value));
            Assert.That(actual.DisplayMember, Is.EqualTo(displayValue));
        }
Esempio n. 2
0
        private bool TryCreateBehaviour(XElement root, IOptionValue optionValue, out OptionBehaviour optionBehaviour)
        {
            string name = root.Name.LocalName;

            optionBehaviour = null;

            switch (name)
            {
            case RangedMinMaxElement.ElementName:
            {
                string min = ReplaceConstants <string>(root, RangedMinMaxElement.Attrs.Min);
                string max = ReplaceConstants <string>(root, RangedMinMaxElement.Attrs.Max);
                optionBehaviour = new RangedOptionBehaviour(optionValue, min, max);
            }
            break;

            case RangedMaxElement.ElementName:
            {
                string max = ReplaceConstants <string>(root, RangedMaxElement.Attrs.Max);
                optionBehaviour = new RangedOptionBehaviour(optionValue, max, false);
            }
            break;

            case RangedMinElement.ElementName:
            {
                string min = ReplaceConstants <string>(root, RangedMinElement.Attrs.Min);
                optionBehaviour = new RangedOptionBehaviour(optionValue, min, true);
            }
            break;

            case FixedListElement.ElementName:
                optionBehaviour = CreateFixedListBehaviour(root, optionValue);
                break;

            case FlagListElement.ElementName:
                optionBehaviour = CreateFlagListBehaviour(root, optionValue);
                break;

            case MultiListElement.ElementName:
            {
                bool   sorted    = DataConversion.Convert <bool>(ReplaceConstants(root.TryGetAttributeValue(MultiListElement.Attrs.Sorted, MultiListElement.Attrs.Defaults.Sorted).ToString()));
                string separator = ReplaceConstants(root.TryGetAttributeValue(MultiListElement.Attrs.Separator, MultiListElement.Attrs.Defaults.Separator));
                optionBehaviour = CreateMultiListBehaviour(root, optionValue, sorted, separator);
            }
            break;

            case SqlFixedListElement.ElementName:
            {
                string query                 = ReplaceConstants <string>(root, SqlFixedListElement.Attrs.Query);
                string valueFieldName        = ReplaceConstants(root.TryGetAttributeValue(SqlFixedListElement.Attrs.ValueFieldName, SqlFixedListElement.Attrs.Defaults.ValueFieldName));
                string displayValueFieldName = ReplaceConstants(root.TryGetAttributeValue(SqlFixedListElement.Attrs.DisplayValueFieldName, SqlFixedListElement.Attrs.Defaults.DisplayValueFieldName));
                optionBehaviour = new SqlFixedListOptionBehaviour(optionValue, query, valueFieldName, displayValueFieldName);
            }
            break;

            case SqlFlagListElement.ElementName:
            {
                string query                 = ReplaceConstants <string>(root, SqlFlagListElement.Attrs.Query);
                string valueFieldName        = ReplaceConstants(root.TryGetAttributeValue(SqlFlagListElement.Attrs.ValueFieldName, SqlFlagListElement.Attrs.Defaults.ValueFieldName));
                string displayValueFieldName = ReplaceConstants(root.TryGetAttributeValue(SqlFlagListElement.Attrs.DisplayValueFieldName, SqlFlagListElement.Attrs.Defaults.DisplayValueFieldName));
                optionBehaviour = new SqlFlagListOptionBehaviour(optionValue, query, valueFieldName, displayValueFieldName);
            }
            break;

            case SqlMultiListElement.ElementName:
            {
                string query                 = ReplaceConstants <string>(root, SqlMultiListElement.Attrs.Query);
                bool   sorted                = DataConversion.Convert <bool>(ReplaceConstants(root.TryGetAttributeValue(SqlMultiListElement.Attrs.Sorted, SqlMultiListElement.Attrs.Defaults.Sorted).ToString()));
                string separator             = ReplaceConstants(root.TryGetAttributeValue(SqlMultiListElement.Attrs.Separator, SqlMultiListElement.Attrs.Defaults.Separator));
                string valueFieldName        = ReplaceConstants(root.TryGetAttributeValue(SqlMultiListElement.Attrs.ValueFieldName, SqlMultiListElement.Attrs.Defaults.ValueFieldName));
                string displayValueFieldName = ReplaceConstants(root.TryGetAttributeValue(SqlMultiListElement.Attrs.DisplayValueFieldName, SqlMultiListElement.Attrs.Defaults.DisplayValueFieldName));
                optionBehaviour = new SqlMultiListOptionBehaviour(optionValue, query, sorted, separator, valueFieldName, displayValueFieldName);
            }
            break;
            }

            return(optionBehaviour != null);
        }
Esempio n. 3
0
        private bool TryCreateBehaviour(XElement root, IOptionValue optionValue, out OptionBehaviour optionBehaviour)
        {
            string name = root.Name.LocalName;

            optionBehaviour = null;

            switch (name)
            {
            case "rangedMinMax":
            {
                string min = root.GetAttributeValue <string>("min");
                string max = root.GetAttributeValue <string>("max");
                optionBehaviour = new RangedOptionBehaviour(optionValue, min, max);
            }
            break;

            case "rangedMax":
            {
                string max = root.GetAttributeValue <string>("max");
                optionBehaviour = new RangedOptionBehaviour(optionValue, max, false);
            }
            break;

            case "rangedMin":
            {
                string min = root.GetAttributeValue <string>("min");
                optionBehaviour = new RangedOptionBehaviour(optionValue, min, true);
            }
            break;

            case "fixedList":
                optionBehaviour = CreateFixedListBehaviour(root, optionValue);
                break;

            case "flagList":
                optionBehaviour = CreateFlagListBehaviour(root, optionValue);
                break;

            case "multiList":
            {
                bool   sorted    = root.GetAttributeValue <bool>("sorted");
                string separator = root.GetAttributeValue <string>("separator");
                optionBehaviour = CreateMultiListBehaviour(root, optionValue, sorted, separator);
            }
            break;

            case "sqlFixedList":
            {
                string query                 = root.GetAttributeValue <string>("query");
                string valueFieldName        = root.GetAttributeValue <string>("valueFieldName");
                string displayValueFieldName = root.GetAttributeValue <string>("displayValueFieldName");
                optionBehaviour = new SqlFixedListOptionBehaviour(optionValue, query, valueFieldName, displayValueFieldName);
            }
            break;

            case "sqlFlagList":
            {
                string query                 = root.GetAttributeValue <string>("query");
                string valueFieldName        = root.GetAttributeValue <string>("valueFieldName");
                string displayValueFieldName = root.GetAttributeValue <string>("displayValueFieldName");
                optionBehaviour = new SqlFlagListOptionBehaviour(optionValue, query, valueFieldName, displayValueFieldName);
            }
            break;

            case "sqlMultiList":
            {
                string query                 = root.GetAttributeValue <string>("query");
                bool   sorted                = root.GetAttributeValue <bool>("sorted");
                string separator             = root.GetAttributeValue <string>("separator");
                string valueFieldName        = root.GetAttributeValue <string>("valueFieldName");
                string displayValueFieldName = root.GetAttributeValue <string>("displayValueFieldName");
                optionBehaviour = new SqlMultiListOptionBehaviour(optionValue, query, sorted, separator, valueFieldName, displayValueFieldName);
            }
            break;
            }

            return(optionBehaviour != null);
        }