private void Serializes_ErrorResponseData(ISerializer serializer)
        {
            var error = new ErrorResponseData(ErrorResponseCodes.UnauthorizedRequest, "crap", true);

            var pack = new ResponsePacket(error);

            using (var ms = new MemoryStream())
                using (var writer = new BinaryWriter(ms))
                    using (var reader = new BinaryReader(ms)) {
                        pack.Serialize(writer, serializer);

                        ms.Position = 0;

                        var p2 = new TestDataPacket();
                        p2.Deserialize(reader, serializer);

                        Assert.AreEqual(error.Code, p2.As <ErrorResponseData>().Code);
                        Assert.AreEqual(error.Message, p2.As <ErrorResponseData>().Message);
                        Assert.AreEqual(error.IsCritical, p2.As <ErrorResponseData>().IsCritical);
                        Assert.AreEqual(error.GetType(), p2.Data.GetType());
                        Assert.AreEqual(typeof(ErrorResponseData).AssemblyQualifiedName, p2.DataType);
                    }
        }
        public void As_ThrowsInvalidCastIfCastIsIncorrect()
        {
            var dp = new TestDataPacket("asdf");

            try {
                dp.As <IConnectionListener>();
                Assert.Fail("Exception should have been thrown");
            }
#pragma warning disable CS0168 // Variable is declared but never used
            catch (InvalidCastException ex)
#pragma warning restore CS0168 // Variable is declared but never used
            {
            }
        }