Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove binary test #10639

Merged
merged 2 commits into from
Jul 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -125,66 +125,6 @@ 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. This can be achieved by calling GenerateProjectRazorBin below.
/// 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
RazorProjectInfo actualProjectInfo;
try
{
actualProjectInfo = MessagePackConvert.Deserialize<RazorProjectInfo>(resourceBytes, options);
}
catch (MessagePackSerializationException ex) when (ex.InnerException is RazorProjectInfoSerializationException)
{
Assert.Fail($"{typeof(MessagePackSerializationFormat).FullName}.{nameof(MessagePackSerializationFormat.Version)} has changed. Re-generate the project.razor.bin for this test.");
return;
}

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

#pragma warning disable IDE0051 // Remove unused private members
private void GenerateProjectRazorBin()
{
var resourceBytes = RazorTestResources.GetResourceBytes("project.razor.json", "Benchmarking");
var projectInfo = DeserializeProjectInfoFromJsonBytes(resourceBytes);

var options = MessagePackSerializerOptions.Standard
.WithResolver(CompositeResolver.Create(
RazorProjectInfoResolver.Instance,
StandardResolver.Instance));

var filePath = Assembly.GetExecutingAssembly().Location;
var binFilePath = Path.Combine(Path.GetDirectoryName(filePath).AssumeNotNull(), "project.razor.bin");

using (var stream = File.OpenWrite(binFilePath))
{
MessagePackSerializer.Serialize(stream, projectInfo, options);
}

Logger.LogInformation($"New project.razor.bin written to '{binFilePath}'");
}
#pragma warning restore IDE0051 // Remove unused private members

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,7 +21,6 @@
</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