public void When_passing_new_item_xml_should_contain_it() { IComparerResult result = new ComparerResult(ResultContext.Assembly, "Assembly"); result.AddAddedItem(ResultContext.Constructor, ".ctor", Severity.Warning); XElement xml = XmlGenerator.GenerateXml(result); XElement sut = xml.Element(ChangedElement).Element(AddedElement); Assert.AreEqual(".ctor", sut.Attribute("Name").Value); StringAssert.AreEqualIgnoringCase(Severity.Warning.ToString(), sut.Attribute("Severity").Value); StringAssert.AreEqualIgnoringCase(ResultContext.Constructor.ToString(), sut.Attribute("Context").Value); }
private void CompareInterfaces() { IEnumerable <string> referenceInterfaces = ReferenceType.GetInterfaces().Select(@interface => @interface.GetCompareableName()).ToList(); IEnumerable <string> newInterfaces = NewType.GetInterfaces().Select(@interface => @interface.GetCompareableName()).ToList(); // missing interfaces foreach (string @interface in referenceInterfaces.Except(newInterfaces)) { ComparerResult.AddRemovedItem(ResultContext.Interface, @interface, Severity.Error); } // new interfaces foreach (string @interface in newInterfaces.Except(referenceInterfaces)) { ComparerResult.AddAddedItem(ResultContext.Interface, @interface, Severity.Warning); } }
private void CompareInterfaces() { IEnumerable <string> referenceInterfaces = GetInterfaces(ReferenceType).ToList(); IEnumerable <string> newInterfaces = GetInterfaces(NewType).ToList(); // missing interfaces foreach (string @interface in referenceInterfaces.Except(newInterfaces)) { ComparerResult.AddRemovedItem(ResultContext.Interface, @interface, Severities.InterfacesRemoved); } // new interfaces foreach (string @interface in newInterfaces.Except(referenceInterfaces)) { ComparerResult.AddAddedItem(ResultContext.Interface, @interface, Severities.InterfacesAdded); } }
private void CompareTypes() { IEnumerable <string> referenceTypes = GetTypeNames(() => ReferenceType.DefinedTypes).ToList(); IEnumerable <string> newTypes = GetTypeNames(() => NewType.DefinedTypes).ToList(); // Missing types foreach (string type in referenceTypes.Except(newTypes)) { ComparerResult.AddRemovedItem(GetItemType(ReferenceType.GetType(type)), type, Severities.TypeRemoved); } // New types foreach (string type in newTypes.Except(referenceTypes)) { ComparerResult.AddAddedItem(GetItemType(NewType.GetType(type)), type, Severities.TypeAdded); } // Equal types foreach (string type in referenceTypes.Intersect(newTypes)) { ComparerResult.AddComparerResult(ComparerContext.CreateComparer(ReferenceType.GetType(type), NewType.GetType(type)).Compare()); } }
private void CompareFields() { IEnumerable <string> referenceFields = GetFields(ReferenceType).ToList(); IEnumerable <string> newFields = GetFields(NewType).ToList(); // missing fields foreach (string field in referenceFields.Except(newFields)) { ComparerResult.AddRemovedItem(ResultContext.Field, field, Severity.Error); } // new fields foreach (string field in newFields.Except(referenceFields)) { ComparerResult.AddAddedItem(ResultContext.Field, field, Severity.Warning); } // equal fields foreach (string field in referenceFields.Intersect(newFields)) { ComparerResult.AddComparerResult(ComparerContext.CreateComparer(ReferenceType.GetField(field), NewType.GetField(field)).Compare()); } }
private void CompareEvents() { IEnumerable <string> referenceEvents = GetEvents(ReferenceType).ToList(); IEnumerable <string> newEvents = GetEvents(NewType).ToList(); // missing event foreach (string @event in referenceEvents.Except(newEvents)) { ComparerResult.AddRemovedItem(ResultContext.Event, @event, Severity.Error); } // new event foreach (string @event in newEvents.Except(referenceEvents)) { ComparerResult.AddAddedItem(ResultContext.Event, @event, Severity.Warning); } // equal events foreach (string @event in newEvents.Intersect(referenceEvents)) { ComparerResult.AddComparerResult(ComparerContext.CreateComparer(ReferenceType.GetEvent(@event), NewType.GetEvent(@event)).Compare()); } }
private void CompareMethods(Func <Type, MethodBase[]> getMethods, Func <Type, string, Type[], MethodBase> getMethod, ResultContext resultContext) { PairList <Item> pairList = new PairList <Item>(); AddMethodsToPairList(pairList.AddReferenceItem, () => getMethods(ReferenceType)); AddMethodsToPairList(pairList.AddNewItem, () => getMethods(NewType)); foreach (Item method in pairList.RemovedItems) { ComparerResult.AddRemovedItem(resultContext, getMethod(ReferenceType, method.Name, method.Types).ToString(), Severity.Error); } foreach (Item method in pairList.AddedItems) { ComparerResult.AddAddedItem(resultContext, getMethod(NewType, method.Name, method.Types).ToString(), Severity.Warning); } foreach (ItemPair <Item> methodPair in pairList.EqualItems) { MethodBase referenceMethod = getMethod(ReferenceType, methodPair.ReferenceItem.Name, methodPair.ReferenceItem.Types); MethodBase newMethod = getMethod(NewType, methodPair.NewItem.Name, methodPair.NewItem.Types); ComparerResult.AddComparerResult(ComparerContext.CreateComparer(referenceMethod, newMethod).Compare()); } }
private void CompareProperties() { PairList <Item> pairList = new PairList <Item>(); GetProperties(ReferenceType).ForEach(property => pairList.AddReferenceItem(new Item(property.Name, property.GetIndexParameterTypes()))); GetProperties(NewType).ForEach(property => pairList.AddNewItem(new Item(property.Name, property.GetIndexParameterTypes()))); foreach (Item property in pairList.RemovedItems) { ComparerResult.AddRemovedItem(ResultContext.Property, ReferenceType.GetApiProperty(property.Name, property.Types).ToString(), Severity.Error); } foreach (Item property in pairList.AddedItems) { ComparerResult.AddAddedItem(ResultContext.Property, NewType.GetApiProperty(property.Name, property.Types).ToString(), Severity.Warning); } foreach (ItemPair <Item> property in pairList.EqualItems) { PropertyInfo referenceProperty = ReferenceType.GetApiProperty(property.ReferenceItem.Name, property.ReferenceItem.Types); PropertyInfo newProperty = NewType.GetApiProperty(property.NewItem.Name, property.NewItem.Types); ComparerResult.AddComparerResult(ComparerContext.CreateComparer(referenceProperty, newProperty).Compare()); } }
private void CompareMethods(Func <Type, MethodBase[]> getMethods, ResultContext resultContext) { PairList <MethodItem> pairList = new PairList <MethodItem>(); getMethods(ReferenceType).ToList().ForEach(m => pairList.AddReferenceItem(new MethodItem(m))); getMethods(NewType).ToList().ForEach(m => pairList.AddNewItem(new MethodItem(m))); foreach (MethodItem item in pairList.RemovedItems) { ComparerResult.AddRemovedItem(resultContext, item.Method.ToString(), Severities.MethodRemoved); } foreach (MethodItem item in pairList.AddedItems) { ComparerResult.AddAddedItem(resultContext, item.Method.ToString(), Severities.MethodAdded); } foreach (ItemPair <MethodItem> itemPair in pairList.EqualItems) { MethodBase referenceMethod = itemPair.ReferenceItem.Method; MethodBase newMethod = itemPair.NewItem.Method; ComparerResult.AddComparerResult(ComparerContext.CreateComparer(referenceMethod, newMethod).Compare()); } }
public Builder Added(Severity severity = Severity.Error, ResultContext resultContext = ResultContext.Class, string itemName = "Item") { _comparerResult.AddAddedItem(resultContext, itemName, severity); return(this); }