diff --git a/build/version.txt b/build/version.txt index 835fcc8d..48f8d8b3 100644 --- a/build/version.txt +++ b/build/version.txt @@ -6,4 +6,4 @@ # Patch: Backwards compatible bug fixes only # -Suffix (optional): a hyphen followed by a string denoting a pre-release version (rc1, rc2, etc.) -9.0.0-rc1 +9.0.0-rc2 diff --git a/src/ClashOfClans.Models/ClientError.cs b/src/ClashOfClans.Models/ClientError.cs index 8b7fb3c5..23c5503b 100644 --- a/src/ClashOfClans.Models/ClientError.cs +++ b/src/ClashOfClans.Models/ClientError.cs @@ -1,15 +1,14 @@ -using System; - -namespace ClashOfClans.Models +namespace ClashOfClans.Models { /// /// Error message from the endpoint /// - [Serializable] public class ClientError { public string Reason { get; set; } = default!; public string Message { get; set; } = default!; + + public override string ToString() => $"Reason '{Reason}', message '{Message}'"; } } diff --git a/src/ClashOfClans.Tests.Unit/ClashOfClansExceptionTests.cs b/src/ClashOfClans.Tests.Unit/ClashOfClansExceptionTests.cs index 21f7249a..c370800a 100644 --- a/src/ClashOfClans.Tests.Unit/ClashOfClansExceptionTests.cs +++ b/src/ClashOfClans.Tests.Unit/ClashOfClansExceptionTests.cs @@ -1,7 +1,6 @@ using ClashOfClans.Core; using ClashOfClans.Models; using Microsoft.VisualStudio.TestTools.UnitTesting; -using Newtonsoft.Json; namespace ClashOfClans.Tests.Unit { @@ -22,25 +21,26 @@ public void ThrowClashOfClansException() } [TestMethod] - public void SerializeAndDeserializeClashOfClansExceptionUsingNewtonsoft() + public void ClashOfClansExceptionHasClientError() { // Arrange var error = new ClientError { - Message = "message", - Reason = "reason" + Reason = "Error reason", + Message = "Error message" }; - var originalException = new ClashOfClansException(error); - // Act - var output = JsonConvert.SerializeObject(originalException); - var deserializedException = JsonConvert.DeserializeObject(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); + try + { + // Act + throw new ClashOfClansException(error); + } + catch (ClashOfClansException ex) + { + // Assert + Assert.AreEqual(error.Reason, ex.Error.Reason); + Assert.AreEqual(error.Message, ex.Error.Message); + } } } } diff --git a/src/ClashOfClans/Core/ClashOfClansException.cs b/src/ClashOfClans/Core/ClashOfClansException.cs index 42f714a2..ffdcb118 100644 --- a/src/ClashOfClans/Core/ClashOfClansException.cs +++ b/src/ClashOfClans/Core/ClashOfClansException.cs @@ -1,14 +1,11 @@ using ClashOfClans.Models; using System; -using System.Runtime.Serialization; -using System.Security.Permissions; namespace ClashOfClans.Core { /// /// Represents errors that occur when communicating with the official Clash of Clans API /// - [Serializable] public class ClashOfClansException : Exception { /// @@ -39,16 +36,6 @@ public ClashOfClansException(ClientError error) Error = error; } - protected ClashOfClansException(SerializationInfo info, StreamingContext context) - : base(info, context) - { - Error = (ClientError)info.GetValue(nameof(Error), typeof(ClientError))!; - } - - public override void GetObjectData(SerializationInfo info, StreamingContext context) - { - base.GetObjectData(info, context); - info.AddValue(nameof(Error), Error); - } + public override string Message => Error.ToString(); } }