Beispiel #1
0
        public void Collecting_json_buffer_when_valid_json_is_supplied_which_has_one_object_should_successfully_parse_single_field_having_string_value_containing_curly_brace()
        {
            var buffer = new JsonObjectParser();

            buffer.Offer(ByteString.FromString("{ \"name\": \"john{"));
            buffer.Offer(ByteString.FromString("}"));
            buffer.Offer(ByteString.FromString("\""));
            buffer.Offer(ByteString.FromString("}"));
            buffer.Poll().Value.ToString().Should().Be("{ \"name\": \"john{}\"}");
        }
Beispiel #2
0
        public void Collecting_json_buffer_when_valid_json_is_supplied_which_returns_none_until_valid_json_is_encountered()
        {
            var buffer = new JsonObjectParser();

            @"{ ""name"" : ""john""".ForEach(c =>
            {
                buffer.Offer(ByteString.FromString(c.ToString()));
                buffer.Poll().Should().Be(Option <ByteString> .None);
            });

            buffer.Offer(ByteString.FromString("}"));
            buffer.Poll().Value.Should().BeEquivalentTo(ByteString.FromString(@"{ ""name"" : ""john""}"));
        }
Beispiel #3
0
        public void Collecting_json_buffer_when_invalid_json_is_supplied_should_fail_if_it_is_broken_from_the_start()
        {
            var buffer = new JsonObjectParser();

            buffer.Offer(ByteString.FromString("THIS IS NOT VALID { \name\": \"john\"}"));
            buffer.Invoking(b => b.Poll()).Should().Throw <Framing.FramingException>();
        }
Beispiel #4
0
        public void Collecting_json_buffer_when_valid_json_is_supplied_which_has_complex_object_graph_should_successfully_parse()
        {
            var          buffer  = new JsonObjectParser();
            const string content = @"{
                 ""name"": ""john"",
                 ""addresses"": [
                   {
                     ""street"": ""3 Hopson Street"",
                     ""postcode"": ""ABC-123"",
                     ""tags"": [""work"", ""office""],
                     ""contactTime"": [
                       {""time"": ""0900-1800"", ""timezone"", ""UTC""}
                     ]
                   },
                   {
                     ""street"": ""12 Adielie Road"",
                     ""postcode"": ""ZZY-888"",
                     ""tags"": [""home""],
                     ""contactTime"": [
                       {""time"": ""0800-0830"", ""timezone"", ""UTC""},
                       {""time"": ""1800-2000"", ""timezone"", ""UTC""}
                     ]
                   }
                 ]
               }";

            buffer.Offer(ByteString.FromString(content));
            buffer.Poll().Value.ToString().Should().Be(content);
        }
Beispiel #5
0
        public void Collecting_json_buffer_when_valid_json_is_supplied_which_has_one_object_should_successfully_parse_single_field_having_decimal_value()
        {
            var buffer = new JsonObjectParser();

            buffer.Offer(ByteString.FromString("{ \"age\" : 10.1}"));
            buffer.Poll().Value.ToString().Should().Be("{ \"age\" : 10.1}");
        }
Beispiel #6
0
        public void Collecting_json_buffer_when_valid_json_is_supplied_which_has_one_object_should_successfully_parse_empty_object()
        {
            var buffer = new JsonObjectParser();

            buffer.Offer(ByteString.FromString("{}"));
            buffer.Poll().Value.ToString().Should().Be("{}");
        }
        public void Counting_1()
        {
            var bracket = new JsonObjectParser();

            bracket.Offer(Json);
            bracket.Poll();
            _bracketThroughputCounter.Increment();
        }
Beispiel #8
0
        public void Collecting_json_buffer_when_invalid_json_is_supplied_should_fail_if_it_is_broken_at_the_end()
        {
            var buffer = new JsonObjectParser();

            buffer.Offer(ByteString.FromString("{ \"name\": \"john\"} THIS IS NOT VALID "));
            buffer.Poll(); // first emitting the valid element
            buffer.Invoking(b => b.Poll()).Should().Throw <Framing.FramingException>();
        }
Beispiel #9
0
        public void Collecting_json_buffer_when_valid_json_is_supplied_which_has_multiple_fields_should_parse_successfully()
        {
            var          buffer  = new JsonObjectParser();
            const string content = "{ \"name\": \"john\", \"age\" : 101}";

            buffer.Offer(ByteString.FromString(content));
            buffer.Poll().Value.ToString().Should().Be(content);
        }
Beispiel #10
0
        public void Collecting_json_buffer_when_valid_json_is_supplied_which_has_one_object_should_successfully_parse_a_string_that_contains_an_escaped_quote()
        {
            var          buffer  = new JsonObjectParser();
            const string content = "{ \"key\": \"\\\"\" }";

            buffer.Offer(ByteString.FromString(content));
            buffer.Poll().Value.ToString().Should().Be(content);
        }
Beispiel #11
0
        public void Collecting_json_buffer_when_valid_json_is_supplied_which_has_one_object_should_successfully_parse_an_escaped_backslash_followed_by_a_double_quote()
        {
            var          buffer  = new JsonObjectParser();
            const string content = @"{ ""key"": ""\\"" }";

            buffer.Offer(ByteString.FromString(content));
            buffer.Poll().Value.ToString().Should().Be(content);
        }
Beispiel #12
0
        public void Collecting_json_buffer_when_valid_json_is_supplied_which_has_multiple_fields_should_parse_successfully_despite_valid_whitespaces_around_json()
        {
            var          buffer  = new JsonObjectParser();
            const string content = "        " +
                                   "        " +
                                   "{ \"name\": \"john\"" +
                                   ", \"age\" : 101}";

            buffer.Offer(ByteString.FromString(content));
            buffer.Poll().Value.DecodeString().Should().Be(content.TrimStart());
        }
Beispiel #13
0
        public void Collecting_json_buffer_when_valid_json_is_supplied_which_has_multiple_objects_should_pops_the_right_object_as_buffer_is_filled()
        {
            var          buffer = new JsonObjectParser();
            const string input1 = @"{
                 ""name"": ""john"",
                 ""age"": 32
               }";
            const string input2 = @"{
                 ""name"": ""katie"",
                 ""age"": 25
               }";

            buffer.Offer(ByteString.FromString(input1 + "," + input2));
            buffer.Poll().Value.ToString().Should().Be(input1);
            buffer.Poll().Value.ToString().Should().Be(input2);

            buffer.Poll().Should().Be(Option <ByteString> .None);
            buffer.Offer(ByteString.FromString("{\"name\":\"jenkins\",\"age\": "));
            buffer.Poll().Should().Be(Option <ByteString> .None);

            buffer.Offer(ByteString.FromString("65 }"));
            buffer.Poll().Value.ToString().Should().Be("{\"name\":\"jenkins\",\"age\": 65 }");
        }
Beispiel #14
0
        public void Collecting_json_buffer_when_valid_json_is_supplied_which_has_one_object_should_successfully_parse_single_field_having_nested_object()
        {
            var          buffer  = new JsonObjectParser();
            const string content = "{ \"name\" : \"john\"," +
                                   "  \"age\"  : 101," +
                                   "  \"address\": {" +
                                   "       \"street\": \"Straight Street\"," +
                                   "       \"postcode\": 1234" +
                                   "  }" +
                                   "}";

            buffer.Offer(ByteString.FromString(content));
            buffer.Poll().Value.ToString().Should().Be(content);
        }
Beispiel #15
0
        public void Collecting_json_buffer_when_valid_json_is_supplied_which_has_nested_array_should_successfully_parse()
        {
            var          buffer  = new JsonObjectParser();
            const string content = "{ \"name\" : \"john\"," +
                                   "  \"things\": [" +
                                   "      1," +
                                   "      \"hey\"," +
                                   "      3" +
                                   "      \"there\"" +
                                   "  ]" +
                                   "}";

            buffer.Offer(ByteString.FromString(content));
            buffer.Poll().Value.ToString().Should().Be(content);
        }
Beispiel #16
0
 public override void OnPush()
 {
     _buffer.Offer(Grab(_stage.Inlet));
     TryPopBuffer();
 }