Ejemplo n.º 1
0
        public void GetHashCodeShouldReturnTheModelsHashCode()
        {
            var modelA = new ModelStub(System.Guid.NewGuid(), 1);

            ModelEqualityComparer<ModelStub> comparer = new ModelEqualityComparer<ModelStub>();

            Assert.That(((IEqualityComparer)comparer).GetHashCode(modelA), Is.EqualTo(modelA.GetHashCode()));
            Assert.That(((IEqualityComparer<ModelStub>)comparer).GetHashCode(modelA), Is.EqualTo(modelA.GetHashCode()));
        }
Ejemplo n.º 2
0
        public void GetHashCodeShouldReturnAUniqueHashCodePerModelIdentity()
        {
            ModelStub model1 = new ModelStub();
            ModelStub model2 = model1;

            Assert.That(model1.GetHashCode(), Is.EqualTo(model1.GetHashCode()));

            Assert.That(model1.GetHashCode(), Is.EqualTo(model2.GetHashCode()));

            ModelStub model3 = new ModelStub(System.Guid.NewGuid(), 1);
            ModelStub model4 = new ModelStub(model3.Id, 1);

            Assert.That(model3.GetHashCode(), Is.EqualTo(model4.GetHashCode()));
        }
Ejemplo n.º 3
0
        public void GetHashCodeShouldReturnSameHasCodeWhereModelIdentityIsEqual()
        {
            ModelStub model1 = new ModelStub();
            ModelStub model2 = new ModelStub();

            Assert.That(model1.GetHashCode(), Is.Not.EqualTo(model2.GetHashCode()));

            ModelStub model3 = new ModelStub(System.Guid.NewGuid(), 0);
            ModelStub model4 = new ModelStub(model3.Id, 0);

            Assert.That(model3.GetHashCode(), Is.Not.EqualTo(model4.GetHashCode()));
        }