From: Haesu Gwon Date: Tue, 21 Jul 2020 07:04:31 +0000 (+0900) Subject: [MediaController][TCSACR-353] Add new request method and deprecate old one X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=234576f535c521a53ee9456d4649f904d0c53854;p=test%2Ftct%2Fcsharp%2Fapi.git [MediaController][TCSACR-353] Add new request method and deprecate old one Change-Id: I7c21f1dccfcb560f8368db91a1641e6d2522fd0a --- diff --git a/tct-suite-vs/Tizen.MediaController.Tests/testcase/TSMediaControlServer.cs b/tct-suite-vs/Tizen.MediaController.Tests/testcase/TSMediaControlServer.cs index 72dabbe..f8d1f41 100644 --- a/tct-suite-vs/Tizen.MediaController.Tests/testcase/TSMediaControlServer.cs +++ b/tct-suite-vs/Tizen.MediaController.Tests/testcase/TSMediaControlServer.cs @@ -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(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(async () => + await MediaControlServer.RequestCommandAsync(null, Application.Current.ApplicationInfo.ApplicationId)); + + Assert.ThrowsAsync(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(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(() => MediaControlServer.Response(null, 0, new Bundle())); } diff --git a/tct-suite-vs/Tizen.MediaController.Tests/testcase/TSMediaController.cs b/tct-suite-vs/Tizen.MediaController.Tests/testcase/TSMediaController.cs index fcc9295..56247ae 100644 --- a/tct-suite-vs/Tizen.MediaController.Tests/testcase/TSMediaController.cs +++ b/tct-suite-vs/Tizen.MediaController.Tests/testcase/TSMediaController.cs @@ -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(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(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 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 eventHandler = (s, e) => + { + customCommand = e.Command; + + MediaControlServer.Response(customCommand, (int)MediaControlResult.Timeout); + }; + + try + { + MediaControlServer.CustomCommandReceived += eventHandler; + + await Task.Run(async () => + { + using (var eventWaiter = EventAwaiter.Create()) + { + _manager.ServerStopped += eventWaiter; + + MediaControlServer.Stop(); + + await eventWaiter.IsRaisedAsync(); + + Assert.ThrowsAsync(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(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(async () => + await _controller.RequestCommandAsync(new ShuffleModeCommand(true))); } [Test]