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""}")); }
public override void OnUpstreamFinish() { var json = _buffer.Poll(); if (json.HasValue) { Emit(_stage.Outlet, json.Value); } else { CompleteStage(); } }
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); }
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}"); }
public void Collecting_json_buffer_when_valid_json_is_supplied_which_has_one_object_should_successfully_parse_single_field_having_string_value_containing_single_quote() { var buffer = new JsonObjectParser(); buffer.Offer(ByteString.FromString("{ \"name\": \"john o'doe\" }")); buffer.Poll().Value.ToString().Should().Be("{ \"name\": \"john o'doe\" }"); }
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(); }
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>(); }
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); }
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); }
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); }
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()); }
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 }"); }
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); }
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); }
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_and_escape_character() { var buffer = new JsonObjectParser(); buffer.Offer(ByteString.FromString("{ \"name\": \"john")); buffer.Offer(ByteString.FromString("\\\"")); buffer.Offer(ByteString.FromString("{")); buffer.Offer(ByteString.FromString("}")); buffer.Offer(ByteString.FromString("\\\"")); buffer.Offer(ByteString.FromString(" ")); buffer.Offer(ByteString.FromString("hey")); buffer.Offer(ByteString.FromString("\"")); buffer.Offer(ByteString.FromString("}")); buffer.Poll().Value.ToString().Should().Be("{ \"name\": \"john\\\"{}\\\" hey\"}"); }