11using FluentAssertions ;
2+ using FluentAssertions . Specialized ;
3+ using KristofferStrube . Blazor . WebIDL . Exceptions ;
24using Microsoft . JSInterop ;
35
46namespace IntegrationTests . AudioNodeTests ;
@@ -9,71 +11,46 @@ namespace IntegrationTests.AudioNodeTests;
911
1012 public override async Task < TAudioNode > GetDefaultInstanceAsync ( )
1113 {
12- return await CreateAsync ( EvaluationContext . JSRuntime , await EvaluationContext . GetAudioContext ( ) , null ) ;
14+ return await CreateAsync ( EvaluationContext . JSRuntime , await GetAudioContextAsync ( ) , null ) ;
1315 }
1416
1517 [ Test ]
1618 public async Task CreateAsync_WithEmptyOptions_Succeeds ( )
1719 {
18- // Arrange
19- AfterRenderAsync = async ( ) =>
20- {
21- return await CreateAsync ( EvaluationContext . JSRuntime , await EvaluationContext . GetAudioContext ( ) , new TAudioNodeOptions ( ) ) ;
22- } ;
23-
2420 // Act
25- await OnAfterRerenderAsync ( ) ;
21+ await using TAudioNode node = await CreateAsync ( EvaluationContext . JSRuntime , await GetAudioContextAsync ( ) , new TAudioNodeOptions ( ) ) ;
2622
2723 // Assert
28- _ = EvaluationContext . Exception . Should ( ) . BeNull ( ) ;
29- _ = EvaluationContext . Result . Should ( ) . BeOfType < TAudioNode > ( ) ;
24+ _ = node . Should ( ) . BeOfType < TAudioNode > ( ) ;
3025 }
3126
3227 [ Test ]
3328 public async Task CreateAsync_WithEmptyOptions_HasSameChannelCountModeAsWhenNoOptionsAreUsed ( )
3429 {
3530 // 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 ) ;
4633
4734 // Act
48- await OnAfterRerenderAsync ( ) ;
35+ ChannelCountMode emptyOptionsCountMode = await emptyOptionsNode . GetChannelCountModeAsync ( ) ;
36+ ChannelCountMode noOptionsCountMode = await noOptionsNode . GetChannelCountModeAsync ( ) ;
4937
5038 // Assert
51- _ = EvaluationContext . Exception . Should ( ) . BeNull ( ) ;
52- ( ChannelCountMode emptyOptionsCountMode , ChannelCountMode noOptionsCountMode ) = EvaluationContext . Result . Should ( ) . BeOfType < ( ChannelCountMode , ChannelCountMode ) > ( ) . Subject ;
5339 _ = emptyOptionsCountMode . Should ( ) . Be ( noOptionsCountMode ) ;
5440 }
5541
5642 [ Test ]
5743 public async Task CreateAsync_WithEmptyOptions_HasSameChannelInterpretationAsWhenNoOptionsAreUsed ( )
5844 {
5945 // 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 ) ;
7048
7149 // Act
72- await OnAfterRerenderAsync ( ) ;
50+ ChannelInterpretation emptyOptionsChannelInterpretation = await emptyOptionsNode . GetChannelInterpretationAsync ( ) ;
51+ ChannelInterpretation noOptionsChannelInterpretation = await noOptionsNode . GetChannelInterpretationAsync ( ) ;
7352
7453 // Assert
75- _ = EvaluationContext . Exception . Should ( ) . BeNull ( ) ;
76- ( ChannelInterpretation emptyOptionsChannelInterpretation , ChannelInterpretation noOptionsChannelInterpretation ) = EvaluationContext . Result . Should ( ) . BeOfType < ( ChannelInterpretation , ChannelInterpretation ) > ( ) . Subject ;
7754 _ = emptyOptionsChannelInterpretation . Should ( ) . Be ( noOptionsChannelInterpretation ) ;
7855 }
7956
@@ -84,29 +61,25 @@ public async Task CreateAsync_WithEmptyOptions_HasSameChannelInterpretationAsWhe
8461 public async Task CreateAsync_WithDifferentChannelCountModes_SetsChannelCountMode_ExceptForUnsupportedValues ( ChannelCountMode mode )
8562 {
8663 // 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 ;
9366
67+ // Act
68+ Func < Task < ChannelCountMode > > action = async ( ) =>
69+ {
70+ await using TAudioNode node = await CreateAsync ( EvaluationContext . JSRuntime , await GetAudioContextAsync ( ) , options ) ;
9471 return await node . GetChannelCountModeAsync ( ) ;
9572 } ;
9673
97- // Act
98- await OnAfterRerenderAsync ( ) ;
99-
10074 // Assert
10175 if ( UnsupportedChannelCountModes . TryGetValue ( mode , out Type ? exceptionType ) )
10276 {
103- _ = EvaluationContext . Result . Should ( ) . Be ( null ) ;
104- _ = EvaluationContext . Exception . Should ( ) . BeOfType ( exceptionType ) ;
77+ _ = ( await action . Should ( ) . ThrowAsync < WebIDLException > ( ) ) . And . Should ( ) . BeOfType ( exceptionType ) ;
10578 }
10679 else
10780 {
108- _ = EvaluationContext . Exception . Should ( ) . BeNull ( ) ;
109- _ = EvaluationContext . Result . Should ( ) . Be ( mode ) ;
81+ ChannelCountMode result = await action ( ) ;
82+ _ = result . Should ( ) . Be ( mode ) ;
11083 }
11184 }
11285
@@ -116,29 +89,26 @@ public async Task CreateAsync_WithDifferentChannelCountModes_SetsChannelCountMod
11689 public async Task CreateAsync_WithDifferentChannelInterpretations_SetsChannelInterpretation_ExceptForUnsupportedValues ( ChannelInterpretation interpretation )
11790 {
11891 // 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 ;
12594
95+ // Act
96+ Func < Task < ChannelInterpretation > > action = async ( ) =>
97+ {
98+ await using TAudioNode node = await CreateAsync ( EvaluationContext . JSRuntime , await GetAudioContextAsync ( ) , options ) ;
12699 return await node . GetChannelInterpretationAsync ( ) ;
127100 } ;
128101
129- // Act
130- await OnAfterRerenderAsync ( ) ;
131-
132102 // Assert
133103 if ( UnsupportedChannelInterpretations . TryGetValue ( interpretation , out Type ? exceptionType ) )
134104 {
135- _ = EvaluationContext . Result . Should ( ) . Be ( null ) ;
136- _ = EvaluationContext . Exception . Should ( ) . BeOfType ( exceptionType ) ;
105+ _ = ( await action . Should ( ) . ThrowAsync < WebIDLException > ( ) ) . And . Should ( ) . BeOfType ( exceptionType ) ;
106+
137107 }
138108 else
139109 {
140- _ = EvaluationContext . Exception . Should ( ) . BeNull ( ) ;
141- _ = EvaluationContext . Result . Should ( ) . Be ( interpretation ) ;
110+ ChannelInterpretation result = await action ( ) ;
111+ _ = result . Should ( ) . Be ( interpretation ) ;
142112 }
143113 }
144114}
0 commit comments