Example #1
0
        public void EntitiesCanBeSuccesfullyUsedInDictionariesAsKeys_True_NoException()
        {
            TestDomain.Entities.VeryComplexKeyEntity firstVeryComplexEntity  = new TestDomain.Entities.VeryComplexKeyEntity();
            TestDomain.Entities.VeryComplexKeyEntity secondVeryComplexEntity = new TestDomain.Entities.VeryComplexKeyEntity();

            TestDomain.Keys.VeryComplexStructKey veryComplexKeyOne = new TestDomain.Keys.VeryComplexStructKey()
            {
                NumericId    = 1,
                TextId       = "2",
                UniqueGuidId = Guid.NewGuid()
            };

            TestDomain.Keys.VeryComplexStructKey veryComplexKeyTwo = new TestDomain.Keys.VeryComplexStructKey()
            {
                NumericId    = 3,
                TextId       = "4",
                UniqueGuidId = Guid.NewGuid()
            };

            firstVeryComplexEntity.Id  = veryComplexKeyOne;
            secondVeryComplexEntity.Id = veryComplexKeyTwo;

            firstVeryComplexEntity.Name  = "SameProp";
            secondVeryComplexEntity.Name = "SameProp";

            Dictionary <TestDomain.Entities.VeryComplexKeyEntity, string> entityDict = new Dictionary <TestDomain.Entities.VeryComplexKeyEntity, string>();

            entityDict.Add(firstVeryComplexEntity, value: "FirstEntity");
            entityDict.Add(secondVeryComplexEntity, value: "SecondEntity");

            var expected = true;
            var actual   = (entityDict[firstVeryComplexEntity] == "FirstEntity") && (entityDict[secondVeryComplexEntity] == "SecondEntity");

            Assert.IsTrue(actual == expected, message: "You should be able to use the entity as Key, taking into account only its key value");
        }
Example #2
0
        public void ComparingEntitiesWithDifferentVeryComplexKey_IsNotEqual_NoException()
        {
            TestDomain.Entities.VeryComplexKeyEntity firstVeryComplexEntity  = new TestDomain.Entities.VeryComplexKeyEntity();
            TestDomain.Entities.VeryComplexKeyEntity secondVeryComplexEntity = new TestDomain.Entities.VeryComplexKeyEntity();

            TestDomain.Keys.VeryComplexStructKey veryComplexKeyOne = new TestDomain.Keys.VeryComplexStructKey()
            {
                NumericId    = 1,
                TextId       = "2",
                UniqueGuidId = Guid.NewGuid()
            };

            TestDomain.Keys.VeryComplexStructKey veryComplexKeyTwo = new TestDomain.Keys.VeryComplexStructKey()
            {
                NumericId    = 3,
                TextId       = "4",
                UniqueGuidId = Guid.NewGuid()
            };

            firstVeryComplexEntity.Id  = veryComplexKeyOne;
            secondVeryComplexEntity.Id = veryComplexKeyTwo;

            firstVeryComplexEntity.Name  = "SameProp";
            secondVeryComplexEntity.Name = "SameProp";

            var expected = false;
            var actual   = firstVeryComplexEntity == secondVeryComplexEntity;

            Assert.IsTrue(actual == expected, message: "Both entities should not be equal due to having different very complex key");
        }
Example #3
0
        public void YouCannotAddTwiceTheSameEntityAsKeyToADictionary_ArgumentException()
        {
            TestDomain.Entities.VeryComplexKeyEntity firstVeryComplexEntity  = new TestDomain.Entities.VeryComplexKeyEntity();
            TestDomain.Entities.VeryComplexKeyEntity secondVeryComplexEntity = new TestDomain.Entities.VeryComplexKeyEntity();

            TestDomain.Keys.VeryComplexStructKey veryComplexKeyToShare = new TestDomain.Keys.VeryComplexStructKey()
            {
                NumericId    = 1,
                TextId       = "2",
                UniqueGuidId = Guid.NewGuid()
            };

            firstVeryComplexEntity.Id  = veryComplexKeyToShare;
            secondVeryComplexEntity.Id = veryComplexKeyToShare;

            firstVeryComplexEntity.Name  = "FirstProp";
            secondVeryComplexEntity.Name = "SecondProp";

            Dictionary <TestDomain.Entities.VeryComplexKeyEntity, string> entityDict = new Dictionary <TestDomain.Entities.VeryComplexKeyEntity, string>();

            entityDict.Add(firstVeryComplexEntity, value: "FirstEntity");
            entityDict.Add(secondVeryComplexEntity, value: "SecondEntity");
        }
Example #4
0
        public void ComparingEntitiesWithDifferentVeryComplexKeyCanHandleNulls_IsEqual_NoException()
        {
            TestDomain.Entities.VeryComplexKeyEntity firstVeryComplexEntity  = new TestDomain.Entities.VeryComplexKeyEntity();
            TestDomain.Entities.VeryComplexKeyEntity secondVeryComplexEntity = new TestDomain.Entities.VeryComplexKeyEntity();

            TestDomain.Keys.VeryComplexStructKey veryComplexKeyToShare = new TestDomain.Keys.VeryComplexStructKey()
            {
                NumericId    = 1,
                TextId       = null,
                UniqueGuidId = Guid.NewGuid()
            };

            firstVeryComplexEntity.Id  = veryComplexKeyToShare;
            secondVeryComplexEntity.Id = veryComplexKeyToShare;

            firstVeryComplexEntity.Name  = "FirstProp";
            secondVeryComplexEntity.Name = "SecondProp";

            var expected = true;
            var actual   = firstVeryComplexEntity == secondVeryComplexEntity;

            Assert.IsTrue(actual == expected, message: "Both entities should be equal due to having same very complex key");
        }
Example #5
0
        public void YouCannotAddTwiceTheSameEntityAsKeyToADictionary_ArgumentException()
        {
            TestDomain.Entities.VeryComplexKeyEntity firstVeryComplexEntity = new TestDomain.Entities.VeryComplexKeyEntity();
            TestDomain.Entities.VeryComplexKeyEntity secondVeryComplexEntity = new TestDomain.Entities.VeryComplexKeyEntity();

            TestDomain.Keys.VeryComplexStructKey veryComplexKeyToShare = new TestDomain.Keys.VeryComplexStructKey()
            {
                NumericId = 1,
                TextId = "2",
                UniqueGuidId = Guid.NewGuid()
            };

            firstVeryComplexEntity.Id = veryComplexKeyToShare;
            secondVeryComplexEntity.Id = veryComplexKeyToShare;

            firstVeryComplexEntity.Name = "FirstProp";
            secondVeryComplexEntity.Name = "SecondProp";

            Dictionary<TestDomain.Entities.VeryComplexKeyEntity, string> entityDict = new Dictionary<TestDomain.Entities.VeryComplexKeyEntity, string>();

            entityDict.Add(firstVeryComplexEntity, value: "FirstEntity");
            entityDict.Add(secondVeryComplexEntity, value: "SecondEntity");
        }
Example #6
0
        public void EntitiesCanBeSuccesfullyUsedInDictionariesAsKeys_True_NoException()
        {
            TestDomain.Entities.VeryComplexKeyEntity firstVeryComplexEntity = new TestDomain.Entities.VeryComplexKeyEntity();
            TestDomain.Entities.VeryComplexKeyEntity secondVeryComplexEntity = new TestDomain.Entities.VeryComplexKeyEntity();

            TestDomain.Keys.VeryComplexStructKey veryComplexKeyOne = new TestDomain.Keys.VeryComplexStructKey()
            {
                NumericId = 1,
                TextId = "2",
                UniqueGuidId = Guid.NewGuid()
            };

            TestDomain.Keys.VeryComplexStructKey veryComplexKeyTwo = new TestDomain.Keys.VeryComplexStructKey()
            {
                NumericId = 3,
                TextId = "4",
                UniqueGuidId = Guid.NewGuid()
            };

            firstVeryComplexEntity.Id = veryComplexKeyOne;
            secondVeryComplexEntity.Id = veryComplexKeyTwo;

            firstVeryComplexEntity.Name = "SameProp";
            secondVeryComplexEntity.Name = "SameProp";

            Dictionary<TestDomain.Entities.VeryComplexKeyEntity, string> entityDict = new Dictionary<TestDomain.Entities.VeryComplexKeyEntity, string>();

            entityDict.Add(firstVeryComplexEntity, value: "FirstEntity");
            entityDict.Add(secondVeryComplexEntity, value: "SecondEntity");

            var expected = true;
            var actual = (entityDict[firstVeryComplexEntity] == "FirstEntity") && (entityDict[secondVeryComplexEntity] == "SecondEntity");

            Assert.IsTrue(actual == expected, message: "You should be able to use the entity as Key, taking into account only its key value");
        }
Example #7
0
        public void ComparingEntitiesWithDifferentVeryComplexKeyCanHandleNulls_IsEqual_NoException()
        {
            TestDomain.Entities.VeryComplexKeyEntity firstVeryComplexEntity = new TestDomain.Entities.VeryComplexKeyEntity();
            TestDomain.Entities.VeryComplexKeyEntity secondVeryComplexEntity = new TestDomain.Entities.VeryComplexKeyEntity();

            TestDomain.Keys.VeryComplexStructKey veryComplexKeyToShare = new TestDomain.Keys.VeryComplexStructKey()
            {
                NumericId = 1,
                TextId = null,
                UniqueGuidId = Guid.NewGuid()
            };

            firstVeryComplexEntity.Id = veryComplexKeyToShare;
            secondVeryComplexEntity.Id = veryComplexKeyToShare;

            firstVeryComplexEntity.Name = "FirstProp";
            secondVeryComplexEntity.Name = "SecondProp";

            var expected = true;
            var actual = firstVeryComplexEntity == secondVeryComplexEntity;

            Assert.IsTrue(actual == expected, message: "Both entities should be equal due to having same very complex key");
        }
Example #8
0
        public void ComparingEntitiesWithDifferentVeryComplexKey_IsNotEqual_NoException()
        {
            TestDomain.Entities.VeryComplexKeyEntity firstVeryComplexEntity = new TestDomain.Entities.VeryComplexKeyEntity();
            TestDomain.Entities.VeryComplexKeyEntity secondVeryComplexEntity = new TestDomain.Entities.VeryComplexKeyEntity();

            TestDomain.Keys.VeryComplexStructKey veryComplexKeyOne = new TestDomain.Keys.VeryComplexStructKey()
            {
                NumericId = 1,
                TextId = "2",
                UniqueGuidId = Guid.NewGuid()
            };

            TestDomain.Keys.VeryComplexStructKey veryComplexKeyTwo = new TestDomain.Keys.VeryComplexStructKey()
            {
                NumericId = 3,
                TextId = "4",
                UniqueGuidId = Guid.NewGuid()
            };

            firstVeryComplexEntity.Id = veryComplexKeyOne;
            secondVeryComplexEntity.Id = veryComplexKeyTwo;

            firstVeryComplexEntity.Name = "SameProp";
            secondVeryComplexEntity.Name = "SameProp";

            var expected = false;
            var actual = firstVeryComplexEntity == secondVeryComplexEntity;

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