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"); }
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"); }
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"); }
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"); }
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"); }
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"); }