Example #1
0
        public void ExceptionRaise_ForDiffOfDisparateFields()
        {
            var oldFieldName = "Test.OldField";
            var oldField = new Mock<IFieldData>();
            oldField.SetupGet(x => x.FieldSignature)
                .Returns(oldFieldName);

            var newFieldName = "Test.NewField";
            var newField = new Mock<IFieldData>();
            newField.SetupGet(x => x.FieldSignature)
                .Returns(newFieldName);

            var SUT = new FieldDiff(oldField.Object, newField.Object);
        }
Example #2
0
        public void AddedAttributes_Populated_ForNewAttribute()
        {
            var newAttributeName = "Test.NewAttribute";
            var newAttribute = new Mock<IAttributeData>();
            newAttribute.SetupGet(x => x.Name).Returns(newAttributeName);

            var oldField = new Mock<IFieldData>();
            oldField.SetupGet(x => x.AttributeData)
                .Returns(new List<IAttributeData>());

            var newField = new Mock<IFieldData>();
            newField.SetupGet(x => x.AttributeData)
                .Returns(new List<IAttributeData>()
                {
                    newAttribute.Object
                });

            var SUT = new FieldDiff(oldField.Object, newField.Object);
            Assert.True(SUT.AddedAttributes.Any(x => x.Name == newAttributeName));
            Assert.False(SUT.RemovedAttributes.Any());
        }
Example #3
0
        public void HasChanged_IsNotSet_ForUnChangedField()
        {
            var unchangedAttributeName = "Test.SameAttribute";
            var unchangedAttribute = new Mock<IAttributeData>();
            unchangedAttribute.SetupGet(x => x.Name).Returns(unchangedAttributeName);

            var oldField = new Mock<IFieldData>();
            oldField.SetupGet(x => x.AttributeData)
                .Returns(new List<IAttributeData>()
                {
                    unchangedAttribute.Object
                });

            var newField = new Mock<IFieldData>();
            newField.SetupGet(x => x.AttributeData)
                .Returns(new List<IAttributeData>()
                {
                    unchangedAttribute.Object
                });

            var SUT = new FieldDiff(oldField.Object, newField.Object);
            Assert.False(SUT.HasChanged);
        }
Example #4
0
 private void GetAddedAndRemovedFields(IEnumTypeData beforeEnum, IEnumTypeData afterEnum)
 {
     foreach (var oldField in beforeEnum.FieldData)
     {
         if (afterEnum.FieldData.All(x => x.FieldSignature != oldField.FieldSignature))
         {
             RemovedFields.Add(oldField);
             HasChanged = true;
         }
     }
     foreach (var newField in afterEnum.FieldData)
     {
         if (beforeEnum.FieldData.All(x => x.FieldSignature != newField.FieldSignature))
         {
             AddedFields.Add(newField);
             HasChanged = true;
         }
     }
     foreach (var oldField in beforeEnum.FieldData)
     {
         var matchingNewField = afterEnum.FieldData.FirstOrDefault(
             x => x.FieldSignature == oldField.FieldSignature);
         if (matchingNewField != null)
         {
             var diff = new FieldDiff(oldField, matchingNewField);
             if (!diff.HasChanged)
             {
                 continue;
             }
             ModifiedFields.Add(diff);
             HasChanged = true;
         }
     }
 }
Example #5
0
        public void HasChanged_IsSet_ForChangedField()
        {
            var oldAttributeName = "Test.OldAttribute";
            var oldAttribute = new Mock<IAttributeData>();
            oldAttribute.SetupGet(x => x.Name).Returns(oldAttributeName);

            var newAttributeName = "Test.NewAttribute";
            var newAttribute = new Mock<IAttributeData>();
            newAttribute.SetupGet(x => x.Name).Returns(newAttributeName);

            var oldField = new Mock<IFieldData>();
            oldField.SetupGet(x => x.AttributeData)
                .Returns(new List<IAttributeData>()
                {
                    oldAttribute.Object
                });

            var newField = new Mock<IFieldData>();
            newField.SetupGet(x => x.AttributeData)
                .Returns(new List<IAttributeData>()
                {
                    newAttribute.Object
                });

            var SUT = new FieldDiff(oldField.Object, newField.Object);
            Assert.True(SUT.HasChanged);
        }