From ea13ca324f8c8554cdc82ee42393c8b1d3c1d71f Mon Sep 17 00:00:00 2001 From: ChulSeung Kim Date: Wed, 7 Jun 2017 15:35:49 +0900 Subject: [PATCH] Add unit test cases and test stub of utils. Change-Id: I69ac1081dc8ca85c899a4e82957a5ae5f4e95ca4 --- HomeUnitTest/AppShortcutTestCases.cs | 232 ++++++++++++++++++ HomeUnitTest/HomeUnitTest.csproj | 17 +- HomeUnitTest/ManagedAppsTestCases.cs | 66 +++++ .../{RecentTesting.cs => RecentTestCases.cs} | 29 ++- .../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 ++++++++ .../Utils/AppShortcutStorage.cs | 19 +- .../Utils/ApplicationManagerUtils.cs | 140 ++--------- .../Utils/FileSystemUtils.cs | 101 ++------ .../Utils/IApplicationManagerAPIs.cs | 32 ++- .../Utils/IFileSystemAPIs.cs | 4 - .../Utils/MediaContentUtils.cs | 98 ++------ .../Ports/ApplicationManagerPort.cs | 33 +-- TVApps/TVApps/ViewModels/AppsHolder.cs | 16 +- 20 files changed, 1026 insertions(+), 377 deletions(-) create mode 100644 HomeUnitTest/AppShortcutTestCases.cs create mode 100644 HomeUnitTest/ManagedAppsTestCases.cs rename HomeUnitTest/{RecentTesting.cs => RecentTestCases.cs} (74%) create mode 100644 LibTVRefCommonPortable/Stubs/ApplicationManagerAPITestStub.cs create mode 100644 LibTVRefCommonPortable/Stubs/FileSystemAPITestStub.cs create mode 100644 LibTVRefCommonPortable/Stubs/FileWatcherAPITestStub.cs create mode 100644 LibTVRefCommonPortable/Stubs/MediaContentAPITestStub.cs diff --git a/HomeUnitTest/AppShortcutTestCases.cs b/HomeUnitTest/AppShortcutTestCases.cs new file mode 100644 index 0000000..e777fb4 --- /dev/null +++ b/HomeUnitTest/AppShortcutTestCases.cs @@ -0,0 +1,232 @@ +/* + * 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 7bf1694..32e91a0 100644 --- a/HomeUnitTest/HomeUnitTest.csproj +++ b/HomeUnitTest/HomeUnitTest.csproj @@ -25,7 +25,7 @@ full false bin\Debug\ - TRACE;DEBUG;_TEST_ + TRACE;DEBUG prompt 4 @@ -46,18 +46,11 @@ - - ..\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 - - + + + @@ -77,8 +70,6 @@ - - \ No newline at end of file diff --git a/HomeUnitTest/ManagedAppsTestCases.cs b/HomeUnitTest/ManagedAppsTestCases.cs new file mode 100644 index 0000000..4d12be1 --- /dev/null +++ b/HomeUnitTest/ManagedAppsTestCases.cs @@ -0,0 +1,66 @@ +/* + * 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/RecentTesting.cs b/HomeUnitTest/RecentTestCases.cs similarity index 74% rename from HomeUnitTest/RecentTesting.cs rename to HomeUnitTest/RecentTestCases.cs index 50f90b0..e9cba17 100644 --- a/HomeUnitTest/RecentTesting.cs +++ b/HomeUnitTest/RecentTestCases.cs @@ -22,22 +22,31 @@ using System.Linq; namespace HomeUnitTest { + /// + /// A test cases for RecentShortcutController + /// [TestClass] - public class RecentTesting + public class RecentTestCases { - public RecentTesting() - { + /// + /// A instance of RecentShortcutController + /// + private RecentShortcutController controller; + /// + /// A constructor that initializes RecentShortcutController instance. + /// + public RecentTestCases() + { + controller = new RecentShortcutController(); } [TestMethod] - public void GetListTest() + public void RecentGetListTest() { - RecentShortcutController recentShortcutController = new RecentShortcutController(); - - var recents = recentShortcutController.GetList(); + var recents = controller.GetList(); - // MAX number of recent = 10 + // R : MAX number of recent = 10 if (recents.Count() > 10) { Assert.Fail("Too many Recent!!!, Returned = " + recents.Count()); @@ -64,7 +73,7 @@ namespace HomeUnitTest break; } - // Invalid Recent(id, label has 'invalid') should not included!!! + // R : Invalid Recent(id, label has 'invalid') should not included!!! if (recent.CurrentStateDescription == null || recent.CurrentStateDescription.Label.ToLower().Contains("invalid")) { @@ -72,7 +81,7 @@ namespace HomeUnitTest } } - // Test Sample Recent is consist of App and Media types. + // R : 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 40585c9..220c7c5 100644 --- a/LibTVRefCommonPortable/DataModels/CommandAction.cs +++ b/LibTVRefCommonPortable/DataModels/CommandAction.cs @@ -15,8 +15,6 @@ */ 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 305ce64..b3766c5 100644 --- a/LibTVRefCommonPortable/DataModels/StateDescription.cs +++ b/LibTVRefCommonPortable/DataModels/StateDescription.cs @@ -17,7 +17,7 @@ namespace LibTVRefCommonPortable.DataModels { /// - /// A class represnts a state of a Shortcut. + /// A class represents a state of a Shortcut. /// public class StateDescription { diff --git a/LibTVRefCommonPortable/LibTVRefCommonPortable.csproj b/LibTVRefCommonPortable/LibTVRefCommonPortable.csproj index f59578f..80bb27f 100755 --- a/LibTVRefCommonPortable/LibTVRefCommonPortable.csproj +++ b/LibTVRefCommonPortable/LibTVRefCommonPortable.csproj @@ -51,6 +51,10 @@ + + + + diff --git a/LibTVRefCommonPortable/Models/AppShortcutController.cs b/LibTVRefCommonPortable/Models/AppShortcutController.cs index 21d63de..e6cbdd5 100755 --- a/LibTVRefCommonPortable/Models/AppShortcutController.cs +++ b/LibTVRefCommonPortable/Models/AppShortcutController.cs @@ -16,7 +16,6 @@ using System; using System.Collections.Generic; - using LibTVRefCommonPortable.DataModels; using LibTVRefCommonPortable.Utils; using System.Threading.Tasks; @@ -48,38 +47,32 @@ namespace LibTVRefCommonPortable.Models var installedAppList = await ApplicationManagerUtils.Instance.GetAllInstalledApplication(); - foreach (KeyValuePair item in installedAppList) + foreach (var item in installedAppList) { - if (ManagedApps.IsNonPinnableApps(item.Key)) + if (ManagedApps.IsNonPinnableApps(item.AppID)) { continue; } var defaultStateDescription = new StateDescription() { - Label = item.Value[0], - IconPath = item.Value[2], + Label = item.Applabel, + IconPath = item.IconPath, Action = new AppControlAction() { - AppID = item.Key, + AppID = item.AppID, } }; - long longDate; - if (long.TryParse(item.Value[3], out longDate) == false) - { - longDate = long.MinValue; - } - var appShortcutInfo = new AppShortcutInfo() { - IsRemovable = ApplicationManagerUtils.Instance.GetAppInfoRemovable(item.Key), - Installed = new DateTime(longDate), + IsRemovable = ApplicationManagerUtils.Instance.GetAppInfoRemovable(item.AppID), + Installed = item.InstalledTime, }; appShortcutInfo.StateDescriptions.Add("default", defaultStateDescription); appShortcutInfo.CurrentStateDescription = defaultStateDescription; - appShortcutInfo.AppID = item.Key; + appShortcutInfo.AppID = item.AppID; appShortcutInfoList.Add(appShortcutInfo); } @@ -224,34 +217,38 @@ namespace LibTVRefCommonPortable.Models List returnPinnedAppsInfo = new List(); + int numberOfPinnedApp = 0; foreach (AppShortcutInfo appShortcutInfo in pinned_apps_info) { - if (ManagedApps.IsNonPinnableApps(appShortcutInfo.AppID)) + if (numberOfPinnedApp >= 10) { - continue; + break; } - Dictionary appInfo = ApplicationManagerUtils.Instance.GetInstalledApplication(appShortcutInfo.AppID); - - if (appInfo == null) + if (appShortcutInfo.AppID == null || + appShortcutInfo.AppID.Length < 1) { continue; } - string appLabel; - string appIconPath; + if (ManagedApps.IsNonPinnableApps(appShortcutInfo.AppID)) + { + continue; + } - if (appInfo.TryGetValue("Label", out appLabel) == false) + InstalledApp appInfo = ApplicationManagerUtils.Instance.GetInstalledApplication(appShortcutInfo.AppID); + if (appInfo == null) { - appLabel = "No Name"; + continue; } - appInfo.TryGetValue("IconPath", out appIconPath); + string appLabel = appInfo.Applabel ?? "No Name"; + string appIconPath = appInfo.IconPath ?? DefaultAppIcon; var defaultStateDescription = new StateDescription() { Label = appLabel, - IconPath = appIconPath ?? DefaultAppIcon, + IconPath = appIconPath, Action = new AppControlAction { AppID = appShortcutInfo.AppID, @@ -262,6 +259,8 @@ namespace LibTVRefCommonPortable.Models appShortcutInfo.CurrentStateDescription = defaultStateDescription; appShortcutInfo.IsPinned = true; returnPinnedAppsInfo.Add(appShortcutInfo); + + numberOfPinnedApp += 1; } return returnPinnedAppsInfo; @@ -306,14 +305,21 @@ 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 new file mode 100644 index 0000000..f19f7e8 --- /dev/null +++ b/LibTVRefCommonPortable/Stubs/ApplicationManagerAPITestStub.cs @@ -0,0 +1,228 @@ +/* + * 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 new file mode 100644 index 0000000..bc3955e --- /dev/null +++ b/LibTVRefCommonPortable/Stubs/FileSystemAPITestStub.cs @@ -0,0 +1,180 @@ +/* + * 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 new file mode 100644 index 0000000..fe4aa6b --- /dev/null +++ b/LibTVRefCommonPortable/Stubs/FileWatcherAPITestStub.cs @@ -0,0 +1,41 @@ +/* + * 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 new file mode 100644 index 0000000..2eeefb9 --- /dev/null +++ b/LibTVRefCommonPortable/Stubs/MediaContentAPITestStub.cs @@ -0,0 +1,101 @@ +/* + * 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 47b9650..47baace 100644 --- a/LibTVRefCommonPortable/Utils/AppShortcutStorage.cs +++ b/LibTVRefCommonPortable/Utils/AppShortcutStorage.cs @@ -17,10 +17,7 @@ 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; @@ -39,7 +36,7 @@ namespace LibTVRefCommonPortable.Utils /// /// A file system watcher which checks if the targeted storage is changed. /// - private static IFileSystemWatcherAPIs fileSystemWatcher = DependencyService.Get(); + private static IFileSystemWatcherAPIs fileSystemWatcher = FileSystemUtils.Instance.FileSysteamWatcherInstance; /// /// An instance of AppShortcutStorage. @@ -59,7 +56,7 @@ namespace LibTVRefCommonPortable.Utils /// private AppShortcutStorage() { - StoragePath = DependencyService.Get()?.PlatformShareStorage + "pinned_apps_info.xml"; + StoragePath = FileSystemUtils.Instance.PlatformShareStorage + "pinned_apps_info.xml"; fileSystemWatcher.Run(); } @@ -70,9 +67,7 @@ namespace LibTVRefCommonPortable.Utils /// An app Shortcut list. public static async Task> Read() { - IFileSystemAPIs fileSystem = DependencyService.Get(); - - if (fileSystem.IsFileExist(StoragePath) == false) + if (FileSystemUtils.Instance.IsFileExist(StoragePath) == false) { DebuggingUtils.Err("Set Default Pinned Apps" + StoragePath); List result = new List(); @@ -82,7 +77,7 @@ namespace LibTVRefCommonPortable.Utils for (int i = 0; i < 5; i++) { - if (fileSystem.IsFileReady(StoragePath)) + if (FileSystemUtils.Instance.IsFileReady(StoragePath)) { break; } @@ -96,7 +91,7 @@ namespace LibTVRefCommonPortable.Utils DebuggingUtils.Dbg("[" + i + "/5] Waiting for Writing" + StoragePath); } - using (Stream fileStream = fileSystem.OpenFile(StoragePath, UtilFileMode.Open)) + using (Stream fileStream = FileSystemUtils.Instance.OpenFile(StoragePath, UtilFileMode.Open)) { Debug.Assert(fileStream != null); @@ -115,9 +110,7 @@ namespace LibTVRefCommonPortable.Utils /// A status of storage update. public static bool Write(IEnumerable pinnedAppInfo) { - IFileSystemAPIs fileSystem = DependencyService.Get(); - - using (Stream fileStream = fileSystem.OpenFile(StoragePath, UtilFileMode.Create)) + using (Stream fileStream = FileSystemUtils.Instance.OpenFile(StoragePath, UtilFileMode.Create)) { Debug.Assert(fileStream != null); diff --git a/LibTVRefCommonPortable/Utils/ApplicationManagerUtils.cs b/LibTVRefCommonPortable/Utils/ApplicationManagerUtils.cs index 62d8b80..138d211 100644 --- a/LibTVRefCommonPortable/Utils/ApplicationManagerUtils.cs +++ b/LibTVRefCommonPortable/Utils/ApplicationManagerUtils.cs @@ -1,4 +1,20 @@ - +/* + * 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; @@ -32,128 +48,12 @@ 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 TestingStub(); + applicationManagerAPIs = new ApplicationManagerAPITestStub(); try { @@ -200,7 +100,7 @@ namespace LibTVRefCommonPortable.Utils /// /// The app Id to get /// The information of the installed application - public Dictionary GetInstalledApplication(string appID) + public InstalledApp GetInstalledApplication(string appID) { return applicationManagerAPIs.GetInstalledApplication(appID); } @@ -209,7 +109,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 3497da7..4ed3434 100644 --- a/LibTVRefCommonPortable/Utils/FileSystemUtils.cs +++ b/LibTVRefCommonPortable/Utils/FileSystemUtils.cs @@ -14,12 +14,9 @@ * 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 @@ -34,6 +31,11 @@ namespace LibTVRefCommonPortable.Utils /// private static IFileSystemAPIs fileSystemAPIs; + /// + /// A instance of file system watcher port layer + /// + private static IFileSystemWatcherAPIs fileSystemWatcherAPIs; + /// /// A instance of FileSystemUtils /// @@ -51,88 +53,13 @@ namespace LibTVRefCommonPortable.Utils } /// - /// A unit test stub for FileSystemUtils + /// A property of file system watcher instance /// - private class TestStub : IFileSystemAPIs + public IFileSystemWatcherAPIs FileSysteamWatcherInstance { - /// - /// 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) + get { - throw new NotImplementedException(); + return fileSystemWatcherAPIs; } } @@ -141,7 +68,8 @@ namespace LibTVRefCommonPortable.Utils /// private FileSystemUtils() { - fileSystemAPIs = new TestStub(); + fileSystemAPIs = new FileSystemAPITestStub(); + fileSystemWatcherAPIs = new FileWatcherAPITestStub(); try { @@ -149,6 +77,11 @@ 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 b8ee51c..c8521b9 100755 --- a/LibTVRefCommonPortable/Utils/IApplicationManagerAPIs.cs +++ b/LibTVRefCommonPortable/Utils/IApplicationManagerAPIs.cs @@ -51,7 +51,7 @@ namespace LibTVRefCommonPortable.Utils public String IconPath; /// - /// A last launched data + /// A last launched date /// public DateTime LaunchedTime; @@ -66,6 +66,32 @@ namespace LibTVRefCommonPortable.Utils public String ScreenShot; } + /// + /// 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 /// @@ -75,7 +101,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. @@ -88,7 +114,7 @@ namespace LibTVRefCommonPortable.Utils /// /// An application ID /// An installed application information - Dictionary GetInstalledApplication(string applicationId); + InstalledApp GetInstalledApplication(string applicationId); /// /// A method for removing all recent applications diff --git a/LibTVRefCommonPortable/Utils/IFileSystemAPIs.cs b/LibTVRefCommonPortable/Utils/IFileSystemAPIs.cs index edeb092..2f29351 100644 --- a/LibTVRefCommonPortable/Utils/IFileSystemAPIs.cs +++ b/LibTVRefCommonPortable/Utils/IFileSystemAPIs.cs @@ -15,10 +15,6 @@ */ 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 c14b051..9d56eb2 100644 --- a/LibTVRefCommonPortable/Utils/MediaContentUtils.cs +++ b/LibTVRefCommonPortable/Utils/MediaContentUtils.cs @@ -1,8 +1,22 @@ -using System; +/* + * 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.Linq; -using System.Text; -using System.Threading.Tasks; using Xamarin.Forms; namespace LibTVRefCommonPortable.Utils @@ -33,86 +47,12 @@ 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 TestStub(); + mediaContentAPIs = new MediaContentAPITestStub(); try { diff --git a/LibTVRefCommonTizen/Ports/ApplicationManagerPort.cs b/LibTVRefCommonTizen/Ports/ApplicationManagerPort.cs index 9e5cb9b..ec7c8d8 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 Dictionary GetInstalledApplication(string appID) + public InstalledApp GetInstalledApplication(string appID) { - Dictionary result = null; + InstalledApp result = null; ApplicationInfo appInfo = null; try @@ -143,10 +143,12 @@ namespace LibTVRefCommonTizen.Ports return null; } - 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); + result = new InstalledApp() + { + AppID = appInfo.ApplicationId, + Applabel = appInfo.Label, + IconPath = (System.IO.File.Exists(appInfo.IconPath)) ? appInfo.IconPath : DefaultAppIcon, + }; } catch (Exception exception) { @@ -161,13 +163,12 @@ 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 { - Dictionary resultList = new Dictionary(); + IList resultList = new List(); Task> task = ApplicationManager.GetInstalledApplicationsAsync(); - string[] result; IEnumerable installedList = await task; @@ -191,13 +192,13 @@ namespace LibTVRefCommonTizen.Ports continue; } - 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); + 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), + }); } return resultList; diff --git a/TVApps/TVApps/ViewModels/AppsHolder.cs b/TVApps/TVApps/ViewModels/AppsHolder.cs index 68acc45..54b33c8 100755 --- a/TVApps/TVApps/ViewModels/AppsHolder.cs +++ b/TVApps/TVApps/ViewModels/AppsHolder.cs @@ -246,6 +246,13 @@ 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); @@ -286,7 +293,7 @@ namespace TVApps.ViewModels /// /// A method for checking the application is removable - /// If the application is removable, show Delete Popup + /// If the application is removable, show Delete Pop-up /// /// The ID of application for checking public void CheckDeleteApp(string appID) @@ -299,11 +306,8 @@ namespace TVApps.ViewModels return; } - string appLabel = null; - if (ApplicationManagerUtils.Instance.GetInstalledApplication(appID).TryGetValue("Label", out appLabel)) - { - ViewModel.ShowDeletePopup(appLabel); - } + string appLabel = ApplicationManagerUtils.Instance.GetInstalledApplication(appID).Applabel; + ViewModel.ShowDeletePopup(appLabel); } /// -- 2.34.1