[MediaController][TCSACR-353] Add new request method and deprecate old one 26/239026/6
authorHaesu Gwon <haesu.gwon@samsung.com>
Tue, 21 Jul 2020 07:04:31 +0000 (16:04 +0900)
committerHaesu Gwon <haesu.gwon@samsung.com>
Mon, 3 Aug 2020 08:20:44 +0000 (08:20 +0000)
Change-Id: I7c21f1dccfcb560f8368db91a1641e6d2522fd0a

tct-suite-vs/Tizen.MediaController.Tests/testcase/TSMediaControlServer.cs
tct-suite-vs/Tizen.MediaController.Tests/testcase/TSMediaController.cs

index 72dabbe..f8d1f41 100644 (file)
@@ -362,6 +362,101 @@ namespace Tizen.Multimedia.Remoting.Tests
 
         [Test]
         [Category("P1")]
+        [Description("Thows nothing when RequestCommandAsync to client")]
+        [Property("SPEC", "Tizen.Multimedia.Remoting.MediaControlServer.RequestCommandAsync M")]
+        [Property("SPEC_URL", "-")]
+        [Property("CRITERIA", "MR")]
+        [Property("AUTHOR", "Haesu Gwon, haesu.gwon@samsung.com")]
+        public async Task RequestCommandAsync_RETURN_VALUE()
+        {
+            using (var manager = new MediaControllerManager())
+            {
+                var controller = manager.GetActiveControllers().Single(
+                        c => c.ServerAppId == Application.Current.ApplicationInfo.ApplicationId);
+                CustomCommand customCommand = null;
+
+                controller.CustomCommandReceived += (s, e) =>
+                {
+                    customCommand = e.Command;
+
+                    controller.Response(customCommand, (int)MediaControlResult.Timeout);
+                };
+
+                await Task.Run(async () =>
+                {
+                    var resultValue = await MediaControlServer.RequestCommandAsync(new CustomCommand("CustomCommand"),
+                        Application.Current.ApplicationInfo.ApplicationId);
+
+                    Assert.AreEqual(resultValue.result, (int)MediaControlResult.Timeout);
+                });
+            }
+        }
+
+        [Test]
+        [Category("P2")]
+        [Description("Check whether RequestCommandAsync throws exception if client response with error")]
+        [Property("SPEC", "Tizen.Multimedia.Remoting.MediaControlServer.RequestCommandAsync M")]
+        [Property("SPEC_URL", "-")]
+        [Property("CRITERIA", "MEX")]
+        [Property("AUTHOR", "Haesu Gwon, haesu.gwon@samsung.com")]
+        public async Task RequestCommandAsync_THROWS_INVALIDOPERATIONEXCEPTION()
+        {
+            using (var manager = new MediaControllerManager())
+            {
+                var controller = manager.GetActiveControllers().Single(
+                        c => c.ServerAppId == Application.Current.ApplicationInfo.ApplicationId);
+                CustomCommand customCommand = null;
+
+                controller.CustomCommandReceived += (s, e) =>
+                {
+                    customCommand = e.Command;
+
+                    controller.Response(customCommand, (int)MediaControlResult.Timeout);
+                };
+
+                await Task.Run(async () =>
+                {
+                    MediaControlServer.Stop();
+
+                    Assert.ThrowsAsync<InvalidOperationException>(async () =>
+                        await MediaControlServer.RequestCommandAsync(new CustomCommand("CustomCommand"),
+                        Application.Current.ApplicationInfo.ApplicationId));
+                });
+            }
+        }
+
+        [Test]
+        [Category("P2")]
+        [Description("Check whether RequestCommandAsync throws exception if parameter is null")]
+        [Property("SPEC", "Tizen.Multimedia.Remoting.MediaControlServer.RequestCommandAsync M")]
+        [Property("SPEC_URL", "-")]
+        [Property("CRITERIA", "MEX")]
+        [Property("AUTHOR", "Haesu Gwon, haesu.gwon@samsung.com")]
+        public void RequestCommandAsync_THROWS_ARGUMENTNULLEXCEPTION()
+        {
+            Assert.ThrowsAsync<ArgumentNullException>(async () =>
+                await MediaControlServer.RequestCommandAsync(null, Application.Current.ApplicationInfo.ApplicationId));
+
+            Assert.ThrowsAsync<ArgumentNullException>(async () =>
+                await MediaControlServer.RequestCommandAsync(new CustomCommand("CustomCommand"), null));
+        }
+
+        [Test]
+        [Category("P2")]
+        [Description("Check whether RequestCommandAsync throws exception if server try to send not implemented command")]
+        [Property("SPEC", "Tizen.Multimedia.Remoting.MediaControlServer.RequestCommandAsync M")]
+        [Property("SPEC_URL", "-")]
+        [Property("CRITERIA", "MEX")]
+        [Property("AUTHOR", "Haesu Gwon, haesu.gwon@samsung.com")]
+        public void RequestCommandAsync_THROWS_NOTIMPLEMENTEDEXCEPTION()
+        {
+            Assert.ThrowsAsync<NotImplementedException>(async () =>
+                await MediaControlServer.RequestCommandAsync(new ShuffleModeCommand(true),
+                Application.Current.ApplicationInfo.ApplicationId));
+        }
+
+        [Test]
+        [Category("P1")]
         [Description("Thows nothing when response to client")]
         [Property("SPEC", "Tizen.Multimedia.Remoting.MediaControlServer.Response M")]
         [Property("SPEC_URL", "-")]
@@ -406,13 +501,24 @@ namespace Tizen.Multimedia.Remoting.Tests
         [Property("CRITERIA", "MEX")]
         [Property("COVPARAM", "Command, int, Bundle")]
         [Property("AUTHOR", "Haesu Gwon, haesu.gwon@samsung.com")]
-        public void Response_WITH_BUNDLE_THROWS_EXCEPTION()
+        public void Response_WITH_BUNDLE_THROWS_INVALIDOPERATIONEXCEPTION()
         {
             MediaControlServer.Stop();
 
             Assert.That(() => MediaControlServer.Response(new CustomCommand("custom"), 0, new Bundle()),
                 Throws.InvalidOperationException);
+        }
 
+        [Test]
+        [Category("P2")]
+        [Description("Check whether Response throws exception if parameter is null")]
+        [Property("SPEC", "Tizen.Multimedia.Remoting.MediaControlServer.Response M")]
+        [Property("SPEC_URL", "-")]
+        [Property("CRITERIA", "MEX")]
+        [Property("COVPARAM", "Command, int, Bundle")]
+        [Property("AUTHOR", "Haesu Gwon, haesu.gwon@samsung.com")]
+        public void Response_WITH_BUNDLE_THROWS_ARGUMENTNULLEXCEPTION()
+        {
             Assert.Throws<ArgumentNullException>(() => MediaControlServer.Response(null, 0, new Bundle()));
         }
 
index fcc9295..56247ae 100644 (file)
@@ -978,7 +978,7 @@ namespace Tizen.Multimedia.Remoting.Tests
 
                 await Task.Run(() =>
                 {
-                    Assert.That(() => _controller.RequestAsync(_command), Throws.Nothing);
+                    Assert.That(async () => await _controller.RequestAsync(_command), Throws.Nothing);
                 });
             }
             finally
@@ -1012,7 +1012,8 @@ namespace Tizen.Multimedia.Remoting.Tests
 
                 await Task.Run(() =>
                 {
-                    Assert.That(() => _controller.RequestAsync(_command), Throws.InvalidOperationException);
+                    Assert.ThrowsAsync<InvalidOperationException>(async () =>
+                        await _controller.RequestAsync(_command));
                 });
             }
             finally
@@ -1030,7 +1031,115 @@ namespace Tizen.Multimedia.Remoting.Tests
         [Property("AUTHOR", "Haesu Gwon, haesu.gwon@samsung.com")]
         public void RequestAsync_THROWS_EXCEPTION_NULL()
         {
-            Assert.That(() => _controller.RequestAsync(null), Throws.ArgumentNullException);
+            Assert.ThrowsAsync<ArgumentNullException>(async () =>
+                await _controller.RequestAsync(null));
+        }
+
+        [Test]
+        [Category("P1")]
+        [Description("Throws nothing when request to server")]
+        [Property("SPEC", "Tizen.Multimedia.Remoting.MediaController.RequestCommandAsync M")]
+        [Property("SPEC_URL", "-")]
+        [Property("CRITERIA", "MR")]
+        [Property("AUTHOR", "Haesu Gwon, haesu.gwon@samsung.com")]
+        public async Task RequestCommandAsync_THROWS_NOTHING()
+        {
+            CustomCommand customCommand = null;
+            EventHandler<CustomCommandReceivedEventArgs> eventHandler = (s, e) =>
+            {
+                customCommand = e.Command;
+                Log.Info("Tizen.MediaController.Tests", $"e.Command.Action : {e.Command.Action}");
+
+                MediaControlServer.Response(customCommand, (int)MediaControlResult.Timeout);
+            };
+
+            try
+            {
+                MediaControlServer.CustomCommandReceived += eventHandler;
+
+                await Task.Run(() =>
+                {
+                    var returnValue = _controller.RequestCommandAsync(_command);
+                    Assert.AreEqual(returnValue.Result.result, (int)MediaControlResult.Timeout);
+                });
+            }
+            finally
+            {
+                MediaControlServer.CustomCommandReceived -= eventHandler;
+            }
+        }
+
+        [Test]
+        [Category("P2")]
+        [Description("Check whether RequestCommandAsync throws exception if server response with error")]
+        [Property("SPEC", "Tizen.Multimedia.Remoting.MediaController.RequestCommandAsync M")]
+        [Property("SPEC_URL", "-")]
+        [Property("CRITERIA", "MEX")]
+        [Property("AUTHOR", "Haesu Gwon, haesu.gwon@samsung.com")]
+        public async Task RequestCommandAsync_THROWS_EXCEPTION()
+        {
+            CustomCommand customCommand = null;
+
+            EventHandler<CustomCommandReceivedEventArgs> eventHandler = (s, e) =>
+            {
+                customCommand = e.Command;
+
+                MediaControlServer.Response(customCommand, (int)MediaControlResult.Timeout);
+            };
+
+            try
+            {
+                MediaControlServer.CustomCommandReceived += eventHandler;
+
+                await Task.Run(async () =>
+                {
+                    using (var eventWaiter = EventAwaiter<MediaControlServerStoppedEventArgs>.Create())
+                    {
+                        _manager.ServerStopped += eventWaiter;
+
+                        MediaControlServer.Stop();
+
+                        await eventWaiter.IsRaisedAsync();
+
+                        Assert.ThrowsAsync<InvalidOperationException>(async () =>
+                            await _controller.RequestCommandAsync(_command));
+
+                        _manager.ServerStopped -= eventWaiter;
+                    }
+                });
+            }
+            finally
+            {
+                MediaControlServer.CustomCommandReceived -= eventHandler;
+            }
+        }
+
+        [Test]
+        [Category("P2")]
+        [Description("Check whether RequestCommandAsync throws exception if parameter is null")]
+        [Property("SPEC", "Tizen.Multimedia.Remoting.MediaController.RequestCommandAsync M")]
+        [Property("SPEC_URL", "-")]
+        [Property("CRITERIA", "MEX")]
+        [Property("AUTHOR", "Haesu Gwon, haesu.gwon@samsung.com")]
+        public void RequestCommandAsync_THROWS_ARGUMENTNULLEXCEPTION()
+        {
+            Assert.ThrowsAsync<ArgumentNullException>(async () =>
+                await _controller.RequestCommandAsync(null));
+        }
+
+        [Test]
+        [Category("P2")]
+        [Description("Check whether RequestCommandAsync throws exception if parameter is null")]
+        [Property("SPEC", "Tizen.Multimedia.Remoting.MediaController.RequestCommandAsync M")]
+        [Property("SPEC_URL", "-")]
+        [Property("CRITERIA", "MEX")]
+        [Property("AUTHOR", "Haesu Gwon, haesu.gwon@samsung.com")]
+        public void RequestCommandAsync_THROWS_IF_OBJECT_IS_DISPOSED()
+        {
+            _manager.Dispose();
+
+            Assert.ThrowsAsync<ObjectDisposedException>(async () =>
+                await _controller.RequestCommandAsync(new ShuffleModeCommand(true)));
         }
 
         [Test]