예제 #1
0
        public void Should_not_allow_register_type_twice()
        {
            EasyHash <Foo> .Reset();

            EasyHash <Foo> .Register(r => { });

            EasyHash <Foo> .Register(r => { });

            Action action = () => new Foo().GetHashCode();

            action.ShouldThrow <InvalidOperationException>();
        }
예제 #2
0
        public void Should_use_custom_hashing_if_registered()
        {
            var foo = new Foo();

            EasyHash <Foo> .Reset();

            int defaultHashCode = foo.GetHashCode();

            EasyHash <Foo> .Register(r => r.WithPrimes(23, 31));

            int customHashCode = foo.GetHashCode();

            defaultHashCode.Should().NotBe(customHashCode);
        }
예제 #3
0
        public void Should_generate_the_same_code_when_have_the_same_data()
        {
            EasyHash <Foo> .Reset();

            EasyHash <Foo> .Register(r => { });

            var one = new Foo()
            {
                Text = "some text"
            };
            var two = one.Clone();

            one.GetHashCode().Should().Be(two.GetHashCode());
        }
예제 #4
0
        public void Should_generate_different_code_when_have_different_data()
        {
            EasyHash <Foo> .Reset();

            EasyHash <Foo> .Register(r => { });

            var one = new Foo()
            {
                Text = "some text"
            };
            var two = new Foo()
            {
                Text = "another text"
            };

            one.GetHashCode().Should().NotBe(two.GetHashCode());
        }
예제 #5
0
        public void Should_use_default_hashing_if_have_no_registration()
        {
            EasyHash <Foo> .Reset();

            new Foo().GetHashCode().Should().NotBe(0);
        }