public void CompositeKey_IsEqualToKey2()
        {
            //Arrange
            CompositeKey ck = new CompositeKey(STRING_KEY, INT_KEY);

            //Act
            bool actual = ck == ck.Key2 && ck.Equals(ck.Key2) && ck == INT_KEY && ck.Equals(INT_KEY);

            //Assert
            Assert.IsTrue(actual);
        }
Example #2
0
        public void CompositeKeysEqualWhenKeysPropertiesEqual()
        {
            DateTime todayDt = DateTime.Today;
            var      key1    = new CompositeKey <UserType, string>(new UserType(todayDt), "Developers");
            var      key2    = new CompositeKey <UserType, string>(new UserType(todayDt), "Developers");

            if (!key1.Equals(key2) || key1 != key2)
            {
                Assert.Fail("Keys are NOT equal!");
            }
        }
Example #3
0
        public void CompositeKeysNotEqualWhenKeysPropertiesNotEqual()
        {
            DateTime dt1  = new DateTime(2017, 03, 13);
            DateTime dt2  = new DateTime(2017, 03, 14);
            var      key1 = new CompositeKey <UserType, string>(new UserType(dt1), "Developers");
            var      key2 = new CompositeKey <UserType, string>(new UserType(dt2), "Managers");

            if (key1.Equals(key2) || key1 == key2)
            {
                Assert.Fail("Keys should not be equal");
            }
        }
        public void TwoCompositeKeys_DifferentKeys_AreNotEqual()
        {
            //Arrange
            CompositeKey ck1 = new CompositeKey(BYTE_KEY, STRING_KEY);
            CompositeKey ck2 = new CompositeKey(INT_KEY, BOOL_KEY);

            //Act
            bool actual = ck1 != ck2 && !ck1.Equals(ck2);

            //Assert
            Assert.IsTrue(actual);
        }
        public void TwoCompositeKeys_SameKeys_AreEqual()
        {
            //Arrange
            CompositeKey ck1 = new CompositeKey(STRING_KEY, INT_KEY);
            CompositeKey ck2 = new CompositeKey(STRING_KEY, INT_KEY);

            //Act
            bool actual = ck1 == ck2 && ck1.Equals(ck2);

            //Assert
            Assert.IsTrue(actual);
        }
        /// <summary>
        /// updates the row in the index, if the index values have not
        /// changed then no-op. if values have changed old is removed
        /// and new is added
        /// </summary>
        /// <param name="row"></param>
        /// <param name="removedDetached"></param>
        private void UpdateDataRowInIndex(DataRow row, bool removedDetached, bool isRollback)
        {
            CompositeKey key;

            // This will commit any changes made when the parent row changed.  Note that the mapping element is removed when a
            // deleted row is committed.
            if (isRollback == true ||
                (removedDetached == true &&
                 (row.RowState == DataRowState.Detached ||
                  row.RowState == DataRowState.Deleted)))
            {
                //if the row is detached (probably from commit) and param set
                //just remove the row when it is detached
                this.DeleteDataRowFromIndex(row);
                return;
            }

            //check if key is is the same and in the map
            if (this.dataRowToKeyMap.TryGetValue(row, out key))
            {
                CompositeKey newKey = this.GetDataRowCompositeKey(row);
                if (newKey != null &&
                    newKey.Equals(key))
                {
                    return;
                }

                //created the key so set Key to it so dont need to create another one
                key = newKey;
            }
            else if (key == null)
            {
                //not in the map create a new key
                key = this.GetDataRowCompositeKey(row);
            }

            //get rid of the old
            this.DeleteDataRowFromIndex(row);

            //if there is a valid key add
            if (key != null)
            {
                this.dataRowToKeyMap.Add(row, key);
                this.keyToDataRowMap.Add(key, row);
            }
        }
        public void DifferentObjectEqualTest()
        {
            var firstObject = new CompositeKey <UserTypeA, UserTypeB>(new UserTypeA {
                UserId = 1, UserName = "******"
            }, new UserTypeB {
                Level = "123456", FriendlyUserTypeA = new UserTypeA {
                    UserId = 3, UserName = "******"
                }
            });
            var secondObject = new CompositeKey <UserTypeA, UserTypeB>(new UserTypeA {
                UserId = 2, UserName = "******"
            }, new UserTypeB {
                Level = "12345", FriendlyUserTypeA = new UserTypeA {
                    UserId = 4, UserName = "******"
                }
            });

            Assert.That(firstObject.Equals(secondObject), Is.False);
        }