Skip to content

Commit

Permalink
Make a messagepack deserialize test (#10163)
Browse files Browse the repository at this point in the history
This adds a test case that verifies deserializing a test file rather
than going through the serialize/deserialize loop. Instructions are
added for if the test fails.
  • Loading branch information
ryzngard authored Mar 26, 2024
2 parents 4226112 + 188316b commit 3fe8231
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 0 deletions.
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,35 @@ public void VerifyJson_TagHelpers(string resourceName, string? folderName = null
Assert.Equal<TagHelperDescriptor>(originalTagHelpers, actualTagHelpers);
}


/// <summary>
/// Verifies that a previous generated file is able to be serialized. If this
/// fails make sure to do ONE of the following:
///
/// 1. Update the deserializer to be lenient on the previous version
/// 2. Bump the Microsoft.AspNetCore.Razor.Serialization.MessagePack.SerializationFormat.Version
/// a. Generate a new file to replace project.razor.bin with the new format. As of writing this was made from the base blazorserver template
/// b. This will require a dual insertion with Roslyn do use the correct version number
/// </summary>
[Theory]
[InlineData("project.razor.bin")]
public void VerifyMessagePack_DeserializeMessagepack(string resourceName)
{
// Arrange
var resourceBytes = RazorTestResources.GetResourceBytes(resourceName, "Benchmarking");
var options = MessagePackSerializerOptions.Standard
.WithResolver(CompositeResolver.Create(
RazorProjectInfoResolver.Instance,
StandardResolver.Instance));

// Act
var actualProjectInfo = MessagePackConvert.Deserialize<RazorProjectInfo>(resourceBytes, options);

// Assert
Assert.NotNull(actualProjectInfo);
Assert.NotNull(actualProjectInfo.DisplayName);
}

private static RazorProjectInfo DeserializeProjectInfoFromJsonBytes(byte[] resourceBytes)
{
using var stream = new MemoryStream(resourceBytes);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
</ItemGroup>

<ItemGroup>
<EmbeddedResource Include="..\..\benchmarks\Microsoft.AspNetCore.Razor.Microbenchmarks\Resources\project.razor.bin" Link="Resources\Benchmarking\project.razor.bin" />
<EmbeddedResource Include="..\..\benchmarks\Microsoft.AspNetCore.Razor.Microbenchmarks\Resources\project.razor.json" Link="Resources\Benchmarking\project.razor.json" />
<EmbeddedResource Include="..\..\benchmarks\Microsoft.AspNetCore.Razor.Microbenchmarks\Resources\taghelpers.json" Link="Resources\Benchmarking\taghelpers.json" />
<EmbeddedResource Include="..\..\benchmarks\Microsoft.AspNetCore.Razor.Microbenchmarks\Resources\Telerik\Kendo.Mvc.Examples.project.razor.json" Link="Resources\Benchmarking\Kendo.Mvc.Examples.project.razor.json" />
Expand Down

0 comments on commit 3fe8231

Please sign in to comment.