2 * Copyright (c) 2017 Samsung Electronics Co., Ltd
4 * Licensed under the Flora License, Version 1.1 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://floralicense.org/license/
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
18 using Microsoft.VisualStudio.TestTools.UnitTesting;
19 using LibTVRefCommonPortable.Models;
20 using System.Threading.Tasks;
22 using LibTVRefCommonPortable.DataModels;
24 namespace HomeUnitTest
27 /// A test cases for AppShortcutController
30 public class AppShortcutTestCases
33 /// A instance of AppShortcutController
35 private AppShortcutController controller;
38 /// All Apps app shortcut name
40 private static readonly string AllApps = "All apps";
43 /// MediaHub app shortcut name
45 private static readonly string MediaHub = "Media Hub";
48 /// Add pin app shortcut name
50 private static readonly string AddPin = "Add pin";
53 /// A constructor that initialize AppShortcutController instance.
55 public AppShortcutTestCases()
57 controller = new AppShortcutController();
62 // 테스트를 작성할 때 다음 추가 특성을 사용할 수 있습니다.
64 // ClassInitialize를 사용하여 클래스의 첫 번째 테스트를 실행하기 전에 코드를 실행합니다.
65 // [ClassInitialize()]
66 // public static void MyClassInitialize(TestContext testContext) { }
68 // ClassCleanup을 사용하여 클래스의 테스트를 모두 실행한 후에 코드를 실행합니다.
70 // public static void MyClassCleanup() { }
72 // TestInitialize를 사용하여 각 테스트를 실행하기 전에 코드를 실행합니다.
74 // public void MyTestInitialize() { }
76 // TestCleanup을 사용하여 각 테스트를 실행한 후에 코드를 실행합니다.
78 // public void MyTestCleanup() { }
84 public async Task AppShortcutGetInstalledAppsTest()
86 var installedApps = await controller.GetInstalledApps();
88 foreach (var app in installedApps)
90 Console.Out.WriteLine("App ID : " + app.AppID);
91 Console.Out.WriteLine("Installed Date : " + app.Installed);
93 // Err : CurrentStateDescription should not be null
94 Assert.AreNotEqual(app.CurrentStateDescription, null,
95 "StateDescription CurrentStateDescription is null!!!");
97 // Err : removable app property check
98 if (app.CurrentStateDescription.Label.Contains("removable") &&
99 app.IsRemovable == false)
101 Assert.Fail("Removable is failed");
104 // Err : Invalid state description removing.
105 if (app.CurrentStateDescription.Label.Contains("invalid"))
107 Assert.Fail("Invalid App Shortcut included!!!");
113 public void AppShortcutGetDefaultShortcutsTest()
115 var defaultShortcuts = controller.GetDefaultShortcuts();
117 // Req : Order of default shortcuts is All apps > Media Hub > Add pin
118 Assert.AreNotEqual(defaultShortcuts.ElementAt(0).CurrentStateDescription,
119 null, "All Apps CurrentStateDescription is invalid!!!");
120 Assert.AreEqual(defaultShortcuts.ElementAt(0).CurrentStateDescription.Label, AllApps);
122 Assert.AreNotEqual(defaultShortcuts.ElementAt(1).CurrentStateDescription,
123 null, "Media Hub CurrentStateDescription is invalid!!!");
124 Assert.AreEqual(defaultShortcuts.ElementAt(1).CurrentStateDescription.Label, MediaHub);
126 Assert.AreNotEqual(defaultShortcuts.ElementAt(2).CurrentStateDescription,
127 null, "Add pin CurrentStateDescription is invalid!!!");
128 Assert.AreEqual(defaultShortcuts.ElementAt(2).CurrentStateDescription.Label, AddPin);
132 public async Task AppShortcutGetPinnedAppsWithDefaultShortcutsTest()
134 var pinnedApps = await controller.GetPinnedAppsWithDefaultShortcuts();
136 // Req : A Maximum number of pinned apps is 10. + All apps, Media Hub, Add pin
137 Assert.IsTrue(pinnedApps.Count() <= 13, "A Maximum number of pinned apps is 10!!! NOT " + pinnedApps.Count());
139 // Req : Order of default shortcuts is All apps > Media Hub > Add pin
140 Assert.AreNotEqual(pinnedApps.ElementAt(0).CurrentStateDescription,
141 null, "All Apps CurrentStateDescription is invalid!!!");
142 Assert.AreEqual(pinnedApps.ElementAt(0).CurrentStateDescription.Label, AllApps);
144 Assert.AreNotEqual(pinnedApps.ElementAt(1).CurrentStateDescription,
145 null, "Media Hub CurrentStateDescription is invalid!!!");
146 Assert.AreEqual(pinnedApps.ElementAt(1).CurrentStateDescription.Label, MediaHub);
148 Assert.AreNotEqual(pinnedApps.ElementAt(pinnedApps.Count() - 1).CurrentStateDescription,
149 null, "Add pin CurrentStateDescription is invalid!!!");
150 Assert.AreEqual(pinnedApps.ElementAt(pinnedApps.Count() - 1).CurrentStateDescription.Label, AddPin);
152 foreach (var shortcut in pinnedApps)
154 // Err : shortcut should be AppShortcutInfo
155 if ((shortcut is AppShortcutInfo) == false)
157 Assert.Fail("Invalid ShortCut type!!!");
160 var app = shortcut as AppShortcutInfo;
162 Console.Out.WriteLine("ID : " + app.AppID);
163 Console.Out.WriteLine("Label : " + app.CurrentStateDescription.Label);
164 Console.Out.WriteLine("Installed : " + app.Installed);
166 // Err : CurrentStateDescription should not be null
167 Assert.AreNotEqual(app.CurrentStateDescription, null,
168 "StateDescription CurrentStateDescription is null!!!");
170 // Err : Both ID and Label should not be null
171 Assert.IsFalse((app.AppID == null || app.AppID.Length < 1) &&
172 (app.CurrentStateDescription.Label == null || app.CurrentStateDescription.Label.Length < 1),
173 "Both ID and Label should not be null!!!");
175 // Err : AppID should be exist
176 if (app.AppID == null)
178 if (app.CurrentStateDescription.Label.CompareTo(AllApps) != 0 &&
179 app.CurrentStateDescription.Label.CompareTo(MediaHub) != 0 &&
180 app.CurrentStateDescription.Label.CompareTo(AddPin) != 0)
182 Assert.Fail("App ID is missing!!! " + app.CurrentStateDescription.Label);
187 // Req : TVHome, TVApps, MediaHub, Settings should not be pinned.
188 Assert.IsFalse(app.AppID.Contains("xahome"), "TVHome should not be pinned");
189 Assert.IsFalse(app.AppID.Contains("xaapps"), "TVApps should not be pinned");
190 Assert.IsFalse(app.AppID.Contains("xamediahub"), "MediaHub should not be pinned");
191 Assert.IsFalse(app.AppID.Contains("settings"), "Settings should not be pinned");
194 // Err : removable app property check
195 if (app.CurrentStateDescription.Label.Contains("removable") &&
196 app.IsRemovable == false)
198 Assert.Fail("Removable is failed");
201 // Err : Invalid state description removing.
202 if (app.CurrentStateDescription.Label.Contains("invalid"))
204 Assert.Fail("Invalid App Shortcut included!!!");
210 public async Task AppShortcutGetPinnedAppsAppIDsTest()
212 var pinnedAppsIDs = await controller.GetPinnedAppsAppIDs();
214 // Req : A Maximum number of pinned apps is 10.
215 Assert.IsTrue(pinnedAppsIDs.Count() <= 10,
216 "A Maximum number of pinned apps is 10!!! NOT " + pinnedAppsIDs.Count());
218 foreach (var appID in pinnedAppsIDs.Keys)
220 // Err : AppID should not be null or empty.
221 Assert.AreNotEqual(appID, null, "App ID should not be null");
222 Assert.IsFalse(appID.Length < 1, "App ID should not be empty");
224 // Req : TVHome, TVApps, MediaHub, Settings should not be pinned.
225 Assert.IsFalse(appID.Contains("xahome"), "TVHome should not be pinned");
226 Assert.IsFalse(appID.Contains("xaapps"), "TVApps should not be pinned");
227 Assert.IsFalse(appID.Contains("xamediahub"), "MediaHub should not be pinned");
228 Assert.IsFalse(appID.Contains("settings"), "Settings should not be pinned");