Example #1
0
    public static void StringsEqualIgnoreWhiteSpace(string x, string y, StringComparisonType comparisonType)
    {
        Action act = () => x.MustNotBe(y, comparisonType, nameof(x));

        act.Should().Throw <ValuesEqualException>()
        .And.Message.Should().Contain($"{nameof(x)} must not be equal to {y.ToStringOrNull()}, but it actually is {x.ToStringOrNull()}");
    }
Example #2
0
    public static void StringsNotEqualIgnoreWhiteSpace(string first, string second, StringComparisonType comparisonType)
    {
        Action act = () => first.MustBe(second, comparisonType, nameof(first));

        act.Should().Throw <ValuesNotEqualException>()
        .And.Message.Should().Contain($"{nameof(first)} must be equal to {second.ToStringOrNull()}, but it actually is {first.ToStringOrNull()}.");
    }
        private void LoadRegexMatchExpression(StringComparisonType stringComparisonType)
        {
            //for a string the comparison type should always be contains, startswith, endswith etc are not supported in this class
            if (stringComparisonType == StringComparisonType.Contains ||
                stringComparisonType == StringComparisonType.NotContains)
            {
                //stringcomparisonType denotes items that are compatible with the contains function in c# for this class it means
                //that we are comparing the property on the left with a regex match call on the right

                if (_caseSensitive)
                {
                    //default behaviour of .net is to do it case sensitive match
                    _wildCard       = new WildCard(_originalValueToCompare);
                    _patternToMatch = _wildCard.WildcardToRegex(_originalValueToCompare);
                }
                else
                {
                    //only if specified will it do a case insensitive match
                    _wildCard       = new WildCard(_originalValueToCompare, RegexOptions.IgnoreCase);
                    _patternToMatch = _wildCard.WildcardToRegex(_originalValueToCompare.ToLower());
                }

                BuildRegexMatchMethodInvokeExpression();
            }
            else
            {
                throw new ApplicationException("Wildcard search is not supported for any string compare types other than Contains or No Contains");
            }
        }
        public static bool IsStringComparisonOperator(OperatorTypes operatorTypes)
        {
            StringComparisonType stringComparisonType = TranslationHelper.StringComparisonValidTypes(operatorTypes);

            if (stringComparisonType != StringComparisonType.NotSupported)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
        public WildCardSearchExpression(CodeExpression leftExpression, string valueToCompare, StringComparisonType stringComparisonType, bool caseSensitive)
        {
            // constructor required by parser
            _leftExpression         = leftExpression;
            _stringComparisonType   = stringComparisonType;
            _originalValueToCompare = valueToCompare;
            _caseSensitive          = caseSensitive;

            if (_leftExpression == null || String.IsNullOrEmpty(_originalValueToCompare) || _stringComparisonType == StringComparisonType.NotSupported)
            {
                throw new ApplicationException("left expression is null or value to compare is null or empty or string comparison type is not supported");
            }
            LoadRegexMatchExpression(_stringComparisonType);
        }
Example #6
0
 public static void StringsNotEqualIgnoreWhiteSpace(string x, string y, StringComparisonType comparisonType) =>
 x.MustNotBe(y, comparisonType).Should().BeSameAs(x);
Example #7
0
 /// <summary>
 /// Constructs a new access control policy condition that compares two
 /// strings.
 /// </summary>
 /// <param name="type">The type of comparison to perform</param>
 /// <param name="key">The access policy condition key specifying where to get the
 ///            first string for the comparison (ex: aws:UserAgent).
 ///            <see cref="Amazon.Auth.Conditions.AWSCommonConditions"/>
 /// </param>
 /// <param name="value">The second string to compare against. When using
 ///            StringComparisonType.StringLike or
 ///            StringComparisonType.StringNotLike this may contain
 ///            the multi-character wildcard (*) or the single-character
 ///            wildcard (?).
 /// </param>
 public static Condition NewCondition(StringComparisonType type, string key, string value)
 {
     return(new Condition(type.ToString(), key, value));
 }
Example #8
0
 public OrderedString(string value, StringComparisonType comparisonType = StringComparisonType.CulureInvariantCaseSensitive)
 {
     Value          = value ?? throw new ArgumentNullException(nameof(value));
     ComparisonType = comparisonType;
 }
Example #9
0
 private void ArrayTest(string[] dataArray, string searchValue, StringComparisonType compareType)
 {
     Array.ForEach(dataArray,
         name =>
             sw.WriteLine("{0:0.00000} arainst \'{1}\'", _method.GetRate(searchValue, name, compareType), name));
 }
Example #10
0
 private void SpeedTest(int count, StringComparisonType compareType)
 {
     var records = PrepareData(count);
     var timer = new Stopwatch();
     timer.Start();
     for (var i = 0; i < count; i++)
     {
         for (var j = 0; j < count; j++)
         {
             _method.IsEqual(records[i], records[j]);
         }
     }
     timer.Stop();
     var totalTime = timer.ElapsedMilliseconds;
     sw.WriteLine("{0} ms for {1} operations", totalTime, count*count);
     sw.WriteLine();
 }
Example #11
0
 /// <summary>
 /// Constructs a new access control policy condition that compares two
 /// strings.
 /// </summary>
 /// <param name="type">The type of comparison to perform</param>
 /// <param name="key">The access policy condition key specifying where to get the
 ///            first string for the comparison (ex: aws:UserAgent). 
 ///            <see cref="Amazon.Auth.Conditions.AWSCommonConditions"/>
 /// </param>
 /// <param name="value">The second string to compare against. When using
 ///            StringComparisonType.StringLike or
 ///            StringComparisonType.StringNotLike this may contain
 ///            the multi-character wildcard (*) or the single-character
 ///            wildcard (?).
 /// </param>
 public static Condition NewCondition(StringComparisonType type, string key, string value)
 {
     return new Condition(type.ToString(), key, value);
 }