From 80f7871dbe1b26d30be1571f0842859116e8b3ae Mon Sep 17 00:00:00 2001
From: Andrew Leader <aleader@microsoft.com>
Date: Fri, 12 Feb 2021 12:59:45 -0800
Subject: [PATCH 1/2] Fix ms-winsoundevent

---
 .../Toasts/Builder/ToastContentBuilder.cs     |  2 +-
 .../TestToastContentBuilder.cs                | 39 +++++++++++++++++++
 2 files changed, 40 insertions(+), 1 deletion(-)

diff --git a/Microsoft.Toolkit.Uwp.Notifications/Toasts/Builder/ToastContentBuilder.cs b/Microsoft.Toolkit.Uwp.Notifications/Toasts/Builder/ToastContentBuilder.cs
index 0850a1b013d..7356aff8d11 100644
--- a/Microsoft.Toolkit.Uwp.Notifications/Toasts/Builder/ToastContentBuilder.cs
+++ b/Microsoft.Toolkit.Uwp.Notifications/Toasts/Builder/ToastContentBuilder.cs
@@ -355,7 +355,7 @@ public ToastContentBuilder AddAudio(
             bool? silent = default)
 #endif
         {
-            if (!src.IsFile)
+            if (!src.IsFile && src.Scheme != "ms-winsoundevent")
             {
                 throw new ArgumentException(nameof(src), "Audio Source has to be a file.");
             }
diff --git a/UnitTests/UnitTests.Notifications.Shared/TestToastContentBuilder.cs b/UnitTests/UnitTests.Notifications.Shared/TestToastContentBuilder.cs
index 21546d2e966..f03b598e45e 100644
--- a/UnitTests/UnitTests.Notifications.Shared/TestToastContentBuilder.cs
+++ b/UnitTests/UnitTests.Notifications.Shared/TestToastContentBuilder.cs
@@ -548,6 +548,45 @@ public void AddAudioTest_WithFullArgs_ReturnSelfWithCustomAudioAddedWithAllOptio
             Assert.AreEqual(testToastAudioSilent, builder.Content.Audio.Silent);
         }
 
+        [TestMethod]
+        public void AddAudioTest_WithMsWinSoundEvent_ReturnSelfWithCustomAudioAdded()
+        {
+            // Arrange
+            Uri testAudioUriSrc = new Uri("ms-winsoundevent:Notification.Reminder");
+
+            // Act
+            ToastContentBuilder builder = new ToastContentBuilder();
+            ToastContentBuilder anotherReference = builder.AddAudio(testAudioUriSrc);
+
+            // Assert
+            Assert.AreSame(builder, anotherReference);
+            Assert.AreEqual(testAudioUriSrc.OriginalString, builder.Content.Audio.Src.OriginalString);
+        }
+
+        [TestMethod]
+        [ExpectedException(typeof(ArgumentException))]
+        public void AddAudioTest_WithInvalidMsUri_ThrowException()
+        {
+            // Arrange
+            Uri testAudioUriSrc = new Uri("ms-doesntexist:Notification.Reminder");
+
+            // Act
+            ToastContentBuilder builder = new ToastContentBuilder();
+            builder.AddAudio(testAudioUriSrc);
+        }
+
+        [TestMethod]
+        [ExpectedException(typeof(ArgumentException))]
+        public void AddAudioTest_WithInvalidHttpUri_ThrowException()
+        {
+            // Arrange
+            Uri testAudioUriSrc = new Uri("https://myaudio.com/song.mp3");
+
+            // Act
+            ToastContentBuilder builder = new ToastContentBuilder();
+            builder.AddAudio(testAudioUriSrc);
+        }
+
         [TestMethod]
         public void AddAudioTest_WithAudioObject_ReturnSelfWithCustomAudioAdded()
         {

From 5704eae3d8a899d5f7764ca35ee003e3fa0ee901 Mon Sep 17 00:00:00 2001
From: Andrew Leader <aleader@microsoft.com>
Date: Fri, 12 Feb 2021 13:35:13 -0800
Subject: [PATCH 2/2] Support ms-appx audio

---
 .../Toasts/Builder/ToastContentBuilder.cs     | 20 ++++++------
 .../TestToastContentBuilder.cs                | 31 +++++++++++++++++--
 2 files changed, 39 insertions(+), 12 deletions(-)

diff --git a/Microsoft.Toolkit.Uwp.Notifications/Toasts/Builder/ToastContentBuilder.cs b/Microsoft.Toolkit.Uwp.Notifications/Toasts/Builder/ToastContentBuilder.cs
index 7356aff8d11..b3d3964dfd4 100644
--- a/Microsoft.Toolkit.Uwp.Notifications/Toasts/Builder/ToastContentBuilder.cs
+++ b/Microsoft.Toolkit.Uwp.Notifications/Toasts/Builder/ToastContentBuilder.cs
@@ -355,25 +355,20 @@ public ToastContentBuilder AddAudio(
             bool? silent = default)
 #endif
         {
-            if (!src.IsFile && src.Scheme != "ms-winsoundevent")
-            {
-                throw new ArgumentException(nameof(src), "Audio Source has to be a file.");
-            }
-
-            Content.Audio = new ToastAudio();
-            Content.Audio.Src = src;
+            var audio = new ToastAudio();
+            audio.Src = src;
 
             if (loop != default)
             {
-                Content.Audio.Loop = loop.Value;
+                audio.Loop = loop.Value;
             }
 
             if (silent != default)
             {
-                Content.Audio.Silent = silent.Value;
+                audio.Silent = silent.Value;
             }
 
-            return this;
+            return AddAudio(audio);
         }
 
         /// <summary>
@@ -383,6 +378,11 @@ public ToastContentBuilder AddAudio(
         /// <returns>The current instance of <see cref="ToastContentBuilder"/></returns>
         public ToastContentBuilder AddAudio(ToastAudio audio)
         {
+            if (audio.Src != null && !audio.Src.IsFile && audio.Src.Scheme != "ms-appx" && audio.Src.Scheme != "ms-winsoundevent")
+            {
+                throw new InvalidOperationException("Audio Source must either be a ms-appx file, absolute file, or ms-winsoundevent.");
+            }
+
             Content.Audio = audio;
             return this;
         }
diff --git a/UnitTests/UnitTests.Notifications.Shared/TestToastContentBuilder.cs b/UnitTests/UnitTests.Notifications.Shared/TestToastContentBuilder.cs
index f03b598e45e..ad35cea5d2a 100644
--- a/UnitTests/UnitTests.Notifications.Shared/TestToastContentBuilder.cs
+++ b/UnitTests/UnitTests.Notifications.Shared/TestToastContentBuilder.cs
@@ -564,7 +564,22 @@ public void AddAudioTest_WithMsWinSoundEvent_ReturnSelfWithCustomAudioAdded()
         }
 
         [TestMethod]
-        [ExpectedException(typeof(ArgumentException))]
+        public void AddAudioTest_WithMsAppx_ReturnSelfWithCustomAudioAdded()
+        {
+            // Arrange
+            Uri testAudioUriSrc = new Uri("ms-appx:///Assets/Audio.mp3");
+
+            // Act
+            ToastContentBuilder builder = new ToastContentBuilder();
+            ToastContentBuilder anotherReference = builder.AddAudio(testAudioUriSrc);
+
+            // Assert
+            Assert.AreSame(builder, anotherReference);
+            Assert.AreEqual(testAudioUriSrc.OriginalString, builder.Content.Audio.Src.OriginalString);
+        }
+
+        [TestMethod]
+        [ExpectedException(typeof(InvalidOperationException))]
         public void AddAudioTest_WithInvalidMsUri_ThrowException()
         {
             // Arrange
@@ -576,7 +591,19 @@ public void AddAudioTest_WithInvalidMsUri_ThrowException()
         }
 
         [TestMethod]
-        [ExpectedException(typeof(ArgumentException))]
+        [ExpectedException(typeof(InvalidOperationException))]
+        public void AddAudioTest_WithInvalidAppDataUri_ThrowException()
+        {
+            // Arrange (ms-appdata isn't currently supported)
+            Uri testAudioUriSrc = new Uri("ms-appdata:///local/Sound.mp3");
+
+            // Act
+            ToastContentBuilder builder = new ToastContentBuilder();
+            builder.AddAudio(testAudioUriSrc);
+        }
+
+        [TestMethod]
+        [ExpectedException(typeof(InvalidOperationException))]
         public void AddAudioTest_WithInvalidHttpUri_ThrowException()
         {
             // Arrange
