Skip to content

Commit debfd49

Browse files
Added tests for ConstantSourceNode.
1 parent 927d224 commit debfd49

File tree

2 files changed

+29
-1
lines changed

2 files changed

+29
-1
lines changed

src/KristofferStrube.Blazor.WebAudio/Options/ConstantSourceOptions.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@ public class ConstantSourceOptions
1111
/// <summary>
1212
/// The initial value for the <see cref="ConstantSourceNode.GetOffsetAsync"/> <see cref="AudioParam"/> of this node.
1313
/// </summary>
14+
/// <remarks>
15+
/// The default value is <c>1</c>.
16+
/// </remarks>
1417
[JsonPropertyName("offset")]
1518
public float Offset { get; set; } = 1;
1619
}
Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,34 @@
1-
namespace IntegrationTests.AudioNodeTests;
1+
using FluentAssertions;
2+
3+
namespace IntegrationTests.AudioNodeTests;
24

35
public class ConstantSourceNodeTest : AudioNodeTest<ConstantSourceNode>
46
{
57
public override async Task<ConstantSourceNode> GetDefaultInstanceAsync()
68
{
79
return await ConstantSourceNode.CreateAsync(JSRuntime, AudioContext);
810
}
11+
12+
[Test]
13+
[TestCase(1)]
14+
[TestCase(-0.5f)]
15+
public async Task GetOffsetAsync_ShouldRetrieveOffsetParameter(float offset)
16+
{
17+
// Arrange
18+
await using ConstantSourceNode node = await ConstantSourceNode.CreateAsync(JSRuntime, AudioContext, new()
19+
{
20+
Offset = offset
21+
});
22+
23+
// Act
24+
await using AudioParam offsetParameter = await node.GetOffsetAsync();
25+
26+
// Assert
27+
float readOffset = await offsetParameter.GetValueAsync();
28+
_ = readOffset.Should().Be(offset);
29+
30+
await offsetParameter.SetValueAsync(offset + 1);
31+
readOffset = await offsetParameter.GetValueAsync();
32+
_ = readOffset.Should().Be(offset + 1);
33+
}
934
}

0 commit comments

Comments
 (0)