Example #1
0
        public void SerializeAndDeserializeClashOfClansExceptionUsingBinaryFormatter()
        {
            // Arrange
            var error = new ClientError
            {
                Message = "message",
                Reason  = "reason"
            };
            var originalException = new ClashOfClansException(error);
            var formatter         = new BinaryFormatter();

            using (var ms = new MemoryStream())
            {
                // Act
                formatter.Serialize(ms, originalException);
                ms.Position = 0;
                var deserializedException = (ClashOfClansException)formatter.Deserialize(ms);

                // Assert
                Assert.IsNotNull(deserializedException);
                Assert.AreEqual(originalException.Message, deserializedException.Message);
                Assert.AreEqual(originalException.Error.Message, deserializedException.Error.Message);
                Assert.AreEqual(originalException.Error.Reason, deserializedException.Error.Reason);
            }
        }
Example #2
0
        public void SerializeAndDeserializeClashOfClansExceptionUsingNewtonsoft()
        {
            // Arrange
            var error = new ClientError
            {
                Message = "message",
                Reason  = "reason"
            };
            var originalException = new ClashOfClansException(error);

            // Act
            var output = JsonConvert.SerializeObject(originalException);
            var deserializedException = JsonConvert.DeserializeObject <ClashOfClansException>(output);

            // Assert
            Assert.IsNotNull(deserializedException);
            Assert.AreEqual(originalException.Message, deserializedException.Message);
            Assert.AreEqual(originalException.Error.Message, deserializedException.Error.Message);
            Assert.AreEqual(originalException.Error.Reason, deserializedException.Error.Reason);
        }