|
3 | 3 | // See the LICENSE file in the project root for more information. |
4 | 4 | // Maintainer: Argo Zhang([email protected]) Website: https://www.blazor.zone |
5 | 5 |
|
6 | | -using Microsoft.JSInterop; |
7 | | - |
8 | 6 | namespace UnitTest.Components; |
9 | 7 |
|
10 | 8 | public class DownloadTest : BootstrapBlazorTestBase |
@@ -96,6 +94,18 @@ public async Task DownloadFromStreamAsync_Null() |
96 | 94 | }); |
97 | 95 | var btn = cut.Find("button"); |
98 | 96 | 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())); |
99 | 109 | } |
100 | 110 |
|
101 | 111 | [Fact] |
@@ -131,7 +141,7 @@ public async Task DownloadFolderAsync_Ok() |
131 | 141 | { |
132 | 142 | File.Delete(zipFile); |
133 | 143 | } |
134 | | - using var fs = File.Create(fileName); |
| 144 | + await using var fs = File.Create(fileName); |
135 | 145 | fs.Close(); |
136 | 146 | btn = cut.Find("button"); |
137 | 147 | await cut.InvokeAsync(() => btn.Click()); |
@@ -175,5 +185,16 @@ public async Task DownloadFromUrlAsync_Null() |
175 | 185 | }); |
176 | 186 | var btn = cut.Find("button"); |
177 | 187 | 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())); |
178 | 199 | } |
179 | 200 | } |
0 commit comments