Skip to content

Commit ea65373

Browse files
committed
test: 增加单元测试
1 parent 885651e commit ea65373

File tree

6 files changed

+80
-48
lines changed

6 files changed

+80
-48
lines changed

src/BootstrapBlazor/Services/MediaDevices/DefaultVideoDevice.cs

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -37,16 +37,6 @@ public Task Capture()
3737
return deviceService.Capture();
3838
}
3939

40-
public Task Preview()
41-
{
42-
throw new NotImplementedException();
43-
}
44-
45-
public Task<Stream?> GetPreviewImage()
46-
{
47-
throw new NotImplementedException();
48-
}
49-
5040
public Task<string?> GetPreviewUrl()
5141
{
5242
return deviceService.GetPreviewUrl();

src/BootstrapBlazor/Services/MediaDevices/DisplayMediaOptions.cs

Lines changed: 0 additions & 13 deletions
This file was deleted.

src/BootstrapBlazor/Services/MediaDevices/IVideoDevice.cs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -36,17 +36,17 @@ public interface IVideoDevice
3636
/// <returns></returns>
3737
Task Capture();
3838

39-
/// <summary>
40-
/// Preview a still image from the video stream.
41-
/// </summary>
42-
/// <returns></returns>
43-
Task Preview();
44-
45-
/// <summary>
46-
/// Gets the stream of the captured image.
47-
/// </summary>
48-
/// <returns></returns>
49-
Task<Stream?> GetPreviewImage();
39+
///// <summary>
40+
///// Preview a still image from the video stream.
41+
///// </summary>
42+
///// <returns></returns>
43+
//Task Preview();
44+
45+
///// <summary>
46+
///// Gets the stream of the captured image.
47+
///// </summary>
48+
///// <returns></returns>
49+
//Task<Stream?> GetPreviewImage();
5050

5151
/// <summary>
5252
/// Gets the preview URL of the captured image.

src/BootstrapBlazor/Services/MediaDevices/MediaDeviceInfo.cs

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,28 @@
55

66
namespace BootstrapBlazor.Components;
77

8-
class MediaDeviceInfo : IMediaDeviceInfo
8+
/// <summary>
9+
/// <inheritdoc/>
10+
/// </summary>
11+
public class MediaDeviceInfo : IMediaDeviceInfo
912
{
13+
/// <summary>
14+
/// <inheritdoc/>
15+
/// </summary>
1016
public string DeviceId { get; set; } = "";
1117

18+
/// <summary>
19+
/// <inheritdoc/>
20+
/// </summary>
1221
public string GroupId { get; set; } = "";
1322

23+
/// <summary>
24+
/// <inheritdoc/>
25+
/// </summary>
1426
public string Kind { get; set; } = "";
1527

28+
/// <summary>
29+
/// <inheritdoc/>
30+
/// </summary>
1631
public string Label { get; set; } = "";
1732
}

src/BootstrapBlazor/Services/MediaDevices/MediaStream.cs

Lines changed: 0 additions & 13 deletions
This file was deleted.
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the Apache 2.0 License
3+
// See the LICENSE file in the project root for more information.
4+
// Maintainer: Argo Zhang([email protected]) Website: https://www.blazor.zone
5+
6+
namespace UnitTest.Services;
7+
8+
public class VideoDeviceTest : BootstrapBlazorTestBase
9+
{
10+
[Fact]
11+
public async Task GetDevices_Ok()
12+
{
13+
Context.JSInterop.Setup<List<MediaDeviceInfo>>("enumerateDevices").SetResult([
14+
new() { DeviceId = "test-device-id", GroupId = "test-groupd-id", Kind = "videoinput", Label="test-video" }
15+
]);
16+
var service = Context.Services.GetRequiredService<IVideoDevice>();
17+
var devices = await service.GetDevices();
18+
Assert.NotNull(devices);
19+
Assert.Equal("test-device-id", devices[0].DeviceId);
20+
Assert.Equal("test-groupd-id", devices[0].GroupId);
21+
Assert.Equal("videoinput", devices[0].Kind);
22+
Assert.Equal("test-video", devices[0].Label);
23+
}
24+
25+
[Fact]
26+
public async Task Open_Ok()
27+
{
28+
Context.JSInterop.Setup<string?>("getPreviewUrl").SetResult("blob:https://test-preview");
29+
30+
var service = Context.Services.GetRequiredService<IVideoDevice>();
31+
var options = new MediaTrackConstraints()
32+
{
33+
DeviceId = "test-device-id",
34+
FacingMode = "user",
35+
Height = 640,
36+
Width = 480,
37+
VideoSelector = ".bb-video"
38+
};
39+
await service.Open(options);
40+
await service.Close(".bb-video");
41+
42+
Assert.Equal("test-device-id", options.DeviceId);
43+
Assert.Equal("user", options.FacingMode);
44+
Assert.Equal(640, options.Height);
45+
Assert.Equal(480, options.Width);
46+
Assert.Equal(".bb-video", options.VideoSelector);
47+
48+
await service.Capture();
49+
await service.Flip();
50+
var url = await service.GetPreviewUrl();
51+
Assert.Equal("blob:https://test-preview", url);
52+
}
53+
}

0 commit comments

Comments
 (0)