public void AttemptingToChangeKeyWhenItHasBeenSet_InvalidOperationException() { TestDomain.Entities.BasicEntity firstEntity = new TestDomain.Entities.BasicEntity(); firstEntity.Id = 1; firstEntity.Id = 2; }
public void ComparingEntityWithNull_ReturnsFalse_NoException() { TestDomain.Entities.BasicEntity firstEntity = new TestDomain.Entities.BasicEntity(); firstEntity.Id = 1; firstEntity.Name = "EntityOne"; var expected = true; var actual = firstEntity != null; Assert.IsTrue(actual == expected, message: "The entity should not be equal to null"); }
public void ComparingEntityWithItselfAsObjectUsingEquals_ReturnsTrue_NoException() { TestDomain.Entities.BasicEntity firstEntity = new TestDomain.Entities.BasicEntity(); firstEntity.Id = 1; firstEntity.Name = "EntityOne"; var expected = true; var actual = firstEntity.Equals((object)firstEntity); Assert.IsTrue(actual == expected, message: "The entity should be equal to itself when using equals even when casted as object (same reference)"); }
public void ComparingEntityWithDifferentObjectUsingEquals_ReturnsFalse_NoException() { TestDomain.Entities.BasicEntity firstEntity = new TestDomain.Entities.BasicEntity(); firstEntity.Id = 1; firstEntity.Name = "EntityOne"; var expected = true; var actual = !firstEntity.Equals(new object()); Assert.IsTrue(actual == expected, message: "The entity should not be equal to an entity of different type"); }
public void ComparingEntityWithItself_ReturnsTrue_NoException() { TestDomain.Entities.BasicEntity firstEntity = new TestDomain.Entities.BasicEntity(); firstEntity.Id = 1; firstEntity.Name = "EntityOne"; var expected = true; #pragma warning disable CS1718 // Comparison made to same variable var actual = firstEntity == firstEntity; #pragma warning restore CS1718 // Comparison made to same variable Assert.IsTrue(actual == expected, message: "The entity should be equal to itself"); }
public void Provided2EntitiesWithDifferentKeyAndSameProps_AreNotEqual_NoException() { TestDomain.Entities.BasicEntity firstEntity = new TestDomain.Entities.BasicEntity(); TestDomain.Entities.BasicEntity secondEntity = new TestDomain.Entities.BasicEntity(); firstEntity.Id = 1; secondEntity.Id = 2; firstEntity.Name = "SameProp"; secondEntity.Name = "SameProp"; var expected = true; var actual = firstEntity != secondEntity; Assert.IsTrue(actual == expected, message: "Both entities should not be equal due to not having the same key"); }
public void ComparingEntityWithEntityOfDifferentTypeEvenBeingSimilar_IsNotEqual_NoException() { TestDomain.Entities.BasicEntity firstEntity = new TestDomain.Entities.BasicEntity(); TestDomain.Entities.DifferentBasicEntity differentEntity = new TestDomain.Entities.DifferentBasicEntity(); firstEntity.Id = 1; differentEntity.Id = 1; firstEntity.Name = "BothEntitiesSameData"; differentEntity.Name = "BothEntitiesSameData"; var expected = true; var actual = firstEntity != differentEntity; Assert.IsTrue(actual == expected, message: "The entity should not be equal to an entity of different type, regardless of them being identical in data"); }
public void ComparingEntityWithDifferentObject_ReturnsFalse_NoException() { TestDomain.Entities.BasicEntity firstEntity = new TestDomain.Entities.BasicEntity(); firstEntity.Id = 1; firstEntity.Name = "EntityOne"; var expected = true; #pragma warning disable CS0253 // Possible unintended reference comparison; right hand side needs cast var actual = firstEntity != new object(); #pragma warning restore CS0253 // Possible unintended reference comparison; right hand side needs cast Assert.IsTrue(actual == expected, message: "The entity should not be equal to an entity of different type"); }
public void Provided2EntitiesWithSameKeyButDifferentProps_AreEqual_NoException() { TestDomain.Entities.BasicEntity firstEntity = new TestDomain.Entities.BasicEntity(); TestDomain.Entities.BasicEntity secondEntity = new TestDomain.Entities.BasicEntity(); firstEntity.Id = 1; secondEntity.Id = 1; firstEntity.Name = "EntityOne"; secondEntity.Name = "EntityTwo"; var expected = true; var actual = firstEntity == secondEntity; Assert.IsTrue(actual == expected, message: "Both entities should be equal due to having the same key"); }
public void HashCollisionsAreWithinLimits_ReturnsTrue_NoException() { Dictionary <TestDomain.Entities.BasicEntity, string> entityDict = new Dictionary <TestDomain.Entities.BasicEntity, string>(); object syncObject = new object(); int errors = 0; int maxIterations = 1000000; Parallel.For(fromInclusive: 0, toExclusive: maxIterations, body: (iteration) => { try { TestDomain.Entities.BasicEntity entity = new TestDomain.Entities.BasicEntity(); entity.Id = iteration; 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 HashCollisionsAreWithinLimits_ReturnsTrue_NoException() { Dictionary<TestDomain.Entities.BasicEntity, string> entityDict = new Dictionary<TestDomain.Entities.BasicEntity, string>(); object syncObject = new object(); int errors = 0; int maxIterations = 1000000; Parallel.For(fromInclusive: 0, toExclusive: maxIterations, body: (iteration) => { try { TestDomain.Entities.BasicEntity entity = new TestDomain.Entities.BasicEntity(); entity.Id = iteration; 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 ComparingEntityWithNullObjectUsingEquals_ReturnsFalse_NoException() { TestDomain.Entities.BasicEntity firstEntity = new TestDomain.Entities.BasicEntity(); firstEntity.Id = 1; object nullObject = null; firstEntity.Name = "EntityOne"; var expected = true; var actual = !firstEntity.Equals(nullObject); Assert.IsTrue(actual == expected, message: "The entity should not be equal to a null entity of different type"); }