|
1 | 1 | using FluentAssertions; |
2 | 2 | using KristofferStrube.Blazor.DOM; |
| 3 | +using KristofferStrube.Blazor.WebIDL.Exceptions; |
3 | 4 |
|
4 | 5 | namespace IntegrationTests.AudioNodeTests; |
5 | 6 |
|
@@ -341,4 +342,74 @@ public async Task StartAsync_WithOffsetParameter_StartsOffsetInBuffer(double off |
341 | 342 | _ = eventListenerTriggered.Should().BeTrue(); |
342 | 343 | await node.RemoveOnEndedEventListenerAsync(onEndedListener); |
343 | 344 | } |
| 345 | + |
| 346 | + [Test] |
| 347 | + public async Task StartAsync_ThrowsInvalidStateErrorException_WhenItHasAlreadyBeenStarted() |
| 348 | + { |
| 349 | + // Arrange |
| 350 | + await using AudioContext context = await AudioContext.CreateAsync(JSRuntime); |
| 351 | + |
| 352 | + await using AudioBuffer buffer = await AudioBuffer.CreateAsync(JSRuntime, new AudioBufferOptions() |
| 353 | + { |
| 354 | + SampleRate = 8000, |
| 355 | + Length = 1 |
| 356 | + }); |
| 357 | + await using AudioBufferSourceNode node = await AudioBufferSourceNode.CreateAsync(JSRuntime, context, new() |
| 358 | + { |
| 359 | + Buffer = buffer |
| 360 | + }); |
| 361 | + await node.StartAsync(); |
| 362 | + |
| 363 | + // Act |
| 364 | + Func<Task> action = async () => await node.StartAsync(); |
| 365 | + |
| 366 | + // Assert |
| 367 | + _ = await action.Should().ThrowAsync<InvalidStateErrorException>(); |
| 368 | + } |
| 369 | + |
| 370 | + [Test] |
| 371 | + public async Task StartAsync_WithNegativeOffset_ThrowsRangeErrorException() |
| 372 | + { |
| 373 | + // Arrange |
| 374 | + await using AudioContext context = await AudioContext.CreateAsync(JSRuntime); |
| 375 | + |
| 376 | + await using AudioBuffer buffer = await AudioBuffer.CreateAsync(JSRuntime, new AudioBufferOptions() |
| 377 | + { |
| 378 | + SampleRate = 8000, |
| 379 | + Length = 1 |
| 380 | + }); |
| 381 | + await using AudioBufferSourceNode node = await AudioBufferSourceNode.CreateAsync(JSRuntime, context, new() |
| 382 | + { |
| 383 | + Buffer = buffer |
| 384 | + }); |
| 385 | + |
| 386 | + // Act |
| 387 | + Func<Task> action = async () => await node.StartAsync(when: 0, offset: -1); |
| 388 | + |
| 389 | + // Assert |
| 390 | + _ = await action.Should().ThrowAsync<RangeErrorException>(); |
| 391 | + } |
| 392 | + |
| 393 | + [Test] |
| 394 | + public async Task StartAsync_WithNegativeDuration_ThrowsRangeErrorException() |
| 395 | + { |
| 396 | + // Arrange |
| 397 | + await using AudioContext context = await AudioContext.CreateAsync(JSRuntime); |
| 398 | + |
| 399 | + await using AudioBuffer buffer = await AudioBuffer.CreateAsync(JSRuntime, new AudioBufferOptions() |
| 400 | + { |
| 401 | + SampleRate = 8000, |
| 402 | + Length = 1 |
| 403 | + }); |
| 404 | + await using AudioBufferSourceNode node = await AudioBufferSourceNode.CreateAsync(JSRuntime, context, new() |
| 405 | + { |
| 406 | + Buffer = buffer |
| 407 | + }); |
| 408 | + |
| 409 | + // Act |
| 410 | + Func<Task> action = async () => await node.StartAsync(when: 0, offset: 0, duration: -1); |
| 411 | + |
| 412 | + // Assert |
| 413 | + _ = await action.Should().ThrowAsync<RangeErrorException>(); |
| 414 | + } |
344 | 415 | } |
0 commit comments