public void Returns_False_For_Invalid_Json() { Assert.False(ShopifyService.TryParseErrorJson("", out _)); Assert.False(ShopifyService.TryParseErrorJson("text here", out _)); Assert.False(ShopifyService.TryParseErrorJson("[]", out _)); Assert.False(ShopifyService.TryParseErrorJson("[1,2,3]", out _)); Assert.False(ShopifyService.TryParseErrorJson("true", out _)); Assert.False(ShopifyService.TryParseErrorJson("false", out _)); }
public void Returns_False_For_Json_That_Does_Not_Match_Expected_Formats() { var json = "{\"error_foo\":\"bar\"}"; Assert.False(ShopifyService.TryParseErrorJson(json, out _)); json = "{\"error_foo\":\"bar\",\"error_description\":\"baz\"}"; Assert.False(ShopifyService.TryParseErrorJson(json, out _)); json = "{\"errors_foo\":\"bar\"}"; Assert.False(ShopifyService.TryParseErrorJson(json, out _)); }
public void Parses_Errors_Of_Type_Three_With_Multiple_Messages() { var json = "{\"errors\":{\"order\":[\"foo error message\",\"bar error message\"]}}"; if (ShopifyService.TryParseErrorJson(json, out var errors)) { Assert.Equal(2, errors.Count()); Assert.Equal("order: foo error message", errors.First()); Assert.Equal("order: bar error message", errors.Last()); } else { CustomAssert.Fail("TryParseErrorJson failed to parse and returned false."); } }
public void Parses_Errors_Of_Type_Five() { var json = "{\"error\":\"location_id must be specified when creating fulfillments.\"}"; if (ShopifyService.TryParseErrorJson(json, out var errors)) { Assert.Single(errors); var error = errors.First(); Assert.Equal("location_id must be specified when creating fulfillments.", error); } else { CustomAssert.Fail("TryParseErrorJson failed to parse and returned false."); } }
public void Parses_Errors_Of_Type_Three() { var json = "{\"errors\":{\"order\":[\"foo error message\"]}}"; if (ShopifyService.TryParseErrorJson(json, out var errors)) { Assert.Single(errors); var error = errors.First(); Assert.Equal("order: foo error message", error); } else { CustomAssert.Fail("TryParseErrorJson failed to parse and returned false."); } }