Skip to content

Commit 80f7871

Browse files
committed
Fix ms-winsoundevent
1 parent e407e07 commit 80f7871

File tree

2 files changed

+40
-1
lines changed

2 files changed

+40
-1
lines changed

Microsoft.Toolkit.Uwp.Notifications/Toasts/Builder/ToastContentBuilder.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -355,7 +355,7 @@ public ToastContentBuilder AddAudio(
355355
bool? silent = default)
356356
#endif
357357
{
358-
if (!src.IsFile)
358+
if (!src.IsFile && src.Scheme != "ms-winsoundevent")
359359
{
360360
throw new ArgumentException(nameof(src), "Audio Source has to be a file.");
361361
}

UnitTests/UnitTests.Notifications.Shared/TestToastContentBuilder.cs

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -548,6 +548,45 @@ public void AddAudioTest_WithFullArgs_ReturnSelfWithCustomAudioAddedWithAllOptio
548548
Assert.AreEqual(testToastAudioSilent, builder.Content.Audio.Silent);
549549
}
550550

551+
[TestMethod]
552+
public void AddAudioTest_WithMsWinSoundEvent_ReturnSelfWithCustomAudioAdded()
553+
{
554+
// Arrange
555+
Uri testAudioUriSrc = new Uri("ms-winsoundevent:Notification.Reminder");
556+
557+
// Act
558+
ToastContentBuilder builder = new ToastContentBuilder();
559+
ToastContentBuilder anotherReference = builder.AddAudio(testAudioUriSrc);
560+
561+
// Assert
562+
Assert.AreSame(builder, anotherReference);
563+
Assert.AreEqual(testAudioUriSrc.OriginalString, builder.Content.Audio.Src.OriginalString);
564+
}
565+
566+
[TestMethod]
567+
[ExpectedException(typeof(ArgumentException))]
568+
public void AddAudioTest_WithInvalidMsUri_ThrowException()
569+
{
570+
// Arrange
571+
Uri testAudioUriSrc = new Uri("ms-doesntexist:Notification.Reminder");
572+
573+
// Act
574+
ToastContentBuilder builder = new ToastContentBuilder();
575+
builder.AddAudio(testAudioUriSrc);
576+
}
577+
578+
[TestMethod]
579+
[ExpectedException(typeof(ArgumentException))]
580+
public void AddAudioTest_WithInvalidHttpUri_ThrowException()
581+
{
582+
// Arrange
583+
Uri testAudioUriSrc = new Uri("https://myaudio.com/song.mp3");
584+
585+
// Act
586+
ToastContentBuilder builder = new ToastContentBuilder();
587+
builder.AddAudio(testAudioUriSrc);
588+
}
589+
551590
[TestMethod]
552591
public void AddAudioTest_WithAudioObject_ReturnSelfWithCustomAudioAdded()
553592
{

0 commit comments

Comments
 (0)