1
1
using FluentAssertions ;
2
+ using FluentAssertions . Specialized ;
3
+ using KristofferStrube . Blazor . WebIDL . Exceptions ;
2
4
using Microsoft . JSInterop ;
3
5
4
6
namespace IntegrationTests . AudioNodeTests ;
@@ -9,71 +11,46 @@ namespace IntegrationTests.AudioNodeTests;
9
11
10
12
public override async Task < TAudioNode > GetDefaultInstanceAsync ( )
11
13
{
12
- return await CreateAsync ( EvaluationContext . JSRuntime , await EvaluationContext . GetAudioContext ( ) , null ) ;
14
+ return await CreateAsync ( EvaluationContext . JSRuntime , await GetAudioContextAsync ( ) , null ) ;
13
15
}
14
16
15
17
[ Test ]
16
18
public async Task CreateAsync_WithEmptyOptions_Succeeds ( )
17
19
{
18
- // Arrange
19
- AfterRenderAsync = async ( ) =>
20
- {
21
- return await CreateAsync ( EvaluationContext . JSRuntime , await EvaluationContext . GetAudioContext ( ) , new TAudioNodeOptions ( ) ) ;
22
- } ;
23
-
24
20
// Act
25
- await OnAfterRerenderAsync ( ) ;
21
+ await using TAudioNode node = await CreateAsync ( EvaluationContext . JSRuntime , await GetAudioContextAsync ( ) , new TAudioNodeOptions ( ) ) ;
26
22
27
23
// Assert
28
- _ = EvaluationContext . Exception . Should ( ) . BeNull ( ) ;
29
- _ = EvaluationContext . Result . Should ( ) . BeOfType < TAudioNode > ( ) ;
24
+ _ = node . Should ( ) . BeOfType < TAudioNode > ( ) ;
30
25
}
31
26
32
27
[ Test ]
33
28
public async Task CreateAsync_WithEmptyOptions_HasSameChannelCountModeAsWhenNoOptionsAreUsed ( )
34
29
{
35
30
// Arrange
36
- AfterRenderAsync = async ( ) =>
37
- {
38
- await using TAudioNode emptyOptionsNode = await CreateAsync ( EvaluationContext . JSRuntime , await EvaluationContext . GetAudioContext ( ) , new TAudioNodeOptions ( ) ) ;
39
- await using TAudioNode noOptionsNode = await CreateAsync ( EvaluationContext . JSRuntime , await EvaluationContext . GetAudioContext ( ) , null ) ;
40
-
41
- ChannelCountMode emptyOptionsCountMode = await emptyOptionsNode . GetChannelCountModeAsync ( ) ;
42
- ChannelCountMode noOptionsCountMode = await noOptionsNode . GetChannelCountModeAsync ( ) ;
43
-
44
- return ( emptyOptionsCountMode , noOptionsCountMode ) ;
45
- } ;
31
+ await using TAudioNode emptyOptionsNode = await CreateAsync ( EvaluationContext . JSRuntime , await GetAudioContextAsync ( ) , new TAudioNodeOptions ( ) ) ;
32
+ await using TAudioNode noOptionsNode = await CreateAsync ( EvaluationContext . JSRuntime , await GetAudioContextAsync ( ) , null ) ;
46
33
47
34
// Act
48
- await OnAfterRerenderAsync ( ) ;
35
+ ChannelCountMode emptyOptionsCountMode = await emptyOptionsNode . GetChannelCountModeAsync ( ) ;
36
+ ChannelCountMode noOptionsCountMode = await noOptionsNode . GetChannelCountModeAsync ( ) ;
49
37
50
38
// Assert
51
- _ = EvaluationContext . Exception . Should ( ) . BeNull ( ) ;
52
- ( ChannelCountMode emptyOptionsCountMode , ChannelCountMode noOptionsCountMode ) = EvaluationContext . Result . Should ( ) . BeOfType < ( ChannelCountMode , ChannelCountMode ) > ( ) . Subject ;
53
39
_ = emptyOptionsCountMode . Should ( ) . Be ( noOptionsCountMode ) ;
54
40
}
55
41
56
42
[ Test ]
57
43
public async Task CreateAsync_WithEmptyOptions_HasSameChannelInterpretationAsWhenNoOptionsAreUsed ( )
58
44
{
59
45
// Arrange
60
- AfterRenderAsync = async ( ) =>
61
- {
62
- await using TAudioNode emptyOptionsNode = await CreateAsync ( EvaluationContext . JSRuntime , await EvaluationContext . GetAudioContext ( ) , new TAudioNodeOptions ( ) ) ;
63
- await using TAudioNode noOptionsNode = await CreateAsync ( EvaluationContext . JSRuntime , await EvaluationContext . GetAudioContext ( ) , null ) ;
64
-
65
- ChannelInterpretation emptyOptionsChannelInterpretation = await emptyOptionsNode . GetChannelInterpretationAsync ( ) ;
66
- ChannelInterpretation noOptionsChannelInterpretation = await noOptionsNode . GetChannelInterpretationAsync ( ) ;
67
-
68
- return ( emptyOptionsChannelInterpretation , noOptionsChannelInterpretation ) ;
69
- } ;
46
+ await using TAudioNode emptyOptionsNode = await CreateAsync ( EvaluationContext . JSRuntime , await GetAudioContextAsync ( ) , new TAudioNodeOptions ( ) ) ;
47
+ await using TAudioNode noOptionsNode = await CreateAsync ( EvaluationContext . JSRuntime , await GetAudioContextAsync ( ) , null ) ;
70
48
71
49
// Act
72
- await OnAfterRerenderAsync ( ) ;
50
+ ChannelInterpretation emptyOptionsChannelInterpretation = await emptyOptionsNode . GetChannelInterpretationAsync ( ) ;
51
+ ChannelInterpretation noOptionsChannelInterpretation = await noOptionsNode . GetChannelInterpretationAsync ( ) ;
73
52
74
53
// Assert
75
- _ = EvaluationContext . Exception . Should ( ) . BeNull ( ) ;
76
- ( ChannelInterpretation emptyOptionsChannelInterpretation , ChannelInterpretation noOptionsChannelInterpretation ) = EvaluationContext . Result . Should ( ) . BeOfType < ( ChannelInterpretation , ChannelInterpretation ) > ( ) . Subject ;
77
54
_ = emptyOptionsChannelInterpretation . Should ( ) . Be ( noOptionsChannelInterpretation ) ;
78
55
}
79
56
@@ -84,29 +61,25 @@ public async Task CreateAsync_WithEmptyOptions_HasSameChannelInterpretationAsWhe
84
61
public async Task CreateAsync_WithDifferentChannelCountModes_SetsChannelCountMode_ExceptForUnsupportedValues ( ChannelCountMode mode )
85
62
{
86
63
// Arrange
87
- AfterRenderAsync = async ( ) =>
88
- {
89
- TAudioNodeOptions options = new ( ) ;
90
- options . ChannelCountMode = mode ;
91
-
92
- await using TAudioNode node = await CreateAsync ( EvaluationContext . JSRuntime , await EvaluationContext . GetAudioContext ( ) , options ) ;
64
+ TAudioNodeOptions options = new ( ) ;
65
+ options . ChannelCountMode = mode ;
93
66
67
+ // Act
68
+ Func < Task < ChannelCountMode > > action = async ( ) =>
69
+ {
70
+ await using TAudioNode node = await CreateAsync ( EvaluationContext . JSRuntime , await GetAudioContextAsync ( ) , options ) ;
94
71
return await node . GetChannelCountModeAsync ( ) ;
95
72
} ;
96
73
97
- // Act
98
- await OnAfterRerenderAsync ( ) ;
99
-
100
74
// Assert
101
75
if ( UnsupportedChannelCountModes . TryGetValue ( mode , out Type ? exceptionType ) )
102
76
{
103
- _ = EvaluationContext . Result . Should ( ) . Be ( null ) ;
104
- _ = EvaluationContext . Exception . Should ( ) . BeOfType ( exceptionType ) ;
77
+ _ = ( await action . Should ( ) . ThrowAsync < WebIDLException > ( ) ) . And . Should ( ) . BeOfType ( exceptionType ) ;
105
78
}
106
79
else
107
80
{
108
- _ = EvaluationContext . Exception . Should ( ) . BeNull ( ) ;
109
- _ = EvaluationContext . Result . Should ( ) . Be ( mode ) ;
81
+ ChannelCountMode result = await action ( ) ;
82
+ _ = result . Should ( ) . Be ( mode ) ;
110
83
}
111
84
}
112
85
@@ -116,29 +89,26 @@ public async Task CreateAsync_WithDifferentChannelCountModes_SetsChannelCountMod
116
89
public async Task CreateAsync_WithDifferentChannelInterpretations_SetsChannelInterpretation_ExceptForUnsupportedValues ( ChannelInterpretation interpretation )
117
90
{
118
91
// Arrange
119
- AfterRenderAsync = async ( ) =>
120
- {
121
- TAudioNodeOptions options = new ( ) ;
122
- options . ChannelInterpretation = interpretation ;
123
-
124
- await using TAudioNode node = await CreateAsync ( EvaluationContext . JSRuntime , await EvaluationContext . GetAudioContext ( ) , options ) ;
92
+ TAudioNodeOptions options = new ( ) ;
93
+ options . ChannelInterpretation = interpretation ;
125
94
95
+ // Act
96
+ Func < Task < ChannelInterpretation > > action = async ( ) =>
97
+ {
98
+ await using TAudioNode node = await CreateAsync ( EvaluationContext . JSRuntime , await GetAudioContextAsync ( ) , options ) ;
126
99
return await node . GetChannelInterpretationAsync ( ) ;
127
100
} ;
128
101
129
- // Act
130
- await OnAfterRerenderAsync ( ) ;
131
-
132
102
// Assert
133
103
if ( UnsupportedChannelInterpretations . TryGetValue ( interpretation , out Type ? exceptionType ) )
134
104
{
135
- _ = EvaluationContext . Result . Should ( ) . Be ( null ) ;
136
- _ = EvaluationContext . Exception . Should ( ) . BeOfType ( exceptionType ) ;
105
+ _ = ( await action . Should ( ) . ThrowAsync < WebIDLException > ( ) ) . And . Should ( ) . BeOfType ( exceptionType ) ;
106
+
137
107
}
138
108
else
139
109
{
140
- _ = EvaluationContext . Exception . Should ( ) . BeNull ( ) ;
141
- _ = EvaluationContext . Result . Should ( ) . Be ( interpretation ) ;
110
+ ChannelInterpretation result = await action ( ) ;
111
+ _ = result . Should ( ) . Be ( interpretation ) ;
142
112
}
143
113
}
144
114
}
0 commit comments