public static void PrintErrorMessage(JSend resp) { Echo.Print( $" status: {resp.status}" + $" data: {resp.data}" + $" code: {resp.code}" + $" message: {resp.message}"); }
public void NewtonsoftTest() { TestUtil.UseNewtonsoftJson(JSend.Success()); TestUtil.UseNewtonsoftJson(JSend.Success(new { ABC = "abc" })); TestUtil.UseNewtonsoftJson(JSend.Fail()); TestUtil.UseNewtonsoftJson(JSend.Fail(new Dictionary <string, string> { ["ABC"] = "abc" })); TestUtil.UseNewtonsoftJson(JSend.Error("error message")); TestUtil.UseNewtonsoftJson(JSend.Error("error message", "#0", new Dictionary <string, string> { ["ABC"] = "abc" })); }
public void StatusTest() { Assert.True(JSend.Success().IsSuccess()); Assert.False(JSend.Success().IsFail()); Assert.False(JSend.Success().IsError()); Assert.False(JSend.Fail().IsSuccess()); Assert.True(JSend.Fail().IsFail()); Assert.False(JSend.Fail().IsError()); Assert.False(JSend.Error("").IsSuccess()); Assert.False(JSend.Error("").IsFail()); Assert.True(JSend.Error("").IsError()); }
internal static void UseNewtonsoftJson(JSend jsend) { var json = JsonConvert.SerializeObject(jsend); var deserialized = JsonConvert.DeserializeObject <JSend>(json); Assert.Equal(jsend.status, deserialized.status); if (jsend.IsSuccess()) { Assert.Equal(Any(jsend.data), Any(deserialized.data)); } else if (jsend.IsFail()) { Assert.Equal(Any(jsend.data), Any(deserialized.data)); } else if (jsend.IsError()) { Assert.Equal(jsend.code, deserialized.code); Assert.Equal(jsend.message, deserialized.message); } }
internal static void UseSystemJson(JSend jsend) { var json = System.Text.Json.JsonSerializer.Serialize(jsend); var deserialized = System.Text.Json.JsonSerializer.Deserialize <JSend>(json); Assert.Equal(jsend.status, deserialized.status); if (jsend.IsSuccess()) { Assert.Equal(Any(jsend.data), Any(deserialized.data)); } else if (jsend.IsFail()) { Assert.Equal(Any(jsend.data), Any(deserialized.data)); } else if (jsend.IsError()) { Assert.Equal(jsend.code, deserialized.code); Assert.Equal(jsend.message, deserialized.message); } }