Beispiel #1
0
        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 })));
        }