You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
var preview = await file.RequestImageFileAsync("image/png", 100, 100);
44
+
await using var stream = preview.OpenReadStream();
45
+
var buffer = new byte[stream.Length];
46
+
await using var memoryStream = new MemoryStream(buffer);
47
+
await stream.CopyToAsync(memoryStream);
48
+
var base64 = Convert.ToBase64String(buffer);
49
+
imageBase64 = $"data:image/png;base64,{base64}";
50
+
}
51
+
}
52
+
```
53
+
54
+
When using the `RequestImageFileAsync` method, the `UploadFiles` method will not be able to upload the file inside a test. Blazor has some internal checks, bUnit can not overcome easily. So the following test will fail:
cut.Find("img").GetAttribute("src").Should().NotBeNullOrEmpty(); // Will fail
65
+
Renderer.UnhandledException.Should().BeNull(); // Will fail
66
+
}
67
+
```
68
+
69
+
To work around this limitation, refactoring the logic into a service that is injected into the component and then mocking the service in the test is a possible solution.
0 commit comments