Ejemplo n.º 1
0
        public void TestDictionary()
        {
            string    str       = "This is a Dictionary payload";
            Event     @event    = new UnhandledEvent(DateTime.UtcNow, "testEvent");
            Exception exception = new InvalidCastException();

            Dictionary <string, object> data = new Dictionary <string, object>();

            data.Add("message", str);
            data.Add("event", @event);
            data.Add("exception", exception);

            Dictionary <string, object> result = PrepRollbarData(data);

            result.TryGetValue("message", out object message);
            Assert.AreEqual(str, message?.ToString());

            result.TryGetValue("event", out object theEvent);
            ((JObject)theEvent).TryGetValue("timestamp", out JToken timestamp);
            Assert.IsNull(timestamp?.ToString());
            ((JObject)theEvent).TryGetValue("type", out JToken type);
            Assert.IsNotNull(type);
            Assert.AreEqual(@event.type, type?.ToString());

            result.TryGetValue("exception", out object theException);
            ((JObject)theException).TryGetValue("Message", out JToken theExceptionMessage);
            Assert.AreEqual(exception.Message, theExceptionMessage?.ToString());
        }
Ejemplo n.º 2
0
        public void TestOther()
        {
            Event data = new UnhandledEvent(DateTime.UtcNow, "testEvent");
            Dictionary <string, object> result = PrepRollbarData(data);

            Assert.IsFalse(result.TryGetValue("timestamp", out object timestamp));
            Assert.IsTrue(result.TryGetValue("type", out object type));
        }
Ejemplo n.º 3
0
        public void TestUnhandledEvent()
        {
            string       line   = @"{ ""timestamp"":""2018 - 10 - 30T20: 45:07Z"", ""event"":""AnyUnhandledEvent""}";
            List <Event> events = JournalMonitor.ParseJournalEntry(line);

            Assert.AreEqual(1, events.Count);
            UnhandledEvent @event = (UnhandledEvent)events[0];

            Assert.AreEqual("AnyUnhandledEvent", @event.edType);
            Assert.IsNotNull(@event.raw);
        }
Ejemplo n.º 4
0
        public bool GetUnhandledEvent(Control source, string eventName)
        {
            var key = new UnhandledEvent {
                Source = source, Name = eventName
            };
            var index = FindEvent(PreviousUnhandledEvents, ref key);

            if (index >= 0)
            {
                PreviousUnhandledEvents.RemoveAt(index);
                return(true);
            }

            index = FindEvent(UnhandledEvents, ref key);
            if (index >= 0)
            {
                UnhandledEvents.RemoveAt(index);
                return(true);
            }

            return(false);
        }
Ejemplo n.º 5
0
 public void MethodThatCausesAnEventThatDoesNotConaintAHandler()
 {
     var e = new UnhandledEvent();
     ApplyEvent(e);
 }
Ejemplo n.º 6
0
        public void TestUnhandledEvents()
        {
            string location = @"{ ""timestamp"":""2018-12-16T20:08:31Z"", ""event"":""Location"", ""Docked"":false, ""StarSystem"":""Pleiades Sector GW-W c1-4"", ""SystemAddress"":1183229809290, ""StarPos"":[-81.62500,-151.31250,-383.53125], ""SystemAllegiance"":"""", ""SystemEconomy"":""$economy_None;"", ""SystemEconomy_Localised"":""None"", ""SystemSecondEconomy"":""$economy_None;"", ""SystemSecondEconomy_Localised"":""None"", ""SystemGovernment"":""$government_None;"", ""SystemGovernment_Localised"":""None"", ""SystemSecurity"":""$GAlAXY_MAP_INFO_state_anarchy;"", ""SystemSecurity_Localised"":""Anarchy"", ""Population"":0, ""Body"":""Pleiades Sector GW-W c1-4"", ""BodyID"":0, ""BodyType"":""Star"" }";
            string jump     = @"{ ""timestamp"":""2018-12-16T20:10:15Z"", ""event"":""FSDJump"", ""StarSystem"":""Pleiades Sector HR-W d1-79"", ""SystemAddress"":2724879894859, ""StarPos"":[-80.62500,-146.65625,-343.25000], ""SystemAllegiance"":""Independent"", ""SystemEconomy"":""$economy_Extraction;"", ""SystemEconomy_Localised"":""Extraction"", ""SystemSecondEconomy"":""$economy_None;"", ""SystemSecondEconomy_Localised"":""None"", ""SystemGovernment"":""$government_Prison;"", ""SystemGovernment_Localised"":""Detention Centre"", ""SystemSecurity"":""$SYSTEM_SECURITY_high;"", ""SystemSecurity_Localised"":""High Security"", ""Population"":0, ""JumpDist"":40.562, ""FuelUsed"":2.827265, ""FuelLevel"":11.702736, ""Factions"":[ { ""Name"":""Independent Detention Foundation"", ""FactionState"":""None"", ""Government"":""Prison"", ""Influence"":0.000000, ""Allegiance"":""Independent"", ""Happiness"":""$Faction_HappinessBand2;"", ""Happiness_Localised"":""Happy"", ""MyReputation"":0.000000 }, { ""Name"":""Pilots Federation Local Branch"", ""FactionState"":""None"", ""Government"":""Democracy"", ""Influence"":0.000000, ""Allegiance"":""PilotsFederation"", ""Happiness"":"""", ""MyReputation"":100.000000 } ], ""SystemFaction"":""Independent Detention Foundation"" }";
            string scan     = @"{ ""timestamp"":""2018-12-16T20:10:21Z"", ""event"":""Scan"", ""ScanType"":""AutoScan"", ""BodyName"":""Pleiades Sector HR-W d1-79"", ""BodyID"":0, ""DistanceFromArrivalLS"":0.000000, ""StarType"":""F"", ""StellarMass"":1.437500, ""Radius"":855515008.000000, ""AbsoluteMagnitude"":3.808395, ""Age_MY"":1216, ""SurfaceTemperature"":6591.000000, ""Luminosity"":""Vab"", ""RotationPeriod"":261918.156250, ""AxialTilt"":0.000000 }";
            string scan2    = @"{ ""timestamp"":""2018-12-16T20:28:02Z"", ""event"":""Scan"", ""ScanType"":""Detailed"", ""BodyName"":""Hyades Sector DL-X b1-2"", ""BodyID"":0, ""DistanceFromArrivalLS"":0.000000, ""StarType"":""M"", ""StellarMass"":0.367188, ""Radius"":370672928.000000, ""AbsoluteMagnitude"":9.054306, ""Age_MY"":586, ""SurfaceTemperature"":2993.000000, ""Luminosity"":""Va"", ""RotationPeriod"":167608.859375, ""AxialTilt"":0.000000, ""Rings"":[ { ""Name"":""Hyades Sector DL-X b1-2 A Belt"", ""RingClass"":""eRingClass_MetalRich"", ""MassMT"":5.4671e+13, ""InnerRad"":7.1727e+08, ""OuterRad"":1.728e+09 }, { ""Name"":""Hyades Sector DL-X b1-2 B Belt"", ""RingClass"":""eRingClass_Icy"", ""MassMT"":8.7822e+14, ""InnerRad"":6.3166e+10, ""OuterRad"":1.5917e+11 } ] }";
            string jump2    = @"{ ""timestamp"":""2019-01-27T07:23:38Z"", ""event"":""FSDJump"", ""StarSystem"":""Omega Sector OO-G a11-0"", ""SystemAddress"":5213552532472, ""StarPos"":[-1433.53125,-94.15625,5326.34375], ""SystemAllegiance"":"""", ""SystemEconomy"":""$economy_None;"", ""SystemEconomy_Localised"":""None"", ""SystemSecondEconomy"":""$economy_None;"", ""SystemSecondEconomy_Localised"":""None"", ""SystemGovernment"":""$government_None;"", ""SystemGovernment_Localised"":""None"", ""SystemSecurity"":""$GAlAXY_MAP_INFO_state_anarchy;"", ""SystemSecurity_Localised"":""Anarchy"", ""Population"":0, ""JumpDist"":56.848, ""FuelUsed"":4.741170, ""FuelLevel"":21.947533 }";
            string scan3    = @"{""timestamp"":""2019-01-27T07:07:46Z"",""event"":""Scan"",""ScanType"":""AutoScan"",""BodyName"":""Omega Sector DM-M b7-16 A B Belt Cluster 8"",""BodyID"":23,""Parents"":[{""Ring"":15},{""Star"":1},{""Null"":0}],""DistanceFromArrivalLS"":646.57074}";

            EDDNResponder.EDDNResponder responder = makeTestEDDNResponder();
            var privateObject = new PrivateObject(responder);

            object[] arguments;

            UnhandledEvent unhandledLocation = new UnhandledEvent(DateTime.UtcNow, "Location")
            {
                raw = location
            };

            arguments = new object[] { unhandledLocation };
            privateObject.Invoke("handleRawEvent", arguments);
            Assert.AreEqual("Pleiades Sector GW-W c1-4", responder.systemName);
            Assert.AreEqual(1183229809290, responder.systemAddress);
            Assert.AreEqual(-81.62500M, responder.systemX);
            Assert.AreEqual(-151.31250M, responder.systemY);
            Assert.AreEqual(-383.53125M, responder.systemZ);
            Assert.IsNull(responder.stationName);
            Assert.IsNull(responder.marketId);

            UnhandledEvent unhandledJump = new UnhandledEvent(DateTime.UtcNow, "FSDJump")
            {
                raw = jump
            };

            arguments = new object[] { unhandledJump };
            privateObject.Invoke("handleRawEvent", arguments);
            Assert.AreEqual("Pleiades Sector HR-W d1-79", responder.systemName);
            Assert.AreEqual(2724879894859, responder.systemAddress);
            Assert.AreEqual(-80.62500M, responder.systemX);
            Assert.AreEqual(-146.65625M, responder.systemY);
            Assert.AreEqual(-343.25000M, responder.systemZ);
            Assert.IsNull(responder.stationName);
            Assert.IsNull(responder.marketId);

            UnhandledEvent unhandledScan = new UnhandledEvent(DateTime.UtcNow, "Scan")
            {
                raw = scan
            };

            arguments = new object[] { unhandledScan };
            privateObject.Invoke("handleRawEvent", arguments);
            Assert.AreEqual("Pleiades Sector HR-W d1-79", responder.systemName);
            Assert.AreEqual(2724879894859, responder.systemAddress);
            Assert.AreEqual(-80.62500M, responder.systemX);
            Assert.AreEqual(-146.65625M, responder.systemY);
            Assert.AreEqual(-343.25000M, responder.systemZ);
            Assert.IsNull(responder.stationName);
            Assert.IsNull(responder.marketId);

            // Deliberately scan a procedurally generated body that doesn't match our last known location & verify heuristics catch it
            UnhandledEvent unhandledScan2 = new UnhandledEvent(DateTime.UtcNow, "Scan")
            {
                raw = scan2
            };

            arguments = new object[] { unhandledScan2 };
            privateObject.Invoke("handleRawEvent", arguments);
            Assert.IsNull(responder.systemName);
            Assert.IsNull(responder.systemAddress);
            Assert.IsNull(responder.systemX);
            Assert.IsNull(responder.systemY);
            Assert.IsNull(responder.systemZ);
            Assert.IsNull(responder.stationName);
            Assert.IsNull(responder.marketId);

            // Reset our position by re-stating the `FSDJump` event
            arguments = new object[] { unhandledJump };
            privateObject.Invoke("handleRawEvent", arguments);

            // Deliberately create a mismatch between the system and coordinates,
            // using the coordinates from our Location event and other data from our FSDJump event
            privateObject.SetFieldOrProperty("systemX", -81.62500M);
            privateObject.SetFieldOrProperty("systemY", -151.31250M);
            privateObject.SetFieldOrProperty("systemZ", -383.53125M);

            // Deliberately scan a body while our coordinates are in a bad state
            arguments = new object[] { unhandledScan };
            privateObject.Invoke("handleRawEvent", arguments);
            Assert.IsNull(responder.systemX);
            Assert.IsNull(responder.systemY);
            Assert.IsNull(responder.systemZ);

            // Reset our position by re-stating the `FSDJump` event
            arguments = new object[] { unhandledJump };
            privateObject.Invoke("handleRawEvent", arguments);

            // Deliberately create a mismatch between the system name and address,
            // using the address from our Location event and other data from our FSDJump event
            privateObject.SetFieldOrProperty("systemAddress", 1183229809290);

            // Deliberately scan a body while our system address is in a bad state
            arguments = new object[] { unhandledScan };
            privateObject.Invoke("handleRawEvent", arguments);
            Assert.IsNull(responder.systemAddress);

            // Reset our position by stating another `FSDJump` event
            UnhandledEvent unhandledJump2 = new UnhandledEvent(DateTime.UtcNow, "FSDJump")
            {
                raw = jump2
            };

            arguments = new object[] { unhandledJump2 };
            privateObject.Invoke("handleRawEvent", arguments);

            // Scan a belt cluster from a different star system
            UnhandledEvent unhandledScan3 = new UnhandledEvent(DateTime.UtcNow, "Scan")
            {
                raw = scan3
            };

            arguments = new object[] { unhandledScan3 };
            privateObject.Invoke("handleRawEvent", arguments);
            Assert.IsNull(responder.systemName);
            Assert.IsNull(responder.systemAddress);
            Assert.IsNull(responder.systemX);
            Assert.IsNull(responder.systemY);
            Assert.IsNull(responder.systemZ);
        }
Ejemplo n.º 7
0
            public void MethodThatCausesAnEventThatDoesNotConaintAHandler()
            {
                var e = new UnhandledEvent();

                ApplyEvent(e);
            }
Ejemplo n.º 8
0
 public bool Equals(UnhandledEvent rhs)
 {
     return((Source == rhs.Source) &&
            (Name == rhs.Name));
 }
Ejemplo n.º 9
0
 public Task InvokeUnhandledEvent(string eventName, ResponseArgs args)
 {
     UnhandledEvent?.Invoke(eventName, args);
     return(Task.CompletedTask);
 }
Ejemplo n.º 10
0
 private void UncaughtHandler(string eventName, ResponseArgs args) => UnhandledEvent?.Invoke(eventName, args);