Skip to content

Commit

Permalink
Merge branch 'main' into mha/openapi-fix-unittests
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelstaib authored Nov 21, 2023
2 parents f1f8d45 + 645185d commit 593f1a2
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Reflection;
Expand Down Expand Up @@ -60,11 +61,14 @@ public static Expression In(
Type genericType,
object? parsedValue)
{
var enumerableType = typeof(IEnumerable<>);
var enumerableGenericType = enumerableType.MakeGenericType(genericType);

return Expression.Call(
typeof(Enumerable),
nameof(Enumerable.Contains),
new Type[] { genericType },
Expression.Constant(parsedValue),
CreateParameter(parsedValue, enumerableGenericType),
property);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ public static JsonElement SafeClone(this JsonElement element)
using var jsonWriter = new Utf8JsonWriter(writer);

element.WriteTo(jsonWriter);
var reader = new Utf8JsonReader(writer.GetSpan(), true, default);
jsonWriter.Flush();
var reader = new Utf8JsonReader(writer.GetWrittenSpan(), true, default);

return JsonElement.ParseValue(ref reader);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,10 @@ public override JsonElement Parse(JsonElement serializedValue)
// write json value to buffer.
using var jsonWriter = new Utf8JsonWriter(writer);
serializedValue.WriteTo(jsonWriter);
jsonWriter.Flush();

// now we read the buffer and create an element that does not need to be disposed.
var reader = new Utf8JsonReader(writer.GetSpan(), true, default);
var reader = new Utf8JsonReader(writer.GetWrittenSpan(), true, default);
return JsonElement.ParseValue(ref reader);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,35 @@ public void Parse()
Assert.Equal(element.ToString(), serialized.ToString());
}

[Fact]
public void ParseLarge()
{
// arrange
var json = System.Text.Json.JsonSerializer.SerializeToElement($@"""{"padding",10000}""");

// act
var serialized = _serializer.Parse(json);

// assert
Assert.Equal(json.ToString(), serialized.ToString());
}

[Fact]
public void UseAfterDispose()
{
// arrange
var json = JsonDocument.Parse(@"{ ""abc"": {""def"":""def""} }");
var element = json.RootElement.EnumerateObject().First().Value;

// act
var serialized = _serializer.Parse(element);
var expected = element.ToString();
json.Dispose();

// assert
Assert.Equal(expected, serialized.ToString());
}

[Fact]
public void Format()
{
Expand Down
2 changes: 1 addition & 1 deletion website/src/pages/products/bananacakepop.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ const BananaCakePopPage: FC = () => {
<h2>Organization Workspaces</h2>
</header>
<p>
Organize your GraphQL APIs and collaborate with colleges across
Organize your GraphQL APIs and collaborate with colleagues across
your organization with ease.
</p>
</CardOffer>
Expand Down

0 comments on commit 593f1a2

Please sign in to comment.