public void GetRuntimeEvents() { var types = GetTypes(); Assert.Throws <ArgumentNullException>(() => { RuntimeReflectionExtensions.GetRuntimeEvents(null); }); List <string> events = new List <string>(); foreach (TypeInfo type in types) { if (!type.Namespace.Equals("EventDefinitions", StringComparison.Ordinal)) { continue; } if (type.IsInterface) { continue; } events.Clear(); events.AddRange((IEnumerable <string>)type.GetDeclaredField("DeclaredEvents").GetValue(null)); events.AddRange((IEnumerable <string>)type.GetDeclaredField("InheritedEvents").GetValue(null)); Assert.All(type.AsType().GetRuntimeEvents(), e => Assert.True(events.Remove(e.Name))); Assert.Empty(events); } }
public static IEnumerable <EventInfo> GetRuntimeEvents(this Type type) { #if UNITY_METRO && !UNITY_EDITOR return(RuntimeReflectionExtensions.GetRuntimeEvents(type)); #else return(type.GetEvents()); #endif }
public void GetRuntimeEvents() { var types = GetTypes(); Assert.Throws <ArgumentNullException>(() => { RuntimeReflectionExtensions.GetRuntimeEvents(null); }); List <String> events = new List <String>(); foreach (TypeInfo type in types) { if (!type.Namespace.Equals("EventDefinitions", StringComparison.Ordinal)) { continue; } if (type.IsInterface) { continue; } events.Clear(); events.AddRange((IEnumerable <String>)type.GetDeclaredField("DeclaredEvents").GetValue(null)); events.AddRange((IEnumerable <String>)type.GetDeclaredField("InheritedEvents").GetValue(null)); foreach (EventInfo ei in type.AsType().GetRuntimeEvents()) { if (events.Remove(ei.Name)) { continue; } Assert.False(true, String.Format("Type: {0}, Event: {1} is not expected", type, ei)); } foreach (String eventName in events) { Assert.False(true, String.Format("Event: {0} cannot be found", eventName)); } } }