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 ConditionalMatcherEqualsByConditionFunctionAndName() { Func <string, bool> condition = s => s.Length > 0; var matcher = new ConditionalMatcher <string>(condition, "foo"); Assert.True(matcher.Equals(new ConditionalMatcher <string>(condition, "foo"))); Assert.True(matcher.Equals(new ConditionalMatcher <string>(condition, "foo"), EqualityComparer <object> .Default)); Assert.Equal(matcher.GetHashCode(), new ConditionalMatcher <string>(condition, "foo").GetHashCode()); Assert.Equal(matcher.GetHashCode(EqualityComparer <object> .Default), new ConditionalMatcher <string>(condition, "foo").GetHashCode(EqualityComparer <object> .Default)); Assert.False(matcher.Equals(new ConditionalMatcher <string>(condition, "bar"))); Assert.False(matcher.Equals(new ConditionalMatcher <string>(s => s.Length > 0, "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 EqualsByConditionFunctionAndName() { Func <string, bool> condition = s => s.Length > 0; var matcher = new ConditionalMatcher <string>(condition, "foo"); Assert.True(matcher.Equals(new ConditionalMatcher <string>(condition, "foo"))); Assert.Equal(matcher.GetHashCode(), new ConditionalMatcher <string>(condition, "foo").GetHashCode()); Assert.False(matcher.Equals(new ConditionalMatcher <string>(condition, "bar"))); Assert.False(matcher.Equals(new ConditionalMatcher <string>(s => s.Length > 0, "foo"))); Assert.False(matcher.Equals(new ConditionalMatcher <int>(_ => true, "foo"))); }
public void DoesNotMatchNullForNonNullableValueType() { var matcher = new ConditionalMatcher <PlatformID>(_ => true); Assert.False(matcher.Matches(null)); }
public void MatchesNullForReferenceType() { var matcher = new ConditionalMatcher <string>(x => x == null); Assert.True(matcher.Matches(default(string))); }
public void MatchesNullForNullableValueType() { var matcher = new ConditionalMatcher <PlatformID?>(_ => true); Assert.True(matcher.Matches(null)); }