Example #1
0
 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 _));
 }
Example #2
0
        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 _));
        }
Example #3
0
        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.");
            }
        }
Example #4
0
        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.");
            }
        }
Example #5
0
        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.");
            }
        }