Ejemplo n.º 1
0
        private void AddToResultIfNotEqual(string propertyName, Func <ParameterInfo, bool> getFlag, Severity severity)
        {
            bool referenceValue = getFlag(ReferenceType);
            bool newValue       = getFlag(NewType);

            if (referenceValue != newValue)
            {
                ComparerResult.AddChangedFlag(propertyName, referenceValue, severity);
            }
        }
Ejemplo n.º 2
0
        private void AddToResultIfNotEqual(string propertyName, MethodAttributes typeAttribute, Severity severity)
        {
            bool referenceValue = ReferenceType.Attributes.HasFlag(typeAttribute);
            bool newValue       = NewType.Attributes.HasFlag(typeAttribute);

            if (referenceValue != newValue)
            {
                ComparerResult.AddChangedFlag(propertyName, referenceValue, severity);
            }
        }
Ejemplo n.º 3
0
        public void When_passing_two_level_report_xml_should_contain_it()
        {
            IComparerResult result1 = new ComparerResult(ResultContext.Assembly, "Assembly");
            IComparerResult result2 = new ComparerResult(ResultContext.Class, "Class");

            result2.AddChangedFlag("dummy", true, Severity.Error);
            result1.AddComparerResult(result2);
            XElement sut = XmlGenerator.GenerateXml(result1);

            Assert.NotNull(sut.Element(ChangedElement).Element(ChangedElement));
        }
Ejemplo n.º 4
0
        public void When_passing_changed_flag_xml_should_contain_it()
        {
            IComparerResult result = new ComparerResult(ResultContext.Assembly, "Assembly");

            result.AddChangedFlag("Flag", true, Severity.Hint);
            XElement xml = XmlGenerator.GenerateXml(result);
            XElement sut = xml.Element("ChangedElement").Element("ChangedAttribute");

            Assert.AreEqual("Flag", sut.Attribute("Name").Value);
            StringAssert.AreEqualIgnoringCase(Severity.Hint.ToString(), sut.Attribute("Severity").Value);
            StringAssert.AreEqualIgnoringCase(true.ToString(), sut.Attribute("ReferenceValue").Value);
            StringAssert.AreEqualIgnoringCase(false.ToString(), sut.Attribute("NewValue").Value);
        }
Ejemplo n.º 5
0
 private void CompareAttributes()
 {
     if (ReferenceType.IsEnum != NewType.IsEnum)
     {
         ComparerResult.AddChangedFlag("Enum", ReferenceType.IsEnum, Severity.Error);
     }
     AddToResultIfNotEqual("Static", TypeAttributes.Sealed | TypeAttributes.Abstract, Severity.Error);
     if (ComparerResult.ChangedFlags.All(change => change.PropertyName != "Static"))
     {
         AddToResultIfNotEqual("Abstract", TypeAttributes.Abstract, Severity.Error);
         AddToResultIfNotEqual("Sealed", TypeAttributes.Sealed, Severity.Error);
     }
     AddToResultIfNotEqual("Interface", TypeAttributes.Interface, Severity.Error);
     AddToResultIfNotEqual("Serializable", TypeAttributes.Serializable, Severity.Error);
 }
Ejemplo n.º 6
0
        public override IComparerResult Compare()
        {
            ComparerContext.LogDetail(string.Format("Comparing event '{0}'", ReferenceType));
            if (ReferenceType.EventHandlerType.GetCompareableName() != NewType.EventHandlerType.GetCompareableName())
            {
                ComparerResult.AddChangedProperty("Type", ReferenceType.EventHandlerType.GetCompareableName(), NewType.EventHandlerType.GetCompareableName(), Severity.Error);
            }
            bool referenceStatic = (ReferenceType.AddMethod != null && ReferenceType.AddMethod.IsStatic) || (ReferenceType.RaiseMethod != null && ReferenceType.RaiseMethod.IsStatic);
            bool newStatic       = (NewType.AddMethod != null && NewType.AddMethod.IsStatic) || (NewType.RaiseMethod != null && NewType.RaiseMethod.IsStatic);

            if (referenceStatic != newStatic)
            {
                ComparerResult.AddChangedFlag("Static", referenceStatic, Severity.Error);
            }
            return(ComparerResult);
        }
Ejemplo n.º 7
0
 public override IComparerResult Compare()
 {
     ComparerContext.LogDetail(string.Format("Comparing field '{0}'", ReferenceType));
     if (ReferenceType.FieldType.GetCompareableName() != NewType.FieldType.GetCompareableName())
     {
         ComparerResult.AddChangedProperty("Type", ReferenceType.FieldType.GetCompareableName(), NewType.FieldType.GetCompareableName(), Severity.Error);
     }
     if (ReferenceType.IsStatic != NewType.IsStatic)
     {
         ComparerResult.AddChangedFlag("Static", ReferenceType.IsStatic, Severity.Error);
     }
     if (ReferenceType.IsStatic && NewType.IsStatic && ReferenceType.FieldType.IsEnum)
     {
         // compare numeric enum values
         object referenceValue = ReferenceType.GetRawConstantValue();
         object newValue       = NewType.GetRawConstantValue();
         if (Convert.ToInt32(referenceValue) != Convert.ToInt32(newValue))
         {
             ComparerResult.AddChangedProperty("Value", referenceValue.ToString(), newValue.ToString(), Severity.Error);
         }
     }
     return(ComparerResult);
 }
Ejemplo n.º 8
0
        public override IComparerResult Compare()
        {
            ComparerContext.LogDetail(string.Format("Comparing property '{0}'", ReferenceType));
            if (ReferenceType.PropertyType.GetCompareableName() != NewType.PropertyType.GetCompareableName())
            {
                ComparerResult.AddChangedProperty("Type", ReferenceType.PropertyType.GetCompareableName(), NewType.PropertyType.GetCompareableName(), Severity.Error);
            }
            if (ReferenceType.CanWrite != NewType.CanWrite)
            {
                ComparerResult.AddChangedFlag("Setter", ReferenceType.CanWrite, Severity.Error);
            }
            if (ReferenceType.CanRead != NewType.CanRead)
            {
                ComparerResult.AddChangedFlag("Getter", ReferenceType.CanRead, Severity.Error);
            }
            bool referenceStatic = (ReferenceType.GetMethod != null && ReferenceType.GetMethod.IsStatic) || (ReferenceType.SetMethod != null && ReferenceType.SetMethod.IsStatic);
            bool newStatic       = (NewType.GetMethod != null && NewType.GetMethod.IsStatic) || (NewType.SetMethod != null && NewType.SetMethod.IsStatic);

            if (referenceStatic != newStatic)
            {
                ComparerResult.AddChangedFlag("Static", referenceStatic, Severity.Error);
            }
            return(ComparerResult);
        }
Ejemplo n.º 9
0
 public Builder Flag(Severity severity = Severity.Error, string flagName = "Value", bool value = false)
 {
     _comparerResult.AddChangedFlag(flagName, value, severity);
     return(this);
 }