Add test using short timeout throws WebException (dotnet/corefx#34856)
authorMaryam Ariyan <maryam.ariyan@microsoft.com>
Sat, 26 Jan 2019 14:26:19 +0000 (06:26 -0800)
committerStephen Toub <stoub@microsoft.com>
Sat, 26 Jan 2019 14:26:19 +0000 (09:26 -0500)
* Add test using short timeout throwing WebException

Fixes: dotnet/corefx#34849

* Make test conditional and target internal location

* code cleanup

Commit migrated from https://github.com/dotnet/corefx/commit/a3df534fca15e6053aab748e020006a5cb3b0d31

src/libraries/System.Windows.Extensions/tests/System/Media/SoundPlayerTests.cs

index dd666cc..ff2c896 100644 (file)
@@ -143,6 +143,22 @@ namespace System.Media.Test
             player.Play();
         }
 
+        [ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsSoundPlaySupported))] 
+        [OuterLoop]
+        public void Play_InvalidFile_ShortTimeout_ThrowsWebException()
+        {
+            using (Socket listener = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp))
+            {
+                listener.Bind(new IPEndPoint(IPAddress.Loopback, 0));
+                listener.Listen(1);
+                var ep = (IPEndPoint)listener.LocalEndPoint;
+                var player = new SoundPlayer();
+                player.SoundLocation = $"http://{ep.Address}:{ep.Port}";
+                player.LoadTimeout = 1;
+                Assert.Throws<WebException>(() => player.Play());
+            } 
+        }
+
         [ConditionalTheory(typeof(PlatformDetection), nameof(PlatformDetection.IsSoundPlaySupported))]
         [MemberData(nameof(Play_String_TestData))]
         [OuterLoop]
@@ -250,7 +266,6 @@ namespace System.Media.Test
 
         [ConditionalTheory(typeof(PlatformDetection), nameof(PlatformDetection.IsSoundPlaySupported))]
         [MemberData(nameof(Play_InvalidString_TestData))]
-        [InlineData("http://google.com")]
         public void Play_InvalidFile_ThrowsInvalidOperationException(string sourceLocation)
         {
             var soundPlayer = new SoundPlayer(sourceLocation);