public void MockSetupEqualsByInvocationAndMatchers() { var method = new Action <bool, string, PlatformID>(AMethod).Method; var args = new object[] { true, "foo", PlatformID.Win32NT }; var target = this; var any = AnyMatcher <string> .Default; Func <string, bool> condition = s => s.Length > 0; var conditional = new ConditionalMatcher <string>(condition, "foo"); var value = new ValueMatcher(typeof(string), "foo"); var setup = new MockSetup(new MethodInvocation(target, method, args), new[] { any, conditional, value }); var other = new MockSetup(new MethodInvocation(target, method, args), new[] { any, conditional, value }); Assert.True(setup.Equals(other)); Assert.Equal(setup.GetHashCode(), other.GetHashCode()); var hash = new HashSet <IMockSetup>(); Assert.True(hash.Add(setup)); Assert.False(hash.Add(other)); Assert.Contains(setup, hash); Assert.Contains(other, hash); Assert.False(setup.Equals( new MockSetup(new MethodInvocation(new object(), method, args), new[] { any, conditional, value }))); }
public void Matchers() { var hash = new HashSet <IArgumentMatcher>(); var value1 = new ValueMatcher(typeof(string), "foo"); var value2 = new ValueMatcher(typeof(string), "foo"); Assert.True(hash.Add(value1)); Assert.False(hash.Add(value2)); }
public void ValueMatcherEqualsByTypeAndValue() { var matcher = new ValueMatcher(typeof(string), "foo"); var other = new ValueMatcher(typeof(string), "foo"); Assert.True(matcher.Equals(other)); Assert.Equal(matcher.GetHashCode(), other.GetHashCode()); Assert.False(matcher.Equals(new ValueMatcher(typeof(string), "bar"))); Assert.False(matcher.Equals(new ValueMatcher(typeof(object), "foo"))); }
public void ValueMatcherEqualsByEqualityComparer() { var comparer = StringComparer.OrdinalIgnoreCase; var matcher = new ValueMatcher(typeof(string), "foo", comparer); var other = new ValueMatcher(typeof(string), "FOO", comparer); Assert.True(matcher.Equals(other)); Assert.Equal(matcher.GetHashCode(), other.GetHashCode()); Assert.False(matcher.Equals(new ValueMatcher(typeof(string), "bar"))); Assert.False(matcher.Equals(new ValueMatcher(typeof(object), "foo"))); }
public void TupleOfEqualMatchersAreEqual() { var any = AnyMatcher <string> .Default; Func <string, bool> condition = s => s.Length > 0; var conditional = new ConditionalMatcher <string>(condition, "foo"); var value = new ValueMatcher(typeof(string), "foo"); var t1 = Tuple.Create(any, conditional, value); var t2 = Tuple.Create(any, conditional, value); Assert.True(t1.Equals(t2)); Assert.Equal(t1.GetHashCode(), t2.GetHashCode()); }
public void Setup() { _matcher = new ValueMatcher(); }
public LookupFunction(ValueMatcher valueMatcher, CompileResultFactory compileResultFactory) { _valueMatcher = valueMatcher; _compileResultFactory = compileResultFactory; }
protected CompileResult Lookup(LookupNavigator navigator, LookupArguments lookupArgs, ValueMatcher valueMatcher) { object lastValue = null; object lastLookupValue = null; int? lastMatchResult = null; if (lookupArgs.SearchedValue == null) { return(new CompileResult(eErrorType.NA)); } do { var matchResult = valueMatcher.IsMatch(lookupArgs.SearchedValue, navigator.CurrentValue); if (matchResult != 0) { if (lastValue != null && navigator.CurrentValue == null) { break; } if (!lookupArgs.RangeLookup) { continue; } if (lastValue == null && matchResult < 0) { return(new CompileResult(eErrorType.NA)); } if (lastValue != null && matchResult < 0 && lastMatchResult > 0) { return(new CompileResultFactory().Create(lastLookupValue)); } lastMatchResult = matchResult; lastValue = navigator.CurrentValue; lastLookupValue = navigator.GetLookupValue(); } else { return(new CompileResultFactory().Create(navigator.GetLookupValue())); } }while (navigator.MoveNext()); return(lookupArgs.RangeLookup ? new CompileResultFactory().Create(lastLookupValue) : new CompileResult(eErrorType.NA)); }
public LookupFunction(ValueMatcher valueMatcher) { _valueMatcher = valueMatcher; }