File tree Expand file tree Collapse file tree 2 files changed +39
-12
lines changed
Microsoft.Toolkit.Uwp.Notifications/Toasts/Builder
UnitTests/UnitTests.Notifications.Shared Expand file tree Collapse file tree 2 files changed +39
-12
lines changed Original file line number Diff line number Diff line change @@ -355,25 +355,20 @@ public ToastContentBuilder AddAudio(
355
355
bool ? silent = default )
356
356
#endif
357
357
{
358
- if ( ! src . IsFile && src . Scheme != "ms-winsoundevent" )
359
- {
360
- throw new ArgumentException ( nameof ( src ) , "Audio Source has to be a file." ) ;
361
- }
362
-
363
- Content . Audio = new ToastAudio ( ) ;
364
- Content . Audio . Src = src ;
358
+ var audio = new ToastAudio ( ) ;
359
+ audio . Src = src ;
365
360
366
361
if ( loop ! = default )
367
362
{
368
- Content . Audio . Loop = loop . Value ;
363
+ audio . Loop = loop . Value ;
369
364
}
370
365
371
366
if ( silent ! = default )
372
367
{
373
- Content . Audio . Silent = silent . Value ;
368
+ audio . Silent = silent . Value ;
374
369
}
375
370
376
- return this ;
371
+ return AddAudio ( audio ) ;
377
372
}
378
373
379
374
/// <summary>
@@ -383,6 +378,11 @@ public ToastContentBuilder AddAudio(
383
378
/// <returns>The current instance of <see cref="ToastContentBuilder"/></returns>
384
379
public ToastContentBuilder AddAudio ( ToastAudio audio )
385
380
{
381
+ if ( audio . Src != null && ! audio . Src . IsFile && audio . Src . Scheme != "ms-appx" && audio . Src . Scheme != "ms-winsoundevent" )
382
+ {
383
+ throw new InvalidOperationException ( "Audio Source must either be a ms-appx file, absolute file, or ms-winsoundevent." ) ;
384
+ }
385
+
386
386
Content . Audio = audio ;
387
387
return this ;
388
388
}
Original file line number Diff line number Diff line change @@ -564,7 +564,22 @@ public void AddAudioTest_WithMsWinSoundEvent_ReturnSelfWithCustomAudioAdded()
564
564
}
565
565
566
566
[ TestMethod ]
567
- [ ExpectedException ( typeof ( ArgumentException ) ) ]
567
+ public void AddAudioTest_WithMsAppx_ReturnSelfWithCustomAudioAdded ( )
568
+ {
569
+ // Arrange
570
+ Uri testAudioUriSrc = new Uri ( "ms-appx:///Assets/Audio.mp3" ) ;
571
+
572
+ // Act
573
+ ToastContentBuilder builder = new ToastContentBuilder ( ) ;
574
+ ToastContentBuilder anotherReference = builder . AddAudio ( testAudioUriSrc ) ;
575
+
576
+ // Assert
577
+ Assert . AreSame ( builder , anotherReference ) ;
578
+ Assert . AreEqual ( testAudioUriSrc . OriginalString , builder . Content . Audio . Src . OriginalString ) ;
579
+ }
580
+
581
+ [ TestMethod ]
582
+ [ ExpectedException ( typeof ( InvalidOperationException ) ) ]
568
583
public void AddAudioTest_WithInvalidMsUri_ThrowException ( )
569
584
{
570
585
// Arrange
@@ -576,7 +591,19 @@ public void AddAudioTest_WithInvalidMsUri_ThrowException()
576
591
}
577
592
578
593
[ TestMethod ]
579
- [ ExpectedException ( typeof ( ArgumentException ) ) ]
594
+ [ ExpectedException ( typeof ( InvalidOperationException ) ) ]
595
+ public void AddAudioTest_WithInvalidAppDataUri_ThrowException ( )
596
+ {
597
+ // Arrange (ms-appdata isn't currently supported)
598
+ Uri testAudioUriSrc = new Uri ( "ms-appdata:///local/Sound.mp3" ) ;
599
+
600
+ // Act
601
+ ToastContentBuilder builder = new ToastContentBuilder ( ) ;
602
+ builder . AddAudio ( testAudioUriSrc ) ;
603
+ }
604
+
605
+ [ TestMethod ]
606
+ [ ExpectedException ( typeof ( InvalidOperationException ) ) ]
580
607
public void AddAudioTest_WithInvalidHttpUri_ThrowException ( )
581
608
{
582
609
// Arrange
You can’t perform that action at this time.
0 commit comments