Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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
2 changes: 1 addition & 1 deletion Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
<!-- Shared code analyzers used for all projects in the solution -->
<ItemGroup Label="Code Analyzers">
<PackageReference Include="AsyncFixer" Version="1.6.0" PrivateAssets="All" />
<PackageReference Include="SonarAnalyzer.CSharp" Version="9.26.0.92422" PrivateAssets="All" />
<PackageReference Include="SonarAnalyzer.CSharp" Version="9.29.0.95321" PrivateAssets="All" />
</ItemGroup>

<ItemGroup Label="Implicit usings"
Expand Down
2 changes: 1 addition & 1 deletion docs/samples/tests/Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
</PropertyGroup>

<ItemGroup Condition="'$(TargetFramework)' == 'net6.0' OR '$(TargetFramework)' == 'net7.0' OR '$(TargetFramework)' == 'net8.0'">
<PackageReference Include="System.Text.Json" Version="8.0.0" />
<PackageReference Include="System.Text.Json" Version="8.0.4" />
</ItemGroup>

<ItemGroup Condition="'$(TargetFramework)' == 'net9.0'">
Expand Down
2 changes: 1 addition & 1 deletion docs/samples/tests/razor/bunit.docs.razor.samples.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<PackageReference Include="Moq" Version="4.16.1" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.0.0" />
<PackageReference Include="NSubstitute" Version="4.2.2" />
<PackageReference Include="xunit" Version="2.8.1" />
<PackageReference Include="xunit" Version="2.9.0" />
<!-- DO NOT UPGRADE TO versions > 2.4.5 as they do not support .net5 or older -->
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.5">
<PrivateAssets>all</PrivateAssets>
Expand Down
2 changes: 1 addition & 1 deletion docs/samples/tests/xunit/bunit.docs.xunit.samples.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<PackageReference Include="Moq" Version="4.16.1" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.0.0" />
<PackageReference Include="NSubstitute" Version="4.2.2" />
<PackageReference Include="xunit" Version="2.8.1" />
<PackageReference Include="xunit" Version="2.9.0" />
<!-- DO NOT UPGRADE TO versions > 2.4.5 as they do not support .net5 or older -->
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.5">
<PrivateAssets>all</PrivateAssets>
Expand Down
2 changes: 1 addition & 1 deletion src/bunit.template/template/Company.BlazorTests1.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
</ItemGroup>

<ItemGroup Condition="'$(testFramework_xunit)' == 'true'">
<PackageReference Include="xunit" Version="2.8.1" />
<PackageReference Include="xunit" Version="2.9.0" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.5.4">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
Expand Down
7 changes: 6 additions & 1 deletion src/bunit.web/Extensions/InputFile/BUnitBrowserFile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,12 @@ public BUnitBrowserFile(

public Stream OpenReadStream(long maxAllowedSize = 512000, CancellationToken cancellationToken = default)
{
if (Size > maxAllowedSize)
{
throw new IOException($"Supplied file with size {Size} bytes exceeds the maximum of {maxAllowedSize} bytes.");
}

return new MemoryStream(Content);
}
}
#endif
#endif
8 changes: 7 additions & 1 deletion src/bunit.web/Extensions/InputFile/InputFileExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#if NET5_0_OR_GREATER
using System.Runtime.ExceptionServices;
using Microsoft.AspNetCore.Components.Forms;

namespace Bunit;
Expand Down Expand Up @@ -36,6 +37,11 @@ public static void UploadFiles(
{
uploadTask.GetAwaiter().GetResult();
}

if (uploadTask.Exception is { InnerException: not null } e)
{
ExceptionDispatchInfo.Capture(e.InnerException).Throw();
}
}
}
#endif
#endif
2 changes: 1 addition & 1 deletion tests/bunit.core.tests/bunit.core.tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="xunit" Version="2.8.1" />
<PackageReference Include="xunit" Version="2.9.0" />
<!-- DO NOT UPGRADE TO versions > 2.4.5 as they do not support .net5 or older -->
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.5">
<PrivateAssets>all</PrivateAssets>
Expand Down
5 changes: 2 additions & 3 deletions tests/bunit.generators.tests/bunit.generators.tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.10.0" />
<PackageReference Include="System.Net.Http" Version="4.3.4" />
<PackageReference Include="System.Text.RegularExpressions" Version="4.3.1" />
<PackageReference Include="Verify.SourceGenerators" Version="2.2.0" />
<PackageReference Include="Verify.Xunit" Version="25.3.0" />
Expand All @@ -25,8 +24,8 @@
<PackageReference Update="Microsoft.CodeAnalysis.CSharp.Workspaces" Version="4.9.2" />
<PackageReference Update="Microsoft.CodeAnalysis.CSharp.SourceGenerators.Testing.XUnit" Version="1.1.1" />

<PackageReference Include="xunit" Version="2.8.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.5.6">
<PackageReference Include="xunit" Version="2.9.0" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.5">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
</PackageReference>
Expand Down
1 change: 0 additions & 1 deletion tests/bunit.testassets/_Imports.razor
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
@using System.Net.Http
@using Microsoft.AspNetCore.Components.Forms
@using Microsoft.AspNetCore.Components.Routing
@using Microsoft.AspNetCore.Components.Web
Expand Down
6 changes: 3 additions & 3 deletions tests/bunit.testassets/bunit.testassets.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,16 @@
<ItemGroup>
<PackageReference Include="Serilog" Version="4.0.0" />
<PackageReference Include="Serilog.Expressions" Version="4.0.0" />
<PackageReference Include="xunit.extensibility.execution" Version="2.8.1" />
<PackageReference Include="xunit.extensibility.execution" Version="2.9.0" />
<PackageReference Include="xunit.abstractions" Version="2.0.3" />
<PackageReference Include="xunit.assert" Version="2.8.1" />
<PackageReference Include="xunit.assert" Version="2.9.0" />
</ItemGroup>

<ItemGroup Condition="'$(TargetFramework)' == 'netstandard2.1'">
<PackageReference Include="Microsoft.Extensions.Localization.Abstractions" Version="$(DotNet3Version)" />
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly" Version="3.2.1" />
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.Authentication" Version="3.2.1" />
<PackageReference Include="System.Text.Json" Version="8.0.3" />
<PackageReference Include="System.Text.Json" Version="8.0.4" />
<PackageReference Include="Serilog.Extensions.Logging" Version="8.0.0" />
</ItemGroup>
<ItemGroup Condition="'$(TargetFramework)' == 'net5.0'">
Expand Down
2 changes: 1 addition & 1 deletion tests/bunit.web.query.tests/bunit.web.query.tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="xunit" Version="2.8.1" />
<PackageReference Include="xunit" Version="2.9.0" />
<!-- DO NOT UPGRADE TO versions > 2.4.5 as they do not support .net5 or older -->
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.5">
<PrivateAssets>all</PrivateAssets>
Expand Down
16 changes: 15 additions & 1 deletion tests/bunit.web.tests/Extensions/InputFile/InputFileTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -102,9 +102,23 @@ public void Test008()

act.ShouldNotThrow();
}

[Fact(DisplayName = "Uploading file exceeding the maximum file size will throw an exception")]
public void Test009()
{
var cut = RenderComponent<InputFileComponent>(ps => ps.Add(p => p.MaxFileSize, 512));
var file = InputFileContent.CreateFromText(new string('a', 513));

Action act = () => cut.FindComponent<InputFile>().UploadFiles(file);

act.ShouldThrow<IOException>();
}

private sealed class InputFileComponent : ComponentBase
{
[Parameter]
public long MaxFileSize { get; set; } = 512000;

public string? Filename { get; private set; }
public string? Content { get; private set; }
public DateTimeOffset? LastChanged { get; private set; }
Expand All @@ -127,7 +141,7 @@ private void OnChange(InputFileChangeEventArgs args)
Filename = file.Name;
LastChanged = file.LastModified;
Size = file.Size;
using var stream = new StreamReader(file.OpenReadStream());
using var stream = new StreamReader(file.OpenReadStream(MaxFileSize));
Content = stream.ReadToEnd();
}
}
Expand Down
2 changes: 1 addition & 1 deletion tests/bunit.web.tests/bunit.web.tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="xunit" Version="2.8.1" />
<PackageReference Include="xunit" Version="2.9.0" />
<!-- DO NOT UPGRADE TO versions > 2.4.5 as they do not support .net5 or older -->
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.5">
<PrivateAssets>all</PrivateAssets>
Expand Down