Beispiel #1
0
        public void HashCollisionsAreWithinLimitsGuidKey_ReturnsTrue_NoException()
        {
            Dictionary <TestDomain.Entities.GuidKeyEntity, string> entityDict = new Dictionary <TestDomain.Entities.GuidKeyEntity, string>();
            object syncObject    = new object();
            int    errors        = 0;
            int    maxIterations = 1000000;

            Parallel.For(fromInclusive: 0, toExclusive: maxIterations, body: (iteration) =>
            {
                try
                {
                    TestDomain.Entities.GuidKeyEntity entity = new TestDomain.Entities.GuidKeyEntity();

                    entity.Id = Guid.NewGuid();

                    entity.Name = "Entity " + iteration;

                    lock (syncObject)
                    {
                        entityDict.Add(entity, iteration.ToString());
                    }
                }
                catch
                {
                    Interlocked.Increment(ref errors);
                }
            });

            var limit    = 1;
            var expected = true;
            var actual   = (errors < limit);

            Assert.IsTrue(actual == expected, message: "The hashing algoritm generates more than " + limit + " collision per " + maxIterations + " entities");
            Assert.IsTrue(entityDict.Count == maxIterations - errors, message: "Something wrong happened running the test, the right number of elements where not introduced in the dictionary");
        }
Beispiel #2
0
        public void ComparingEntitiesWithDifferentGuidKey_IsNotEqual_NoException()
        {
            TestDomain.Entities.GuidKeyEntity firstGuidEntity  = new TestDomain.Entities.GuidKeyEntity();
            TestDomain.Entities.GuidKeyEntity secondGuidEntity = new TestDomain.Entities.GuidKeyEntity();

            firstGuidEntity.Id  = Guid.NewGuid();
            secondGuidEntity.Id = Guid.NewGuid();

            firstGuidEntity.Name  = "SameProp";
            secondGuidEntity.Name = "SameProp";

            var expected = false;
            var actual   = firstGuidEntity == secondGuidEntity;

            Assert.IsTrue(actual == expected, message: "Both entities should not be equal due to having different Guids key");
        }
Beispiel #3
0
        public void ComparingEntitiesWithSameGuidKey_IsEqual_NoException()
        {
            TestDomain.Entities.GuidKeyEntity firstGuidEntity  = new TestDomain.Entities.GuidKeyEntity();
            TestDomain.Entities.GuidKeyEntity secondGuidEntity = new TestDomain.Entities.GuidKeyEntity();

            Guid guidToShare = Guid.NewGuid();

            firstGuidEntity.Id  = guidToShare;
            secondGuidEntity.Id = guidToShare;

            firstGuidEntity.Name  = "FirstProp";
            secondGuidEntity.Name = "SecondProp";

            var expected = true;
            var actual   = firstGuidEntity == secondGuidEntity;

            Assert.IsTrue(actual == expected, message: "Both entities should be equal due to having same Guid key");
        }
Beispiel #4
0
        public void HashCollisionsAreWithinLimitsGuidKey_ReturnsTrue_NoException()
        {
            Dictionary<TestDomain.Entities.GuidKeyEntity, string> entityDict = new Dictionary<TestDomain.Entities.GuidKeyEntity, string>();
            object syncObject = new object();
            int errors = 0;
            int maxIterations = 1000000;

            Parallel.For(fromInclusive: 0, toExclusive: maxIterations, body: (iteration) =>
                 {
                     try
                     {
                         TestDomain.Entities.GuidKeyEntity entity = new TestDomain.Entities.GuidKeyEntity();

                         entity.Id = Guid.NewGuid();

                         entity.Name = "Entity " + iteration;

                         lock (syncObject)
                         {
                             entityDict.Add(entity, iteration.ToString());
                         }
                     }
                     catch
                     {
                         Interlocked.Increment(ref errors);
                     }
                 });

            var limit = 1;
            var expected = true;
            var actual = (errors < limit);

            Assert.IsTrue(actual == expected, message: "The hashing algoritm generates more than " + limit + " collision per " + maxIterations + " entities");
            Assert.IsTrue(entityDict.Count == maxIterations - errors, message: "Something wrong happened running the test, the right number of elements where not introduced in the dictionary");
        }
Beispiel #5
0
        public void ComparingEntitiesWithSameGuidKey_IsEqual_NoException()
        {
            TestDomain.Entities.GuidKeyEntity firstGuidEntity = new TestDomain.Entities.GuidKeyEntity();
            TestDomain.Entities.GuidKeyEntity secondGuidEntity = new TestDomain.Entities.GuidKeyEntity();

            Guid guidToShare = Guid.NewGuid();

            firstGuidEntity.Id = guidToShare;
            secondGuidEntity.Id = guidToShare;

            firstGuidEntity.Name = "FirstProp";
            secondGuidEntity.Name = "SecondProp";

            var expected = true;
            var actual = firstGuidEntity == secondGuidEntity;

            Assert.IsTrue(actual == expected, message: "Both entities should be equal due to having same Guid key");
        }
Beispiel #6
0
        public void ComparingEntitiesWithDifferentGuidKey_IsNotEqual_NoException()
        {
            TestDomain.Entities.GuidKeyEntity firstGuidEntity = new TestDomain.Entities.GuidKeyEntity();
            TestDomain.Entities.GuidKeyEntity secondGuidEntity = new TestDomain.Entities.GuidKeyEntity();

            firstGuidEntity.Id = Guid.NewGuid();
            secondGuidEntity.Id = Guid.NewGuid();

            firstGuidEntity.Name = "SameProp";
            secondGuidEntity.Name = "SameProp";

            var expected = false;
            var actual = firstGuidEntity == secondGuidEntity;

            Assert.IsTrue(actual == expected, message: "Both entities should not be equal due to having different Guids key");
        }