Example #1
0
        public void RegisterPacketsThrowExceptionOnInvalidTest()
        {
            ServerPacketFactory_Accessor target = new ServerPacketFactory_Accessor(version);
            IEnumerable <Type>           types  = new List <Type> {
                typeof(UnAdornedServerPacket), typeof(ServerPacketDupe2)
            };

            try
            {
                target.RegisterPackets(types);
            }
            catch (PacketRegistrationException ex)
            {
                Assert.IsTrue(ex is PacketRegistrationExceptions);

                PacketRegistrationExceptions caught = (PacketRegistrationExceptions)ex;

                Assert.AreEqual(1, caught.Exceptions.Count());
                Assert.IsTrue(caught.Exceptions.FirstOrDefault() is InvalidPacketException);

                InvalidPacketException inner = (InvalidPacketException)caught.Exceptions.FirstOrDefault();

                Assert.AreEqual(typeof(UnAdornedServerPacket), inner.FailedType);

                return;
            }
            Assert.Fail("Expected exception not thrown.");
        }
Example #2
0
 private void InstanceOnInvalidDataReceived(object?sender, InvalidPacketException e)
 {
     Dispatcher.UIThread.Post((async() =>
     {
         await BluetoothImpl.Instance.DisconnectAsync();
         SetWarning(true, $"{Loc.Resolve("mainpage_corrupt_data")} ({e.ErrorCode})");
         await Task.Delay(500).ContinueWith(async(_) =>
         {
             await Task.Factory.StartNew(() => BluetoothImpl.Instance.ConnectAsync());
             SetWarning(false);
         });
     }), DispatcherPriority.Render);
 }