public void TestTypeDiff() { var str1 = "true"; var str2 = "\"true\""; var diff1 = JsonStrings.Diff(str1, str2).Single(); Assert.True(diff1.IsTypeDiff); Assert.False(diff1.IsValueDiff); Assert.False(diff1.IsArrayDiff); Assert.False(diff1.IsObjectDiff); var diff2 = new TypeDiff( new DiffPoint("$", JsonTrue.Instance, new JsonString("true"))); Assert.True(diff2.IsTypeDiff); Assert.False(diff2.IsValueDiff); Assert.False(diff2.IsArrayDiff); Assert.False(diff2.IsObjectDiff); Assert.Equal(diff1, diff2); Assert.Equal("TypeDiff { Path = $, Left = true, Right = true }", diff1.ToString()); }
public void DiffBaseClassAndInmplementedInterfaces() { var simpleV1 = TypeQuery.GetTypeByName(TestConstants.BaseLibV1Assembly, "BaseLibrary.TypeDiff.ClassWithInterfacesAndBaseClass"); var simpleV2 = TypeQuery.GetTypeByName(TestConstants.BaseLibV2Assembly, "BaseLibrary.TypeDiff.ClassWithInterfacesAndBaseClass"); TypeDiff diff = TypeDiff.GenerateDiff(simpleV1, simpleV2, myQueries); try { Assert.IsTrue(diff.HasChangedBaseType, "Base class type has changed"); Assert.AreEqual("EventArgs", diff.TypeV1.BaseType.Name, "Base Type V1"); Assert.AreEqual("ResolveEventArgs", diff.TypeV2.BaseType.Name, "Base Type V2"); Assert.AreEqual(2, diff.Interfaces.RemovedCount, "Removed interfaces"); Assert.AreEqual(1, diff.Interfaces.AddedCount, "Added interfaces"); } finally { if (ExceptionHelper.InException) { Console.WriteLine("Removed interfaces"); foreach (var remItf in diff.Interfaces.Removed) { Console.WriteLine("{0}", remItf.ObjectV1.FullName); } Console.WriteLine("Added interfaces"); foreach (var addItf in diff.Interfaces.Added) { Console.WriteLine("{0}", addItf.ObjectV1.FullName); } } } }
public void TestTypeDiffEquality() { var diff = new TypeDiff( new DiffPoint("$", JsonTrue.Instance, new JsonString("true"))); var sameDiff = new TypeDiff( new DiffPoint("$", JsonTrue.Instance, new JsonString("true"))); var anotherDiff = new TypeDiff( new DiffPoint("$.value", JsonTrue.Instance, new JsonString("true"))); var yetAnotherDiff = new TypeDiff( new DiffPoint("$", JsonTrue.Instance, new JsonString("false"))); Assert.Equal(diff, sameDiff); Assert.NotEqual(diff, anotherDiff); Assert.NotEqual(diff, yetAnotherDiff); Assert.NotEqual(anotherDiff, yetAnotherDiff); }
public void DiffMethods() { var simpleV1 = TypeQuery.GetTypeByName(TestConstants.BaseLibV1Assembly, "BaseLibrary.TypeDiff.MethodClass"); var simpleV2 = TypeQuery.GetTypeByName(TestConstants.BaseLibV2Assembly, "BaseLibrary.TypeDiff.MethodClass"); TypeDiff diff = TypeDiff.GenerateDiff(simpleV1, simpleV2, myQueries); try { Assert.AreEqual(12, diff.Methods.RemovedCount, "Removed methods count"); Assert.AreEqual(7, diff.Methods.AddedCount, "Added methods"); } finally { if (ExceptionHelper.InException) { Console.WriteLine("Removed methods"); foreach (var method in diff.Methods.Removed) { Console.WriteLine("{0}", method.ObjectV1.Print(MethodPrintOption.Full)); } Console.WriteLine("Added methods"); foreach (var method in diff.Methods.Added) { Console.WriteLine("{0}", method.ObjectV1.Print(MethodPrintOption.Full)); } } } }
public void DiffEvents() { var simpleV1 = TypeQuery.GetTypeByName(TestConstants.BaseLibV1Assembly, "BaseLibrary.TypeDiff.EventClass"); var simpleV2 = TypeQuery.GetTypeByName(TestConstants.BaseLibV2Assembly, "BaseLibrary.TypeDiff.EventClass"); TypeDiff diff = TypeDiff.GenerateDiff(simpleV1, simpleV2, myQueries); try { Assert.AreEqual(7, diff.Events.RemovedCount, "Removed events"); Assert.AreEqual(10, diff.Events.AddedCount, "Added events"); } finally { if (ExceptionHelper.InException) { Console.WriteLine("Removed events"); foreach (var ev in diff.Events.Removed) { Console.WriteLine("{0}", ev.ObjectV1.Print()); } Console.WriteLine("Added events"); foreach (var ev in diff.Events.Added) { Console.WriteLine("{0}", ev.ObjectV1.Print()); } } } }
public void DiffBaseClassWithChangeInGenericTypeArgs() { var simpleV1 = TypeQuery.GetTypeByName(TestConstants.BaseLibV1Assembly, "BaseLibrary.TypeDiff.ClassWithGenericBase"); var simpleV2 = TypeQuery.GetTypeByName(TestConstants.BaseLibV2Assembly, "BaseLibrary.TypeDiff.ClassWithGenericBase"); TypeDiff diff = TypeDiff.GenerateDiff(simpleV1, simpleV2, myQueries); Assert.IsTrue(diff.HasChangedBaseType, "Base Type has changed generic argument"); }
static IEnumerable<object> BuildMethodsChangedToNonPublic(TypeDiff typeDiff) { foreach (var method in typeDiff.MethodsChangedToNonPublic()) { yield return new { name = method.Left.GetName() }; } }
static IEnumerable<object> BuildMethodsRemoved(TypeDiff typeDiff) { foreach (var method in typeDiff.PublicMethodsRemoved()) { yield return new { name = method.GetName() }; } }
static IEnumerable<object> BuildFieldsChangedToNonPublic(TypeDiff typeDiff) { foreach (var field in typeDiff.FieldsChangedToNonPublic()) { yield return new { name = field.Right.GetName() }; } }
static IEnumerable<object> BuildFieldsRemoved(TypeDiff typeDiff) { foreach (var field in typeDiff.PublicFieldsRemoved()) { yield return new { name = field.GetName() }; } }
static IEnumerable <RemovedItem> BuildMethodsChangedToNonPublic(TypeDiff typeDiff) { foreach (var method in typeDiff.MethodsChangedToNonPublic()) { yield return(new RemovedItem { name = method.Left.GetName() }); } }
static IEnumerable <RemovedItem> BuildMethodsRemoved(TypeDiff typeDiff) { foreach (var method in typeDiff.PublicMethodsRemoved()) { yield return(new RemovedItem { name = method.GetName() }); } }
static IEnumerable <RemovedItem> BuildFieldsRemoved(TypeDiff typeDiff) { foreach (var field in typeDiff.PublicFieldsRemoved()) { yield return(new RemovedItem { name = field.GetName() }); } }
static IEnumerable <RemovedItem> BuildFieldsChangedToNonPublic(TypeDiff typeDiff) { foreach (var field in typeDiff.FieldsChangedToNonPublic()) { yield return(new RemovedItem { name = field.Right.GetName() }); } }
private static string ToTextDiff(Diff diff) { return(diff switch { TypeDiff typeDiff => ToTypeTextDiff(typeDiff), ValueDiff valueDiff => ToValueTypeTextDiff(valueDiff), ArrayDiff arrayDiff => ToArrayTextDiff(arrayDiff), ObjectDiff objectDiff => ToObjectTextDiff(objectDiff), _ => throw new Exception("Unknown diff type") });
private void PrintTypeChanges(TypeDiff typeChange) { Out.WriteLine("\t" + typeChange.TypeV1.Print()); if (typeChange.HasChangedBaseType) { Out.WriteLine("\t\tBase type changed: {0} -> {1}", typeChange.TypeV1.IsNotNull(() => typeChange.TypeV1.BaseType.IsNotNull(() => typeChange.TypeV1.BaseType.FullName)), typeChange.TypeV2.IsNotNull(() => typeChange.TypeV2.BaseType.IsNotNull(() => typeChange.TypeV2.BaseType.FullName)) ); } if (typeChange.Interfaces.Count > 0) { foreach (var addedItf in typeChange.Interfaces.Added) { Out.WriteLine("\t\t+ interface: {0}", addedItf.ObjectV1.FullName); } foreach (var removedItd in typeChange.Interfaces.Removed) { Out.WriteLine("\t\t- interface: {0}", removedItd.ObjectV1.FullName); } } foreach (var addedEvent in typeChange.Events.Added) { Out.WriteLine("\t\t+ {0}", addedEvent.ObjectV1.Print()); } foreach (var remEvent in typeChange.Events.Removed) { Out.WriteLine("\t\t- {0}", remEvent.ObjectV1.Print()); } foreach (var addedField in typeChange.Fields.Added) { Out.WriteLine("\t\t+ {0}", addedField.ObjectV1.Print(FieldPrintOptions.All)); } foreach (var remField in typeChange.Fields.Removed) { Out.WriteLine("\t\t- {0}", remField.ObjectV1.Print(FieldPrintOptions.All)); } foreach (var addedMethod in typeChange.Methods.Added) { Out.WriteLine("\t\t+ {0}", addedMethod.ObjectV1.Print(MethodPrintOption.Full)); } foreach (var remMethod in typeChange.Methods.Removed) { Out.WriteLine("\t\t- {0}", remMethod.ObjectV1.Print(MethodPrintOption.Full)); } }
static IEnumerable <ObsoletedItem> BuildMethodsObsoleted(TypeDiff typeDiff) { foreach (var method in typeDiff.PublicMethodsObsoleted()) { yield return(new ObsoletedItem { name = method.Right.GetName(), obsolete = method.Right.GetObsoleteString() }); } }
public void DiffWithItselfMustReturnEmptyDiff() { var simpleV1 = TypeQuery.GetTypeByName(TestConstants.BaseLibV1Assembly, "BaseLibrary.TypeDiff.ClassWithGenericBase"); TypeDiff diff = TypeDiff.GenerateDiff(simpleV1, simpleV1, myQueries); Assert.IsFalse(diff.HasChangedBaseType, "Base Type has changed generic argument"); Assert.AreEqual(0, diff.Events.Count); Assert.AreEqual(0, diff.Fields.Count); Assert.AreEqual(0, diff.Interfaces.Count); Assert.AreEqual(0, diff.Methods.Count); }
private void PrintTypeChanges(TypeDiff typeChange) { this.Out.WriteLine("\t" + typeChange.TypeV1.Print()); if (typeChange.HasChangedBaseType) { this.Out.WriteLine("\t\tBase type changed: {0} -> {1}", typeChange.TypeV1.IsNotNull(() => typeChange.TypeV1.BaseType.IsNotNull(() => typeChange.TypeV1.BaseType.FullName)), typeChange.TypeV2.IsNotNull(() => typeChange.TypeV2.BaseType.IsNotNull(() => typeChange.TypeV2.BaseType.FullName))); } if (typeChange.Interfaces.Count > 0) { foreach (var addedItf in typeChange.Interfaces.Added) { this.Out.WriteLine("\t\t+ interface: {0}", addedItf.ObjectV1.FullName); } foreach (var removedItd in typeChange.Interfaces.Removed) { this.Out.WriteLine("\t\t- interface: {0}", removedItd.ObjectV1.FullName); } } foreach (var addedEvent in typeChange.Events.Added) { this.Out.WriteLine("\t\t+ {0}", addedEvent.ObjectV1.Print()); } foreach (var remEvent in typeChange.Events.Removed) { this.Out.WriteLine("\t\t- {0}", remEvent.ObjectV1.Print()); } foreach (var addedField in typeChange.Fields.Added) { this.Out.WriteLine("\t\t+ {0}", addedField.ObjectV1.Print(FieldPrintOptions.All)); } foreach (var remField in typeChange.Fields.Removed) { this.Out.WriteLine("\t\t- {0}", remField.ObjectV1.Print(FieldPrintOptions.All)); } foreach (var addedMethod in typeChange.Methods.Added) { this.Out.WriteLine("\t\t+ {0}", addedMethod.ObjectV1.Print(MethodPrintOption.Full)); } foreach (var remMethod in typeChange.Methods.Removed) { this.Out.WriteLine("\t\t- {0}", remMethod.ObjectV1.Print(MethodPrintOption.Full)); } }
public void DiffTypeWithOnlyFieldChanges() { var simpleV1 = TypeQuery.GetTypeByName(TestConstants.BaseLibV1Assembly, "BaseLibrary.TypeDiff.SimpleFieldClass"); var simpleV2 = TypeQuery.GetTypeByName(TestConstants.BaseLibV2Assembly, "BaseLibrary.TypeDiff.SimpleFieldClass"); TypeDiff diff = TypeDiff.GenerateDiff(simpleV1, simpleV2, myQueries); Assert.IsFalse(diff.HasChangedBaseType, "No Base Type change"); Assert.AreEqual(0, diff.Events.Count, "Event count"); Assert.AreEqual(5, diff.Fields.RemovedCount, "Field remove count"); Assert.AreEqual(6, diff.Fields.AddedCount, "Field add count"); Assert.AreEqual(0, diff.Interfaces.Count, "Interface changes"); Assert.AreEqual(0, diff.Methods.Count, "Method changes"); }
public static TypeDiff GetTypeByName(this HashSet <TypeDiff> set, string typeName) { TypeDiff lret = null; foreach (TypeDiff type in set) { if (String.CompareOrdinal(type.ToString(), typeName) == 0) { lret = type; break; } } return(lret); }
private async void HitDamage(TypeDiff td) { personData.HPDino -= personData.Coins * 3 * 5 / (int)td; if (personData.HPDino < 1) { personData.Coins++; personData.HPDino = personData.Coins * 100; personData.FullHPDino = personData.Coins * 100; } switch (td) { case TypeDiff.Easy: if (moveCounter < personData.EasySecRecord) { personData.EasySecRecord = moveCounter; MessageAndroid.ShortAlert("New Record!"); } break; case TypeDiff.Medum: if (moveCounter < personData.MediumSecRecord) { personData.MediumSecRecord = moveCounter; MessageAndroid.ShortAlert("New Record!"); } break; case TypeDiff.Hard: if (moveCounter < personData.HardSecRecord) { personData.HardSecRecord = moveCounter; MessageAndroid.ShortAlert("New Record!"); } break; } string serializeString; serializeString = JsonConvert.SerializeObject(personData); using (var writer = File.CreateText(backingFile)) { await writer.WriteLineAsync(serializeString); //Async } randomizeButton(); }
private void AddIntefaceChange(TypeDiff changedType) { // A changed interface breaks all its implementers new WhoImplementsInterface(myAggregator, changedType.TypeV1); // If methods are removed we must also search for all users of this // interface method List <MethodDefinition> removedInterfaceMethods = changedType.Methods.RemovedList; if (removedInterfaceMethods.Count > 0) { new WhoUsesMethod(myAggregator, removedInterfaceMethods); } List <EventDefinition> removedInterfaceEvents = changedType.Events.RemovedList; if (removedInterfaceEvents.Count > 0) { new WhoUsesEvents(myAggregator, removedInterfaceEvents); } }
protected override void OnStart() { base.OnStart(); typeDiff = JsonConvert.DeserializeObject <TypeDiff>(Intent.GetStringExtra("TypeDiff")); if (typeDiff > 0) { MessageAndroid.ShortAlert(typeDiff.ToString()); } arrNums[0] = one; arrRightsLayouts[0] = one.LayoutParameters; one.SetOnClickListener(this); arrNums[1] = two; arrRightsLayouts[1] = two.LayoutParameters; two.SetOnClickListener(this); arrNums[2] = three; arrRightsLayouts[2] = three.LayoutParameters; three.SetOnClickListener(this); arrNums[3] = four; arrRightsLayouts[3] = four.LayoutParameters; four.SetOnClickListener(this); arrNums[4] = five; arrRightsLayouts[4] = five.LayoutParameters; five.SetOnClickListener(this); arrNums[5] = six; arrRightsLayouts[5] = six.LayoutParameters; six.SetOnClickListener(this); arrNums[6] = seven; arrRightsLayouts[6] = seven.LayoutParameters; seven.SetOnClickListener(this); arrNums[7] = eight; arrRightsLayouts[7] = eight.LayoutParameters; eight.SetOnClickListener(this); arrRightsLayouts[8] = emptyTextView.LayoutParameters; emptyTextView.SetOnClickListener(this); diffText.Text = typeDiff.ToString(); backButtonGameMain.Click += BackButtonGameMain_Click; determinateBar.Progress = 0; }
private void CheckFieldChanges(TypeDiff changedType) { List <FieldDefinition> removedFields = changedType.Fields.RemovedList; if (removedFields.Count > 0) { var nonConstFields = (from field in removedFields where !field.HasConstant select field).ToList(); new WhoAccessesField(myAggregator, nonConstFields); foreach (var field in changedType.Fields.Removed) { if (field.ObjectV1.HasConstant) { Console.WriteLine("Warning: Constants are not referenced by other assemblies but copied by value: field {0} declaring type {1} in assembly {2}", field.ObjectV1.Print(FieldPrintOptions.All), field.ObjectV1.DeclaringType.Name, field.ObjectV1.DeclaringType.Module.Assembly.Name.Name); new WhoUsesType(myAggregator, changedType.TypeV1); } } } }
public TypeMadeNonPublic(TypeDiff typeDiff) { this.typeDiff = typeDiff; }