コード例 #1
0
        public void InputOutputViewModelEqualityComparer_Equals_WhenNotEqual_ExpectFalse()
        {
            //------------Setup for test--------------------------
            var inputOutputViewModelEqualityComparer = new InputOutputViewModelEqualityComparer();

            var obj1 = new Mock <IInputOutputViewModel>();
            var obj2 = new Mock <IInputOutputViewModel>();

            obj1.Setup(c => c.DisplayName).Returns("rs().val2");
            obj2.Setup(c => c.DisplayName).Returns("rs().val");

            //------------Execute Test---------------------------
            var result = inputOutputViewModelEqualityComparer.Equals(obj1.Object, obj2.Object);

            //------------Assert Results-------------------------
            Assert.IsFalse(result);
        }
        public void InputOutputViewModelEqualityComparer_Equals_WhenNotEqual_ExpectFalse()
        {
            //------------Setup for test--------------------------
            var inputOutputViewModelEqualityComparer = new InputOutputViewModelEqualityComparer();

            Mock<IInputOutputViewModel> obj1 = new Mock<IInputOutputViewModel>();
            Mock<IInputOutputViewModel> obj2 = new Mock<IInputOutputViewModel>();

            obj1.Setup(c => c.DisplayName).Returns("rs().val2");
            obj2.Setup(c => c.DisplayName).Returns("rs().val");

            //------------Execute Test---------------------------
            var result = inputOutputViewModelEqualityComparer.Equals(obj1.Object, obj2.Object);

            //------------Assert Results-------------------------
            Assert.IsFalse(result);
        }
コード例 #3
0
        public void InputOutputViewModelEqualityComparer_Equals_WhenValidObject_ExpectHashCode()
        {
            //------------Setup for test--------------------------
            var inputOutputViewModelEqualityComparer = new InputOutputViewModelEqualityComparer();

            Mock <IInputOutputViewModel> obj1 = new Mock <IInputOutputViewModel>();
            Mock <IInputOutputViewModel> obj2 = new Mock <IInputOutputViewModel>();

            obj1.Setup(c => c.DisplayName).Returns("rs().val");
            obj2.Setup(c => c.DisplayName).Returns("rs().val");

            //------------Execute Test---------------------------
            var result  = inputOutputViewModelEqualityComparer.GetHashCode(obj1.Object);
            var result2 = inputOutputViewModelEqualityComparer.GetHashCode(obj2.Object);

            //------------Assert Results-------------------------
            Assert.AreEqual(253903065, result);
            Assert.AreEqual(result, result2);
        }
        public void InputOutputViewModelEqualityComparer_Equals_WhenValidObject_ExpectHashCode()
        {
            //------------Setup for test--------------------------
            var inputOutputViewModelEqualityComparer = new InputOutputViewModelEqualityComparer();

            Mock<IInputOutputViewModel> obj1 = new Mock<IInputOutputViewModel>();
            Mock<IInputOutputViewModel> obj2 = new Mock<IInputOutputViewModel>();

            obj1.Setup(c => c.DisplayName).Returns("rs().val");
            obj2.Setup(c => c.DisplayName).Returns("rs().val");

            //------------Execute Test---------------------------
            var result = inputOutputViewModelEqualityComparer.GetHashCode(obj1.Object);
            var result2 = inputOutputViewModelEqualityComparer.GetHashCode(obj2.Object);

            //------------Assert Results-------------------------
            Assert.AreEqual(253903065, result);
            Assert.AreEqual(result, result2);
        }
コード例 #5
0
        /// <summary>
        /// Reconsiles the exiting and master view.
        /// </summary>
        /// <param name="masterView">The master view.</param>
        /// <param name="existingView">The existing view.</param>
        /// <returns></returns>
        private IList<IInputOutputViewModel> ReconcileExistingAndMasterView(IList<IInputOutputViewModel> masterView, IEnumerable<IInputOutputViewModel> existingView)
        {
            var equalityCompareImpl = new InputOutputViewModelEqualityComparer();

            var intersectionResult = existingView.Intersect(masterView, equalityCompareImpl);

            IEnumerable<IInputOutputViewModel> inputOutputViewModels = intersectionResult as IList<IInputOutputViewModel> ?? intersectionResult.ToList();
            foreach(var intersectionRowItem in inputOutputViewModels)
            {
                //  Find a match in master list and tranfer properties ;)
                var match = masterView.FirstOrDefault(c => c.DisplayName == intersectionRowItem.DisplayName);

                if(match != null)
                {
                    intersectionRowItem.Required = match.Required;
                    intersectionRowItem.DefaultValue = match.DefaultValue;
                }
            }

            // ordering maters ;)
            IList<IInputOutputViewModel> result = inputOutputViewModels.Union(masterView, equalityCompareImpl).ToList();

            return result;
        }