Skip to content

Commit b91ea33

Browse files
committed
test: 更新单元测试
1 parent fcf6a9a commit b91ea33

File tree

2 files changed

+25
-4
lines changed

2 files changed

+25
-4
lines changed

src/BootstrapBlazor/Extensions/DownloadServiceExtensions.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ public static async Task DownloadFolderAsync(this DownloadService download, stri
4949
var destZipFile = $"{directoryName}.zip";
5050
ZipFile.CreateFromDirectory(folder, destZipFile);
5151

52-
using var stream = new FileStream(destZipFile, FileMode.Open);
52+
await using var stream = new FileStream(destZipFile, FileMode.Open);
5353
await download.DownloadFromStreamAsync(new DownloadOption() { FileName = downloadFileName, FileStream = stream });
5454
}
5555

test/UnitTest/Components/DownloadTest.cs

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@
33
// See the LICENSE file in the project root for more information.
44
// Maintainer: Argo Zhang([email protected]) Website: https://www.blazor.zone
55

6-
using Microsoft.JSInterop;
7-
86
namespace UnitTest.Components;
97

108
public class DownloadTest : BootstrapBlazorTestBase
@@ -96,6 +94,18 @@ public async Task DownloadFromStreamAsync_Null()
9694
});
9795
var btn = cut.Find("button");
9896
await Assert.ThrowsAsync<InvalidOperationException>(() => cut.InvokeAsync(() => btn.Click()));
97+
98+
var trigger = cut.FindComponent<Button>();
99+
trigger.SetParametersAndRender(pb =>
100+
{
101+
pb.Add(a => a.OnClick, async () =>
102+
{
103+
var stream = new MemoryStream();
104+
await downloadService.DownloadFromStreamAsync("", stream);
105+
});
106+
});
107+
btn = cut.Find("button");
108+
await Assert.ThrowsAsync<InvalidOperationException>(() => cut.InvokeAsync(() => btn.Click()));
99109
}
100110

101111
[Fact]
@@ -131,7 +141,7 @@ public async Task DownloadFolderAsync_Ok()
131141
{
132142
File.Delete(zipFile);
133143
}
134-
using var fs = File.Create(fileName);
144+
await using var fs = File.Create(fileName);
135145
fs.Close();
136146
btn = cut.Find("button");
137147
await cut.InvokeAsync(() => btn.Click());
@@ -175,5 +185,16 @@ public async Task DownloadFromUrlAsync_Null()
175185
});
176186
var btn = cut.Find("button");
177187
await Assert.ThrowsAsync<InvalidOperationException>(() => cut.InvokeAsync(() => btn.Click()));
188+
189+
var trigger = cut.FindComponent<Button>();
190+
trigger.SetParametersAndRender(pb =>
191+
{
192+
pb.Add(a => a.OnClick, async () =>
193+
{
194+
await downloadService.DownloadFromUrlAsync("", "./favicon.png");
195+
});
196+
});
197+
btn = cut.Find("button");
198+
await Assert.ThrowsAsync<InvalidOperationException>(() => cut.InvokeAsync(() => btn.Click()));
178199
}
179200
}

0 commit comments

Comments
 (0)