From 25d1f69799b281ee80ea178ebd09c27b81b1578e Mon Sep 17 00:00:00 2001 From: ChulSeung Kim Date: Wed, 7 Jun 2017 15:07:23 +0900 Subject: [PATCH] Revert "Add Test cases for app shortcut, managedapps" This reverts commit 7b8ebc0fd5ef30b043cd1398d339ff1d0b82d750. Change-Id: I15dc252ad24b2bb2b001e2a71b1f4823c6ebbdc4 --- HomeUnitTest/AppShortcutTestCases.cs | 232 --------------------- HomeUnitTest/HomeUnitTest.csproj | 17 +- HomeUnitTest/ManagedAppsTestCases.cs | 66 ------ .../{RecentTestCases.cs => RecentTesting.cs} | 29 +-- LibTVRefCommonPortable/DataModels/CommandAction.cs | 2 + .../DataModels/StateDescription.cs | 2 +- .../LibTVRefCommonPortable.csproj | 4 - .../Models/AppShortcutController.cs | 58 +++--- .../Stubs/ApplicationManagerAPITestStub.cs | 228 -------------------- .../Stubs/FileSystemAPITestStub.cs | 180 ---------------- .../Stubs/FileWatcherAPITestStub.cs | 41 ---- .../Stubs/MediaContentAPITestStub.cs | 101 --------- LibTVRefCommonPortable/Utils/AppShortcutStorage.cs | 19 +- .../Utils/ApplicationManagerUtils.cs | 140 +++++++++++-- LibTVRefCommonPortable/Utils/FileSystemUtils.cs | 101 +++++++-- .../Utils/IApplicationManagerAPIs.cs | 32 +-- LibTVRefCommonPortable/Utils/IFileSystemAPIs.cs | 4 + LibTVRefCommonPortable/Utils/MediaContentUtils.cs | 98 +++++++-- .../Ports/ApplicationManagerPort.cs | 33 ++- TVApps/TVApps/ViewModels/AppsHolder.cs | 16 +- 20 files changed, 377 insertions(+), 1026 deletions(-) delete mode 100644 HomeUnitTest/AppShortcutTestCases.cs delete mode 100644 HomeUnitTest/ManagedAppsTestCases.cs rename HomeUnitTest/{RecentTestCases.cs => RecentTesting.cs} (74%) delete mode 100644 LibTVRefCommonPortable/Stubs/ApplicationManagerAPITestStub.cs delete mode 100644 LibTVRefCommonPortable/Stubs/FileSystemAPITestStub.cs delete mode 100644 LibTVRefCommonPortable/Stubs/FileWatcherAPITestStub.cs delete mode 100644 LibTVRefCommonPortable/Stubs/MediaContentAPITestStub.cs diff --git a/HomeUnitTest/AppShortcutTestCases.cs b/HomeUnitTest/AppShortcutTestCases.cs deleted file mode 100644 index e777fb4..0000000 --- a/HomeUnitTest/AppShortcutTestCases.cs +++ /dev/null @@ -1,232 +0,0 @@ -/* - * Copyright (c) 2017 Samsung Electronics Co., Ltd - * - * Licensed under the Flora License, Version 1.1 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://floralicense.org/license/ - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -using System; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using LibTVRefCommonPortable.Models; -using System.Threading.Tasks; -using System.Linq; -using LibTVRefCommonPortable.DataModels; - -namespace HomeUnitTest -{ - /// - /// A test cases for AppShortcutController - /// - [TestClass] - public class AppShortcutTestCases - { - /// - /// A instance of AppShortcutController - /// - private AppShortcutController controller; - - /// - /// All Apps app shortcut name - /// - private static readonly string AllApps = "All apps"; - - /// - /// MediaHub app shortcut name - /// - private static readonly string MediaHub = "Media Hub"; - - /// - /// Add pin app shortcut name - /// - private static readonly string AddPin = "Add pin"; - - /// - /// A constructor that initialize AppShortcutController instance. - /// - public AppShortcutTestCases() - { - controller = new AppShortcutController(); - } - - #region 추가 테스트 특성 - // - // 테스트를 작성할 때 다음 추가 특성을 사용할 수 있습니다. - // - // ClassInitialize를 사용하여 클래스의 첫 번째 테스트를 실행하기 전에 코드를 실행합니다. - // [ClassInitialize()] - // public static void MyClassInitialize(TestContext testContext) { } - // - // ClassCleanup을 사용하여 클래스의 테스트를 모두 실행한 후에 코드를 실행합니다. - // [ClassCleanup()] - // public static void MyClassCleanup() { } - // - // TestInitialize를 사용하여 각 테스트를 실행하기 전에 코드를 실행합니다. - // [TestInitialize()] - // public void MyTestInitialize() { } - // - // TestCleanup을 사용하여 각 테스트를 실행한 후에 코드를 실행합니다. - // [TestCleanup()] - // public void MyTestCleanup() { } - // - #endregion - - - [TestMethod] - public async Task AppShortcutGetInstalledAppsTest() - { - var installedApps = await controller.GetInstalledApps(); - - foreach (var app in installedApps) - { - Console.Out.WriteLine("App ID : " + app.AppID); - Console.Out.WriteLine("Installed Date : " + app.Installed); - - // Err : CurrentStateDescription should not be null - Assert.AreNotEqual(app.CurrentStateDescription, null, - "StateDescription CurrentStateDescription is null!!!"); - - // Err : removable app property check - if (app.CurrentStateDescription.Label.Contains("removable") && - app.IsRemovable == false) - { - Assert.Fail("Removable is failed"); - } - - // Err : Invalid state description removing. - if (app.CurrentStateDescription.Label.Contains("invalid")) - { - Assert.Fail("Invalid App Shortcut included!!!"); - } - } - } - - [TestMethod] - public void AppShortcutGetDefaultShortcutsTest() - { - var defaultShortcuts = controller.GetDefaultShortcuts(); - - // Req : Order of default shortcuts is All apps > Media Hub > Add pin - Assert.AreNotEqual(defaultShortcuts.ElementAt(0).CurrentStateDescription, - null, "All Apps CurrentStateDescription is invalid!!!"); - Assert.AreEqual(defaultShortcuts.ElementAt(0).CurrentStateDescription.Label, AllApps); - - Assert.AreNotEqual(defaultShortcuts.ElementAt(1).CurrentStateDescription, - null, "Media Hub CurrentStateDescription is invalid!!!"); - Assert.AreEqual(defaultShortcuts.ElementAt(1).CurrentStateDescription.Label, MediaHub); - - Assert.AreNotEqual(defaultShortcuts.ElementAt(2).CurrentStateDescription, - null, "Add pin CurrentStateDescription is invalid!!!"); - Assert.AreEqual(defaultShortcuts.ElementAt(2).CurrentStateDescription.Label, AddPin); - } - - [TestMethod] - public async Task AppShortcutGetPinnedAppsWithDefaultShortcutsTest() - { - var pinnedApps = await controller.GetPinnedAppsWithDefaultShortcuts(); - - // Req : A Maximum number of pinned apps is 10. + All apps, Media Hub, Add pin - Assert.IsTrue(pinnedApps.Count() <= 13, "A Maximum number of pinned apps is 10!!! NOT " + pinnedApps.Count()); - - // Req : Order of default shortcuts is All apps > Media Hub > Add pin - Assert.AreNotEqual(pinnedApps.ElementAt(0).CurrentStateDescription, - null, "All Apps CurrentStateDescription is invalid!!!"); - Assert.AreEqual(pinnedApps.ElementAt(0).CurrentStateDescription.Label, AllApps); - - Assert.AreNotEqual(pinnedApps.ElementAt(1).CurrentStateDescription, - null, "Media Hub CurrentStateDescription is invalid!!!"); - Assert.AreEqual(pinnedApps.ElementAt(1).CurrentStateDescription.Label, MediaHub); - - Assert.AreNotEqual(pinnedApps.ElementAt(pinnedApps.Count() - 1).CurrentStateDescription, - null, "Add pin CurrentStateDescription is invalid!!!"); - Assert.AreEqual(pinnedApps.ElementAt(pinnedApps.Count() - 1).CurrentStateDescription.Label, AddPin); - - foreach (var shortcut in pinnedApps) - { - // Err : shortcut should be AppShortcutInfo - if ((shortcut is AppShortcutInfo) == false) - { - Assert.Fail("Invalid ShortCut type!!!"); - } - - var app = shortcut as AppShortcutInfo; - - Console.Out.WriteLine("ID : " + app.AppID); - Console.Out.WriteLine("Label : " + app.CurrentStateDescription.Label); - Console.Out.WriteLine("Installed : " + app.Installed); - - // Err : CurrentStateDescription should not be null - Assert.AreNotEqual(app.CurrentStateDescription, null, - "StateDescription CurrentStateDescription is null!!!"); - - // Err : Both ID and Label should not be null - Assert.IsFalse((app.AppID == null || app.AppID.Length < 1) && - (app.CurrentStateDescription.Label == null || app.CurrentStateDescription.Label.Length < 1), - "Both ID and Label should not be null!!!"); - - // Err : AppID should be exist - if (app.AppID == null) - { - if (app.CurrentStateDescription.Label.CompareTo(AllApps) != 0 && - app.CurrentStateDescription.Label.CompareTo(MediaHub) != 0 && - app.CurrentStateDescription.Label.CompareTo(AddPin) != 0) - { - Assert.Fail("App ID is missing!!! " + app.CurrentStateDescription.Label); - } - } - else - { - // Req : TVHome, TVApps, MediaHub, Settings should not be pinned. - Assert.IsFalse(app.AppID.Contains("xahome"), "TVHome should not be pinned"); - Assert.IsFalse(app.AppID.Contains("xaapps"), "TVApps should not be pinned"); - Assert.IsFalse(app.AppID.Contains("xamediahub"), "MediaHub should not be pinned"); - Assert.IsFalse(app.AppID.Contains("settings"), "Settings should not be pinned"); - } - - // Err : removable app property check - if (app.CurrentStateDescription.Label.Contains("removable") && - app.IsRemovable == false) - { - Assert.Fail("Removable is failed"); - } - - // Err : Invalid state description removing. - if (app.CurrentStateDescription.Label.Contains("invalid")) - { - Assert.Fail("Invalid App Shortcut included!!!"); - } - } - } - - [TestMethod] - public async Task AppShortcutGetPinnedAppsAppIDsTest() - { - var pinnedAppsIDs = await controller.GetPinnedAppsAppIDs(); - - // Req : A Maximum number of pinned apps is 10. - Assert.IsTrue(pinnedAppsIDs.Count() <= 10, - "A Maximum number of pinned apps is 10!!! NOT " + pinnedAppsIDs.Count()); - - foreach (var appID in pinnedAppsIDs.Keys) - { - // Err : AppID should not be null or empty. - Assert.AreNotEqual(appID, null, "App ID should not be null"); - Assert.IsFalse(appID.Length < 1, "App ID should not be empty"); - - // Req : TVHome, TVApps, MediaHub, Settings should not be pinned. - Assert.IsFalse(appID.Contains("xahome"), "TVHome should not be pinned"); - Assert.IsFalse(appID.Contains("xaapps"), "TVApps should not be pinned"); - Assert.IsFalse(appID.Contains("xamediahub"), "MediaHub should not be pinned"); - Assert.IsFalse(appID.Contains("settings"), "Settings should not be pinned"); - } - } - } -} diff --git a/HomeUnitTest/HomeUnitTest.csproj b/HomeUnitTest/HomeUnitTest.csproj index 0a0b50b..7bf1694 100644 --- a/HomeUnitTest/HomeUnitTest.csproj +++ b/HomeUnitTest/HomeUnitTest.csproj @@ -1,6 +1,6 @@  - + Debug AnyCPU @@ -46,11 +46,18 @@ + + ..\packages\Xamarin.Forms.2.3.5-r233-008\lib\portable-win+net45+wp80+win81+wpa81+MonoAndroid10+Xamarin.iOS10+xamarinmac20\Xamarin.Forms.Core.dll + + + ..\packages\Xamarin.Forms.2.3.5-r233-008\lib\portable-win+net45+wp80+win81+wpa81+MonoAndroid10+Xamarin.iOS10+xamarinmac20\Xamarin.Forms.Platform.dll + + + ..\packages\Xamarin.Forms.2.3.5-r233-008\lib\portable-win+net45+wp80+win81+wpa81+MonoAndroid10+Xamarin.iOS10+xamarinmac20\Xamarin.Forms.Xaml.dll + - - - + @@ -70,6 +77,8 @@ + + \ No newline at end of file diff --git a/HomeUnitTest/ManagedAppsTestCases.cs b/HomeUnitTest/ManagedAppsTestCases.cs deleted file mode 100644 index 4d12be1..0000000 --- a/HomeUnitTest/ManagedAppsTestCases.cs +++ /dev/null @@ -1,66 +0,0 @@ -/* - * Copyright (c) 2017 Samsung Electronics Co., Ltd - * - * Licensed under the Flora License, Version 1.1 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://floralicense.org/license/ - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -using Microsoft.VisualStudio.TestTools.UnitTesting; -using LibTVRefCommonPortable.Models; - -namespace HomeUnitTest -{ - /// - /// A Test cases for ManagedApps class. - /// - [TestClass] - public class ManagedAppsTestCases - { - /// - /// TVHome package ID - /// - private static readonly string Home = "org.tizen.xahome"; - - /// - /// TVApps package ID - /// - private static readonly string Apps = "org.tizen.xaapps"; - - /// - /// Mediahub package ID - /// - private static readonly string Mediahub = "org.tizen.xamediahub"; - - /// - /// Settings package ID - /// - private static readonly string Settings = "org.tizen.settings"; - - [TestMethod] - public void ManagerAppsIsHiddenRecentAppTest() - { - Assert.IsTrue(ManagedApps.IsHiddenRecentApp(Home), "TVHome should not be hidden in Recents"); - Assert.IsTrue(ManagedApps.IsHiddenRecentApp(Apps), "Apps should not be hidden in Recents"); - Assert.IsTrue(ManagedApps.IsHiddenRecentApp(Mediahub), "Mediahub should not be hidden in Recents"); - Assert.IsTrue(ManagedApps.IsHiddenRecentApp(Settings), "Settings should not be hidden in Recents"); - } - - [TestMethod] - public void ManagerAppsIsNonPinnableAppsTest() - { - Assert.IsTrue(ManagedApps.IsNonPinnableApps(Home), "TVHome should not be pinned"); - Assert.IsTrue(ManagedApps.IsNonPinnableApps(Apps), "Apps should not be pinned"); - Assert.IsTrue(ManagedApps.IsNonPinnableApps(Mediahub), "Mediahub should not be pinned"); - Assert.IsTrue(ManagedApps.IsNonPinnableApps(Settings), "Settings should not be pinned"); - } - } -} diff --git a/HomeUnitTest/RecentTestCases.cs b/HomeUnitTest/RecentTesting.cs similarity index 74% rename from HomeUnitTest/RecentTestCases.cs rename to HomeUnitTest/RecentTesting.cs index e9cba17..50f90b0 100644 --- a/HomeUnitTest/RecentTestCases.cs +++ b/HomeUnitTest/RecentTesting.cs @@ -22,31 +22,22 @@ using System.Linq; namespace HomeUnitTest { - /// - /// A test cases for RecentShortcutController - /// [TestClass] - public class RecentTestCases + public class RecentTesting { - /// - /// A instance of RecentShortcutController - /// - private RecentShortcutController controller; - - /// - /// A constructor that initializes RecentShortcutController instance. - /// - public RecentTestCases() + public RecentTesting() { - controller = new RecentShortcutController(); + } [TestMethod] - public void RecentGetListTest() + public void GetListTest() { - var recents = controller.GetList(); + RecentShortcutController recentShortcutController = new RecentShortcutController(); + + var recents = recentShortcutController.GetList(); - // R : MAX number of recent = 10 + // MAX number of recent = 10 if (recents.Count() > 10) { Assert.Fail("Too many Recent!!!, Returned = " + recents.Count()); @@ -73,7 +64,7 @@ namespace HomeUnitTest break; } - // R : Invalid Recent(id, label has 'invalid') should not included!!! + // Invalid Recent(id, label has 'invalid') should not included!!! if (recent.CurrentStateDescription == null || recent.CurrentStateDescription.Label.ToLower().Contains("invalid")) { @@ -81,7 +72,7 @@ namespace HomeUnitTest } } - // R : Test Sample Recent is consist of App and Media types. + // Test Sample Recent is consist of App and Media types. if (isAllMedias || isAllApps) { Assert.Fail("Invalid Recent list, All Media({0}), All Apps({1})", isAllMedias, isAllApps); diff --git a/LibTVRefCommonPortable/DataModels/CommandAction.cs b/LibTVRefCommonPortable/DataModels/CommandAction.cs index 220c7c5..40585c9 100644 --- a/LibTVRefCommonPortable/DataModels/CommandAction.cs +++ b/LibTVRefCommonPortable/DataModels/CommandAction.cs @@ -15,6 +15,8 @@ */ using System; +using System.Windows.Input; +using Xamarin.Forms; namespace LibTVRefCommonPortable.DataModels { diff --git a/LibTVRefCommonPortable/DataModels/StateDescription.cs b/LibTVRefCommonPortable/DataModels/StateDescription.cs index b3766c5..305ce64 100644 --- a/LibTVRefCommonPortable/DataModels/StateDescription.cs +++ b/LibTVRefCommonPortable/DataModels/StateDescription.cs @@ -17,7 +17,7 @@ namespace LibTVRefCommonPortable.DataModels { /// - /// A class represents a state of a Shortcut. + /// A class represnts a state of a Shortcut. /// public class StateDescription { diff --git a/LibTVRefCommonPortable/LibTVRefCommonPortable.csproj b/LibTVRefCommonPortable/LibTVRefCommonPortable.csproj index 80bb27f..f59578f 100755 --- a/LibTVRefCommonPortable/LibTVRefCommonPortable.csproj +++ b/LibTVRefCommonPortable/LibTVRefCommonPortable.csproj @@ -51,10 +51,6 @@ - - - - diff --git a/LibTVRefCommonPortable/Models/AppShortcutController.cs b/LibTVRefCommonPortable/Models/AppShortcutController.cs index e6cbdd5..21d63de 100755 --- a/LibTVRefCommonPortable/Models/AppShortcutController.cs +++ b/LibTVRefCommonPortable/Models/AppShortcutController.cs @@ -16,6 +16,7 @@ using System; using System.Collections.Generic; + using LibTVRefCommonPortable.DataModels; using LibTVRefCommonPortable.Utils; using System.Threading.Tasks; @@ -47,32 +48,38 @@ namespace LibTVRefCommonPortable.Models var installedAppList = await ApplicationManagerUtils.Instance.GetAllInstalledApplication(); - foreach (var item in installedAppList) + foreach (KeyValuePair item in installedAppList) { - if (ManagedApps.IsNonPinnableApps(item.AppID)) + if (ManagedApps.IsNonPinnableApps(item.Key)) { continue; } var defaultStateDescription = new StateDescription() { - Label = item.Applabel, - IconPath = item.IconPath, + Label = item.Value[0], + IconPath = item.Value[2], Action = new AppControlAction() { - AppID = item.AppID, + AppID = item.Key, } }; + long longDate; + if (long.TryParse(item.Value[3], out longDate) == false) + { + longDate = long.MinValue; + } + var appShortcutInfo = new AppShortcutInfo() { - IsRemovable = ApplicationManagerUtils.Instance.GetAppInfoRemovable(item.AppID), - Installed = item.InstalledTime, + IsRemovable = ApplicationManagerUtils.Instance.GetAppInfoRemovable(item.Key), + Installed = new DateTime(longDate), }; appShortcutInfo.StateDescriptions.Add("default", defaultStateDescription); appShortcutInfo.CurrentStateDescription = defaultStateDescription; - appShortcutInfo.AppID = item.AppID; + appShortcutInfo.AppID = item.Key; appShortcutInfoList.Add(appShortcutInfo); } @@ -217,38 +224,34 @@ namespace LibTVRefCommonPortable.Models List returnPinnedAppsInfo = new List(); - int numberOfPinnedApp = 0; foreach (AppShortcutInfo appShortcutInfo in pinned_apps_info) { - if (numberOfPinnedApp >= 10) - { - break; - } - - if (appShortcutInfo.AppID == null || - appShortcutInfo.AppID.Length < 1) + if (ManagedApps.IsNonPinnableApps(appShortcutInfo.AppID)) { continue; } - if (ManagedApps.IsNonPinnableApps(appShortcutInfo.AppID)) + Dictionary appInfo = ApplicationManagerUtils.Instance.GetInstalledApplication(appShortcutInfo.AppID); + + if (appInfo == null) { continue; } - InstalledApp appInfo = ApplicationManagerUtils.Instance.GetInstalledApplication(appShortcutInfo.AppID); - if (appInfo == null) + string appLabel; + string appIconPath; + + if (appInfo.TryGetValue("Label", out appLabel) == false) { - continue; + appLabel = "No Name"; } - string appLabel = appInfo.Applabel ?? "No Name"; - string appIconPath = appInfo.IconPath ?? DefaultAppIcon; + appInfo.TryGetValue("IconPath", out appIconPath); var defaultStateDescription = new StateDescription() { Label = appLabel, - IconPath = appIconPath, + IconPath = appIconPath ?? DefaultAppIcon, Action = new AppControlAction { AppID = appShortcutInfo.AppID, @@ -259,8 +262,6 @@ namespace LibTVRefCommonPortable.Models appShortcutInfo.CurrentStateDescription = defaultStateDescription; appShortcutInfo.IsPinned = true; returnPinnedAppsInfo.Add(appShortcutInfo); - - numberOfPinnedApp += 1; } return returnPinnedAppsInfo; @@ -305,21 +306,14 @@ namespace LibTVRefCommonPortable.Models IEnumerable pinned_apps_info = await AppShortcutStorage.Read(); Dictionary pinnedAppsDictionary = new Dictionary(); - int numberOfPinnedApp = 0; foreach (AppShortcutInfo appShortcutInfo in pinned_apps_info) { - if (numberOfPinnedApp >= 10) - { - break; - } - if (ManagedApps.IsNonPinnableApps(appShortcutInfo.AppID)) { continue; } pinnedAppsDictionary.Add(appShortcutInfo.AppID, appShortcutInfo.AppID); - numberOfPinnedApp += 1; } return pinnedAppsDictionary; diff --git a/LibTVRefCommonPortable/Stubs/ApplicationManagerAPITestStub.cs b/LibTVRefCommonPortable/Stubs/ApplicationManagerAPITestStub.cs deleted file mode 100644 index f19f7e8..0000000 --- a/LibTVRefCommonPortable/Stubs/ApplicationManagerAPITestStub.cs +++ /dev/null @@ -1,228 +0,0 @@ -/* - * Copyright (c) 2017 Samsung Electronics Co., Ltd - * - * Licensed under the Flora License, Version 1.1 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://floralicense.org/license/ - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -using LibTVRefCommonPortable.Utils; -using System; -using System.Collections.Generic; -using System.Threading.Tasks; - -namespace LibTVRefCommonPortable.Stubs -{ - /// - /// A unit testing stub of IApplicationManagerAPIs. - /// - public class ApplicationManagerAPITestStub : IApplicationManagerAPIs - { - /// - /// A method for removing all recent applications - /// - public void DeleteAllRecentApplication() - { - throw new NotImplementedException(); - } - - /// - /// A method for removing the specified recent application - /// - /// An application ID - public void DeleteRecentApplication(string appId) - { - throw new NotImplementedException(); - } - - /// - /// A method provides installed application list. - /// - /// An installed application list - public Task> GetAllInstalledApplication() - { - return Task.Run(() => - { - List installedApps = new List(); - - installedApps.Add(new InstalledApp - { - Applabel = "app1", - AppID = "app1", - IconPath = "path/app1", - InstalledTime = new DateTime(2017, 05, 02), - }); - - installedApps.Add(new InstalledApp - { - Applabel = "app2.removable", - AppID = "app2.removable", - IconPath = "path/app2", - InstalledTime = new DateTime(2017, 05, 02), - }); - - installedApps.Add(new InstalledApp - { - Applabel = "invalid.org.tizen.xahome", - AppID = "org.tizen.xahome", - IconPath = "path/app3", - InstalledTime = new DateTime(2017, 05, 02), - }); - - installedApps.Add(new InstalledApp - { - Applabel = "invalid.org.tizen.xaapps", - AppID = "org.tizen.xaapps", - IconPath = "path/app4", - InstalledTime = new DateTime(2017, 05, 02), - }); - - installedApps.Add(new InstalledApp - { - Applabel = "invalid.org.tizen.xamediahub", - AppID = "org.tizen.xamediahub", - IconPath = "path/app5", - InstalledTime = new DateTime(2017, 05, 02), - }); - - installedApps.Add(new InstalledApp - { - Applabel = "invalid.org.tizen.settings", - AppID = "org.tizen.settings", - IconPath = "path/app6", - InstalledTime = new DateTime(2017, 05, 02), - }); - - return (IEnumerable)installedApps; - }); - } - - /// - /// Gets the app ID by the app label - /// - /// the app label to get - /// the app ID of the app label - public Task GetAppIDbyAppLabel(string appLabel) - { - throw new NotImplementedException(); - } - - /// - /// Checks whether application is removable - /// - /// The app ID to get - /// If the application is removable, true; otherwise, false - public bool GetAppInfoRemovable(string appID) - { - return appID.Contains("removable"); - } - - /// - /// A method provides application information which is matched with the given app ID. - /// - /// An application ID - /// An installed application information - public InstalledApp GetInstalledApplication(string applicationId) - { - return new InstalledApp - { - AppID = applicationId, - Applabel = applicationId, - IconPath = "path/" + applicationId, - InstalledTime = DateUtils.GetRandomDate(), - }; - } - - /// - /// A method provides a recent application list. - /// - /// A Recent application list. - public IEnumerable GetRecentApplications() - { - IList testData = new List(); - - testData.Add(new RecentApp - { - InstanceID = "recentapp1", - InstanceLabel = "recentapp1", - AppID = "org.tizen.recentapp1", - Applabel = "recentapp1", - IconPath = "/test/recentapp1", - LaunchedTime = new DateTime(2014, 11, 12), - Uri = "uri/recentapp1", - ScreenShot = "screenshot/recentapp1", - }); - testData.Add(new RecentApp - { - InstanceID = "recentapp2.noscreenshot", - InstanceLabel = "recentapp2.noscreenshot", - AppID = "org.tizen.recentapp2.noscreenshot", - Applabel = "recentapp2.noscreenshot", - IconPath = "/test/recentapp2", - LaunchedTime = new DateTime(2014, 11, 12), - Uri = "uri/recentapp2", - }); - testData.Add(new RecentApp - { - InstanceID = "invalid.recentapp3.nolabel", - AppID = "invalid.org.tizen.recentapp3.nolabel", - IconPath = "/test/recentapp3", - LaunchedTime = new DateTime(2014, 11, 12), - Uri = "uri/recentapp3", - ScreenShot = "screenshot/recentapp3", - }); - testData.Add(new RecentApp - { - InstanceID = "invalid.recentapp4.notime", - AppID = "invalid.org.tizen.recentapp4.notime", - Applabel = "recentapp4.notime", - IconPath = "/test/recentapp4", - Uri = "uri/recentapp4", - ScreenShot = "screenshot/recentapp4", - }); - testData.Add(new RecentApp - { - InstanceID = "recentapp5", - InstanceLabel = "recentapp5", - AppID = "org.tizen.recentapp5", - Applabel = "recentapp5", - IconPath = "/test/recentapp5", - LaunchedTime = new DateTime(2017, 05, 02), - Uri = "uri/recentapp5", - ScreenShot = "screenshot/recentapp5", - }); - testData.Add(new RecentApp - { - InstanceID = "recentapp6", - InstanceLabel = "recentapp6", - AppID = "org.tizen.recentapp6", - Applabel = "recentapp6", - IconPath = "/test/recentapp6", - LaunchedTime = new DateTime(2017, 02, 26), - Uri = "uri/recentapp6", - ScreenShot = "screenshot/recentapp6", - }); - testData.Add(new RecentApp - { - InstanceID = "recentapp7", - InstanceLabel = "recentapp7", - AppID = "org.tizen.recentapp7", - Applabel = "recentapp7", - IconPath = "/test/recentapp7", - LaunchedTime = new DateTime(2016, 04, 25), - Uri = "uri/recentapp7", - ScreenShot = "screenshot/recentapp7", - }); - - return testData; - } - } -} diff --git a/LibTVRefCommonPortable/Stubs/FileSystemAPITestStub.cs b/LibTVRefCommonPortable/Stubs/FileSystemAPITestStub.cs deleted file mode 100644 index bc3955e..0000000 --- a/LibTVRefCommonPortable/Stubs/FileSystemAPITestStub.cs +++ /dev/null @@ -1,180 +0,0 @@ -/* - * Copyright (c) 2017 Samsung Electronics Co., Ltd - * - * Licensed under the Flora License, Version 1.1 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://floralicense.org/license/ - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -using LibTVRefCommonPortable.Utils; -using System; -using System.IO; -using System.Text; - -namespace LibTVRefCommonPortable.Stubs -{ - /// - /// A unit test stub for FileSystemUtils - /// - public class FileSystemAPITestStub : IFileSystemAPIs - { - /// - /// A directory path which should be used for app data storing. - /// - public string AppDataStorage - { - get - { - return "test_app_data_path/"; - } - } - - /// - /// A directory path which should be used for app resource storing. - /// - public string AppResourceStorage - { - get - { - return "test_app_resource_path/"; - } - } - - /// - /// A directory path which should be used for sharing between apps. - /// - public string PlatformShareStorage - { - get - { - return "test_platform_share_path/"; - } - } - - /// - /// A method closes the file. - /// - /// A file descriptor - public void CloseFile(Stream stream) - { - } - - /// - /// A method flushing the stream to write remains. - /// - /// A file descriptor - public void Flush(Stream stream) - { - } - - /// - /// A method checks if a file existence in the file system. - /// - /// A file path - /// An existence of the file - public bool IsFileExist(string filePath) - { - return true; - } - - /// - /// A method checks if file is read to use. - /// - /// A file path - /// A status of ready - public bool IsFileReady(string filePath) - { - return true; - } - - /// - /// A method opens a file on the given mode. - /// - /// A file path - /// An opening mode - /// A file descriptor - public Stream OpenFile(string filePath, UtilFileMode mode) - { - if (mode != UtilFileMode.Open) - { - throw new NotImplementedException(); - } - - if (filePath.Contains("pinned_apps_info")) - { - StringBuilder pinnedApps = new StringBuilder(); - - pinnedApps.Append(""); - pinnedApps.Append(""); - pinnedApps.Append(" "); - pinnedApps.Append(" org.tizen.xahome"); - pinnedApps.Append(" "); - pinnedApps.Append(" "); - pinnedApps.Append(" org.tizen.xaapps"); - pinnedApps.Append(" "); - pinnedApps.Append(" "); - pinnedApps.Append(" org.tizen.xamediahub"); - pinnedApps.Append(" "); - pinnedApps.Append(" "); - pinnedApps.Append(" org.tizen.settings"); - pinnedApps.Append(" "); - pinnedApps.Append(" "); - pinnedApps.Append(" org.tizen.example.TocToc.Tizen"); - pinnedApps.Append(" "); - pinnedApps.Append(" "); - pinnedApps.Append(" org.tizen.example.YouTube.Tizen"); - pinnedApps.Append(" "); - pinnedApps.Append(" "); - pinnedApps.Append(" org.tizen.example.Toda.Tizen"); - pinnedApps.Append(" "); - pinnedApps.Append(" "); - pinnedApps.Append(" org.tizen.example.Butterfly4.Tizen"); - pinnedApps.Append(" "); - pinnedApps.Append(" "); - pinnedApps.Append(" org.tizen.example.Butterfly5.Tizen"); - pinnedApps.Append(" "); - pinnedApps.Append(" "); - pinnedApps.Append(" org.tizen.example.Butterfly6.Tizen"); - pinnedApps.Append(" "); - pinnedApps.Append(" "); - pinnedApps.Append(" org.tizen.example.Butterfly7.Tizen"); - pinnedApps.Append(" "); - pinnedApps.Append(" "); - pinnedApps.Append(" org.tizen.example.Butterfly8.Tizen"); - pinnedApps.Append(" "); - pinnedApps.Append(" "); - pinnedApps.Append(" org.tizen.example.Butterfly9.Tizen"); - pinnedApps.Append(" "); - pinnedApps.Append(" "); - pinnedApps.Append(" org.tizen.example.Butterfly10.Tizen"); - pinnedApps.Append(" "); - pinnedApps.Append(" "); - pinnedApps.Append(" org.tizen.example.Butterfly11.Tizen"); - pinnedApps.Append(" "); - pinnedApps.Append(" "); - pinnedApps.Append(" "); - pinnedApps.Append(" "); - pinnedApps.Append(""); - - MemoryStream stream = new MemoryStream(); - StreamWriter writer = new StreamWriter(stream); - writer.Write(pinnedApps.ToString()); - writer.Flush(); - stream.Position = 0; - return stream; - } - - throw new NotImplementedException(); - } - } -} diff --git a/LibTVRefCommonPortable/Stubs/FileWatcherAPITestStub.cs b/LibTVRefCommonPortable/Stubs/FileWatcherAPITestStub.cs deleted file mode 100644 index fe4aa6b..0000000 --- a/LibTVRefCommonPortable/Stubs/FileWatcherAPITestStub.cs +++ /dev/null @@ -1,41 +0,0 @@ -/* - * Copyright (c) 2017 Samsung Electronics Co., Ltd - * - * Licensed under the Flora License, Version 1.1 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://floralicense.org/license/ - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -using LibTVRefCommonPortable.Utils; -using System; - -namespace LibTVRefCommonPortable.Stubs -{ - /// - /// A unit test stub for FileSystemUtils - /// - public class FileWatcherAPITestStub : IFileSystemWatcherAPIs - { - /// - /// A EventHandler for the file system watcher. - /// - public event EventHandler CustomChanged; - - /// - /// A method starts the file system watcher. - /// - public void Run() - { - CustomChanged?.Invoke(this, EventArgs.Empty); - - } - } -} diff --git a/LibTVRefCommonPortable/Stubs/MediaContentAPITestStub.cs b/LibTVRefCommonPortable/Stubs/MediaContentAPITestStub.cs deleted file mode 100644 index 2eeefb9..0000000 --- a/LibTVRefCommonPortable/Stubs/MediaContentAPITestStub.cs +++ /dev/null @@ -1,101 +0,0 @@ -/* - * Copyright (c) 2017 Samsung Electronics Co., Ltd - * - * Licensed under the Flora License, Version 1.1 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://floralicense.org/license/ - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -using LibTVRefCommonPortable.Utils; -using System; -using System.Collections.Generic; - -namespace LibTVRefCommonPortable.Stubs -{ - /// - /// A unit testing stub for MediaContentUtils - /// - public class MediaContentAPITestStub : IMediaContentAPIs - { - /// - /// A method for getting recently played media content list - /// - /// Maximum count of list - /// The recently played media content list - public IEnumerable GetRecentlyPlayedMedia(int limitation) - { - IList recentlyPlayed = new List(); - - recentlyPlayed.Add(new RecentlyPlayedMedia - { - MediaId = "id/recent_media1", - ThumbnailPath = "thumbnail/recent_media1", - FilePath = "filepath/recent_media1", - DisplayName = "recent_media1", - PlayedAt = new DateTime(2017, 05, 22), - }); - - recentlyPlayed.Add(new RecentlyPlayedMedia - { - MediaId = "invalid.recent_media2.nofilepath", - ThumbnailPath = "invalid.recent_media2.nofilepath", - DisplayName = "invalid.recent_media2.nofilepath", - PlayedAt = new DateTime(2017, 2, 26), - }); - - recentlyPlayed.Add(new RecentlyPlayedMedia - { - MediaId = "id/recent_media3.nothumbnail", - FilePath = "filepath/recent_media3.nothumbnail", - DisplayName = "recent_media3.nothumbnail", - PlayedAt = new DateTime(2016, 4, 25), - }); - - recentlyPlayed.Add(new RecentlyPlayedMedia - { - MediaId = "id/recent_media4", - ThumbnailPath = "thumbnail/recent_media4", - FilePath = "filepath/recent_media4", - DisplayName = "recent_media4", - PlayedAt = new DateTime(2015, 12, 7), - }); - - recentlyPlayed.Add(new RecentlyPlayedMedia - { - MediaId = "id/recent_media5", - ThumbnailPath = "thumbnail/recent_media5", - FilePath = "filepath/recent_media5", - DisplayName = "recent_media5", - PlayedAt = new DateTime(2015, 10, 1), - }); - - recentlyPlayed.Add(new RecentlyPlayedMedia - { - MediaId = "id/recent_media6", - ThumbnailPath = "thumbnail/recent_media6", - FilePath = "filepath/recent_media6", - DisplayName = "recent_media6", - PlayedAt = new DateTime(2015, 3, 3), - }); - - recentlyPlayed.Add(new RecentlyPlayedMedia - { - MediaId = "id/recent_media7", - ThumbnailPath = "thumbnail/recent_media7", - FilePath = "filepath/recent_media7", - DisplayName = "recent_media8", - PlayedAt = new DateTime(2014, 11, 17), - }); - - return recentlyPlayed; - } - } -} diff --git a/LibTVRefCommonPortable/Utils/AppShortcutStorage.cs b/LibTVRefCommonPortable/Utils/AppShortcutStorage.cs index 47baace..47b9650 100644 --- a/LibTVRefCommonPortable/Utils/AppShortcutStorage.cs +++ b/LibTVRefCommonPortable/Utils/AppShortcutStorage.cs @@ -17,7 +17,10 @@ using System; using System.Collections.Generic; using System.Xml.Serialization; using System.IO; + using LibTVRefCommonPortable.DataModels; + +using Xamarin.Forms; using System.Threading.Tasks; using System.Diagnostics; @@ -36,7 +39,7 @@ namespace LibTVRefCommonPortable.Utils /// /// A file system watcher which checks if the targeted storage is changed. /// - private static IFileSystemWatcherAPIs fileSystemWatcher = FileSystemUtils.Instance.FileSysteamWatcherInstance; + private static IFileSystemWatcherAPIs fileSystemWatcher = DependencyService.Get(); /// /// An instance of AppShortcutStorage. @@ -56,7 +59,7 @@ namespace LibTVRefCommonPortable.Utils /// private AppShortcutStorage() { - StoragePath = FileSystemUtils.Instance.PlatformShareStorage + "pinned_apps_info.xml"; + StoragePath = DependencyService.Get()?.PlatformShareStorage + "pinned_apps_info.xml"; fileSystemWatcher.Run(); } @@ -67,7 +70,9 @@ namespace LibTVRefCommonPortable.Utils /// An app Shortcut list. public static async Task> Read() { - if (FileSystemUtils.Instance.IsFileExist(StoragePath) == false) + IFileSystemAPIs fileSystem = DependencyService.Get(); + + if (fileSystem.IsFileExist(StoragePath) == false) { DebuggingUtils.Err("Set Default Pinned Apps" + StoragePath); List result = new List(); @@ -77,7 +82,7 @@ namespace LibTVRefCommonPortable.Utils for (int i = 0; i < 5; i++) { - if (FileSystemUtils.Instance.IsFileReady(StoragePath)) + if (fileSystem.IsFileReady(StoragePath)) { break; } @@ -91,7 +96,7 @@ namespace LibTVRefCommonPortable.Utils DebuggingUtils.Dbg("[" + i + "/5] Waiting for Writing" + StoragePath); } - using (Stream fileStream = FileSystemUtils.Instance.OpenFile(StoragePath, UtilFileMode.Open)) + using (Stream fileStream = fileSystem.OpenFile(StoragePath, UtilFileMode.Open)) { Debug.Assert(fileStream != null); @@ -110,7 +115,9 @@ namespace LibTVRefCommonPortable.Utils /// A status of storage update. public static bool Write(IEnumerable pinnedAppInfo) { - using (Stream fileStream = FileSystemUtils.Instance.OpenFile(StoragePath, UtilFileMode.Create)) + IFileSystemAPIs fileSystem = DependencyService.Get(); + + using (Stream fileStream = fileSystem.OpenFile(StoragePath, UtilFileMode.Create)) { Debug.Assert(fileStream != null); diff --git a/LibTVRefCommonPortable/Utils/ApplicationManagerUtils.cs b/LibTVRefCommonPortable/Utils/ApplicationManagerUtils.cs index 138d211..62d8b80 100644 --- a/LibTVRefCommonPortable/Utils/ApplicationManagerUtils.cs +++ b/LibTVRefCommonPortable/Utils/ApplicationManagerUtils.cs @@ -1,20 +1,4 @@ -/* - * Copyright (c) 2017 Samsung Electronics Co., Ltd - * - * Licensed under the Flora License, Version 1.1 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://floralicense.org/license/ - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -using LibTVRefCommonPortable.Stubs; + using System; using System.Collections.Generic; using System.Threading.Tasks; @@ -49,11 +33,127 @@ namespace LibTVRefCommonPortable.Utils } /// + /// A unit testing stub of IApplicationManagerAPIs. + /// + private class TestingStub : IApplicationManagerAPIs + { + public void DeleteAllRecentApplication() + { + throw new NotImplementedException(); + } + + public void DeleteRecentApplication(string appId) + { + throw new NotImplementedException(); + } + + public Task> GetAllInstalledApplication() + { + throw new NotImplementedException(); + } + + public Task GetAppIDbyAppLabel(string appLabel) + { + throw new NotImplementedException(); + } + + public bool GetAppInfoRemovable(string appID) + { + throw new NotImplementedException(); + } + + public Dictionary GetInstalledApplication(string applicationId) + { + throw new NotImplementedException(); + } + + public IEnumerable GetRecentApplications() + { + IList testData = new List(); + + testData.Add(new RecentApp + { + InstanceID = "recentapp1", + InstanceLabel = "recentapp1", + AppID = "org.tizen.recentapp1", + Applabel = "recentapp1", + IconPath = "/test/recentapp1", + LaunchedTime = new DateTime(2014, 11, 12), + Uri = "uri/recentapp1", + ScreenShot = "screenshot/recentapp1", + }); + testData.Add(new RecentApp + { + InstanceID = "recentapp2.noscreenshot", + InstanceLabel = "recentapp2.noscreenshot", + AppID = "org.tizen.recentapp2.noscreenshot", + Applabel = "recentapp2.noscreenshot", + IconPath = "/test/recentapp2", + LaunchedTime = new DateTime(2014, 11, 12), + Uri = "uri/recentapp2", + }); + testData.Add(new RecentApp + { + InstanceID = "invalid.recentapp3.nolabel", + AppID = "invalid.org.tizen.recentapp3.nolabel", + IconPath = "/test/recentapp3", + LaunchedTime = new DateTime(2014, 11, 12), + Uri = "uri/recentapp3", + ScreenShot = "screenshot/recentapp3", + }); + testData.Add(new RecentApp + { + InstanceID = "invalid.recentapp4.notime", + AppID = "invalid.org.tizen.recentapp4.notime", + Applabel = "recentapp4.notime", + IconPath = "/test/recentapp4", + Uri = "uri/recentapp4", + ScreenShot = "screenshot/recentapp4", + }); + testData.Add(new RecentApp + { + InstanceID = "recentapp5", + InstanceLabel = "recentapp5", + AppID = "org.tizen.recentapp5", + Applabel = "recentapp5", + IconPath = "/test/recentapp5", + LaunchedTime = new DateTime(2017, 05, 02), + Uri = "uri/recentapp5", + ScreenShot = "screenshot/recentapp5", + }); + testData.Add(new RecentApp + { + InstanceID = "recentapp6", + InstanceLabel = "recentapp6", + AppID = "org.tizen.recentapp6", + Applabel = "recentapp6", + IconPath = "/test/recentapp6", + LaunchedTime = new DateTime(2017, 02, 26), + Uri = "uri/recentapp6", + ScreenShot = "screenshot/recentapp6", + }); + testData.Add(new RecentApp + { + InstanceID = "recentapp7", + InstanceLabel = "recentapp7", + AppID = "org.tizen.recentapp7", + Applabel = "recentapp7", + IconPath = "/test/recentapp7", + LaunchedTime = new DateTime(2016, 04, 25), + Uri = "uri/recentapp7", + ScreenShot = "screenshot/recentapp7", + }); + + return testData; + } + } + + /// /// A constructor /// private ApplicationManagerUtils() { - applicationManagerAPIs = new ApplicationManagerAPITestStub(); + applicationManagerAPIs = new TestingStub(); try { @@ -100,7 +200,7 @@ namespace LibTVRefCommonPortable.Utils /// /// The app Id to get /// The information of the installed application - public InstalledApp GetInstalledApplication(string appID) + public Dictionary GetInstalledApplication(string appID) { return applicationManagerAPIs.GetInstalledApplication(appID); } @@ -109,7 +209,7 @@ namespace LibTVRefCommonPortable.Utils /// Gets the information of the installed applications asynchronously /// /// The list of the installed applications - public Task> GetAllInstalledApplication() + public Task> GetAllInstalledApplication() { return applicationManagerAPIs.GetAllInstalledApplication(); } diff --git a/LibTVRefCommonPortable/Utils/FileSystemUtils.cs b/LibTVRefCommonPortable/Utils/FileSystemUtils.cs index 4ed3434..3497da7 100644 --- a/LibTVRefCommonPortable/Utils/FileSystemUtils.cs +++ b/LibTVRefCommonPortable/Utils/FileSystemUtils.cs @@ -14,9 +14,12 @@ * limitations under the License. */ -using LibTVRefCommonPortable.Stubs; using System; +using System.Collections.Generic; using System.IO; +using System.Linq; +using System.Text; +using System.Threading.Tasks; using Xamarin.Forms; namespace LibTVRefCommonPortable.Utils @@ -32,11 +35,6 @@ namespace LibTVRefCommonPortable.Utils private static IFileSystemAPIs fileSystemAPIs; /// - /// A instance of file system watcher port layer - /// - private static IFileSystemWatcherAPIs fileSystemWatcherAPIs; - - /// /// A instance of FileSystemUtils /// private static readonly FileSystemUtils instance = new FileSystemUtils(); @@ -53,13 +51,88 @@ namespace LibTVRefCommonPortable.Utils } /// - /// A property of file system watcher instance + /// A unit test stub for FileSystemUtils /// - public IFileSystemWatcherAPIs FileSysteamWatcherInstance + private class TestStub : IFileSystemAPIs { - get + /// + /// A directory path which should be used for app data storing. + /// + public string AppDataStorage + { + get + { + return "test_app_data_path/"; + } + } + + /// + /// A directory path which should be used for app resource storing. + /// + public string AppResourceStorage + { + get + { + return "test_app_resource_path/"; + } + } + + /// + /// A directory path which should be used for sharing between apps. + /// + public string PlatformShareStorage + { + get + { + return "test_platform_share_path/"; + } + } + + /// + /// A method closes the file. + /// + /// A file descriptor + public void CloseFile(Stream stream) + { + } + + /// + /// A method flushing the stream to write remains. + /// + /// A file descriptor + public void Flush(Stream stream) { - return fileSystemWatcherAPIs; + } + + /// + /// A method checks if a file existence in the file system. + /// + /// A file path + /// An existence of the file + public bool IsFileExist(string filePath) + { + return true; + } + + /// + /// A method checks if file is read to use. + /// + /// A file path + /// A status of ready + public bool IsFileReady(string filePath) + { + return true; + } + + /// + /// A method opens a file on the given mode. + /// + /// A file path + /// An opening mode + /// A file descriptor + public Stream OpenFile(string filePath, UtilFileMode mode) + { + throw new NotImplementedException(); } } @@ -68,8 +141,7 @@ namespace LibTVRefCommonPortable.Utils /// private FileSystemUtils() { - fileSystemAPIs = new FileSystemAPITestStub(); - fileSystemWatcherAPIs = new FileWatcherAPITestStub(); + fileSystemAPIs = new TestStub(); try { @@ -77,11 +149,6 @@ namespace LibTVRefCommonPortable.Utils { fileSystemAPIs = DependencyService.Get(); } - - if (DependencyService.Get() != null) - { - fileSystemWatcherAPIs = DependencyService.Get(); - } } catch (InvalidOperationException e) { diff --git a/LibTVRefCommonPortable/Utils/IApplicationManagerAPIs.cs b/LibTVRefCommonPortable/Utils/IApplicationManagerAPIs.cs index c8521b9..b8ee51c 100755 --- a/LibTVRefCommonPortable/Utils/IApplicationManagerAPIs.cs +++ b/LibTVRefCommonPortable/Utils/IApplicationManagerAPIs.cs @@ -51,7 +51,7 @@ namespace LibTVRefCommonPortable.Utils public String IconPath; /// - /// A last launched date + /// A last launched data /// public DateTime LaunchedTime; @@ -67,32 +67,6 @@ namespace LibTVRefCommonPortable.Utils } /// - /// A class to store installed app information. - /// - public class InstalledApp - { - /// - /// An app ID - /// - public String AppID; - - /// - /// An app label - /// - public String Applabel; - - /// - /// An app icon path - /// - public String IconPath; - - /// - /// A installed date - /// - public DateTime InstalledTime; - } - - /// /// An interface for Application Manager feature /// public interface IApplicationManagerAPIs @@ -101,7 +75,7 @@ namespace LibTVRefCommonPortable.Utils /// A method provides installed application list. /// /// An installed application list - Task> GetAllInstalledApplication(); + Task> GetAllInstalledApplication(); /// /// A method provides a recent application list. @@ -114,7 +88,7 @@ namespace LibTVRefCommonPortable.Utils /// /// An application ID /// An installed application information - InstalledApp GetInstalledApplication(string applicationId); + Dictionary GetInstalledApplication(string applicationId); /// /// A method for removing all recent applications diff --git a/LibTVRefCommonPortable/Utils/IFileSystemAPIs.cs b/LibTVRefCommonPortable/Utils/IFileSystemAPIs.cs index 2f29351..edeb092 100644 --- a/LibTVRefCommonPortable/Utils/IFileSystemAPIs.cs +++ b/LibTVRefCommonPortable/Utils/IFileSystemAPIs.cs @@ -15,6 +15,10 @@ */ using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; using System.IO; namespace LibTVRefCommonPortable.Utils diff --git a/LibTVRefCommonPortable/Utils/MediaContentUtils.cs b/LibTVRefCommonPortable/Utils/MediaContentUtils.cs index 9d56eb2..c14b051 100644 --- a/LibTVRefCommonPortable/Utils/MediaContentUtils.cs +++ b/LibTVRefCommonPortable/Utils/MediaContentUtils.cs @@ -1,22 +1,8 @@ -/* - * Copyright (c) 2017 Samsung Electronics Co., Ltd - * - * Licensed under the Flora License, Version 1.1 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://floralicense.org/license/ - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -using LibTVRefCommonPortable.Stubs; -using System; +using System; using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; using Xamarin.Forms; namespace LibTVRefCommonPortable.Utils @@ -48,11 +34,85 @@ namespace LibTVRefCommonPortable.Utils } /// + /// A unit testing stub for MediaContentUtils + /// + private class TestStub : IMediaContentAPIs + { + public IEnumerable GetRecentlyPlayedMedia(int limitation) + { + IList recentlyPlayed = new List(); + + recentlyPlayed.Add(new RecentlyPlayedMedia + { + MediaId = "id/recent_media1", + ThumbnailPath = "thumbnail/recent_media1", + FilePath = "filepath/recent_media1", + DisplayName = "recent_media1", + PlayedAt = new DateTime(2017, 05, 22), + }); + + recentlyPlayed.Add(new RecentlyPlayedMedia + { + MediaId = "invalid.recent_media2.nofilepath", + ThumbnailPath = "invalid.recent_media2.nofilepath", + DisplayName = "invalid.recent_media2.nofilepath", + PlayedAt = new DateTime(2017, 2, 26), + }); + + recentlyPlayed.Add(new RecentlyPlayedMedia + { + MediaId = "id/recent_media3.nothumbnail", + FilePath = "filepath/recent_media3.nothumbnail", + DisplayName = "recent_media3.nothumbnail", + PlayedAt = new DateTime(2016, 4, 25), + }); + + recentlyPlayed.Add(new RecentlyPlayedMedia + { + MediaId = "id/recent_media4", + ThumbnailPath = "thumbnail/recent_media4", + FilePath = "filepath/recent_media4", + DisplayName = "recent_media4", + PlayedAt = new DateTime(2015, 12, 7), + }); + + recentlyPlayed.Add(new RecentlyPlayedMedia + { + MediaId = "id/recent_media5", + ThumbnailPath = "thumbnail/recent_media5", + FilePath = "filepath/recent_media5", + DisplayName = "recent_media5", + PlayedAt = new DateTime(2015, 10, 1), + }); + + recentlyPlayed.Add(new RecentlyPlayedMedia + { + MediaId = "id/recent_media6", + ThumbnailPath = "thumbnail/recent_media6", + FilePath = "filepath/recent_media6", + DisplayName = "recent_media6", + PlayedAt = new DateTime(2015, 3, 3), + }); + + recentlyPlayed.Add(new RecentlyPlayedMedia + { + MediaId = "id/recent_media7", + ThumbnailPath = "thumbnail/recent_media7", + FilePath = "filepath/recent_media7", + DisplayName = "recent_media8", + PlayedAt = new DateTime(2014, 11, 17), + }); + + return recentlyPlayed; + } + } + + /// /// A Constructor /// private MediaContentUtils() { - mediaContentAPIs = new MediaContentAPITestStub(); + mediaContentAPIs = new TestStub(); try { diff --git a/LibTVRefCommonTizen/Ports/ApplicationManagerPort.cs b/LibTVRefCommonTizen/Ports/ApplicationManagerPort.cs index ec7c8d8..9e5cb9b 100755 --- a/LibTVRefCommonTizen/Ports/ApplicationManagerPort.cs +++ b/LibTVRefCommonTizen/Ports/ApplicationManagerPort.cs @@ -129,9 +129,9 @@ namespace LibTVRefCommonTizen.Ports /// /// The app Id to get /// The information of the installed application - public InstalledApp GetInstalledApplication(string appID) + public Dictionary GetInstalledApplication(string appID) { - InstalledApp result = null; + Dictionary result = null; ApplicationInfo appInfo = null; try @@ -143,12 +143,10 @@ namespace LibTVRefCommonTizen.Ports return null; } - result = new InstalledApp() - { - AppID = appInfo.ApplicationId, - Applabel = appInfo.Label, - IconPath = (System.IO.File.Exists(appInfo.IconPath)) ? appInfo.IconPath : DefaultAppIcon, - }; + result = new Dictionary(); + result.Add("Label", appInfo.Label); + result.Add("ApplicationId", appInfo.ApplicationId); + result.Add("IconPath", (System.IO.File.Exists(appInfo.IconPath)) ? appInfo.IconPath : DefaultAppIcon); } catch (Exception exception) { @@ -163,12 +161,13 @@ namespace LibTVRefCommonTizen.Ports /// Gets the information of the installed applications asynchronously /// /// The list of the installed applications - public async Task> GetAllInstalledApplication() + public async Task> GetAllInstalledApplication() { try { - IList resultList = new List(); + Dictionary resultList = new Dictionary(); Task> task = ApplicationManager.GetInstalledApplicationsAsync(); + string[] result; IEnumerable installedList = await task; @@ -192,13 +191,13 @@ namespace LibTVRefCommonTizen.Ports continue; } - resultList.Add(new InstalledApp - { - AppID = appInfo.ApplicationId, - Applabel = appInfo.Label, - IconPath = (System.IO.File.Exists(appInfo.IconPath)) ? appInfo.IconPath : DefaultAppIcon, - InstalledTime = new DateTime(pkgInfo.InstalledTime), - }); + result = new string[4]; + + result[0] = appInfo.Label; + result[1] = appInfo.ApplicationId; + result[2] = (System.IO.File.Exists(appInfo.IconPath)) ? appInfo.IconPath : DefaultAppIcon; + result[3] = "" + pkgInfo.InstalledTime; + resultList.Add(appInfo.ApplicationId, result); } return resultList; diff --git a/TVApps/TVApps/ViewModels/AppsHolder.cs b/TVApps/TVApps/ViewModels/AppsHolder.cs index 54b33c8..68acc45 100755 --- a/TVApps/TVApps/ViewModels/AppsHolder.cs +++ b/TVApps/TVApps/ViewModels/AppsHolder.cs @@ -246,13 +246,6 @@ namespace TVApps.ViewModels } else { - if (PinnedApps.Count >= 10) - { - IsSelectedExceeds = true; - ViewModel.OnPropertyChanged("IsSelectedExceeds"); - return; - } - DebuggingUtils.Dbg("Pin : " + appID); SelectedApp.IsPinned = true; PinnedApps.Add(appID, appID); @@ -293,7 +286,7 @@ namespace TVApps.ViewModels /// /// A method for checking the application is removable - /// If the application is removable, show Delete Pop-up + /// If the application is removable, show Delete Popup /// /// The ID of application for checking public void CheckDeleteApp(string appID) @@ -306,8 +299,11 @@ namespace TVApps.ViewModels return; } - string appLabel = ApplicationManagerUtils.Instance.GetInstalledApplication(appID).Applabel; - ViewModel.ShowDeletePopup(appLabel); + string appLabel = null; + if (ApplicationManagerUtils.Instance.GetInstalledApplication(appID).TryGetValue("Label", out appLabel)) + { + ViewModel.ShowDeletePopup(appLabel); + } } /// -- 2.7.4