Add Test cases for app shortcut, managedapps
[profile/tv/apps/dotnet/home.git] / HomeUnitTest / AppShortcutTestCases.cs
1 /*
2  * Copyright (c) 2017 Samsung Electronics Co., Ltd
3  *
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
7  *
8  *     http://floralicense.org/license/
9  *
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.
15  */
16
17 using System;
18 using Microsoft.VisualStudio.TestTools.UnitTesting;
19 using LibTVRefCommonPortable.Models;
20 using System.Threading.Tasks;
21 using System.Linq;
22 using LibTVRefCommonPortable.DataModels;
23
24 namespace HomeUnitTest
25 {
26     /// <summary>
27     /// A test cases for AppShortcutController
28     /// </summary>
29     [TestClass]
30     public class AppShortcutTestCases
31     {
32         /// <summary>
33         /// A instance of AppShortcutController
34         /// </summary>
35         private AppShortcutController controller;
36
37         /// <summary>
38         /// All Apps app shortcut name
39         /// </summary>
40         private static readonly string AllApps = "All apps";
41
42         /// <summary>
43         /// MediaHub app shortcut name
44         /// </summary>
45         private static readonly string MediaHub = "Media Hub";
46
47         /// <summary>
48         /// Add pin app shortcut name
49         /// </summary>
50         private static readonly string AddPin = "Add pin";
51
52         /// <summary>
53         /// A constructor that initialize AppShortcutController instance.
54         /// </summary>
55         public AppShortcutTestCases()
56         {
57             controller = new AppShortcutController();
58         }
59
60         #region 추가 테스트 특성
61         //
62         // 테스트를 작성할 때 다음 추가 특성을 사용할 수 있습니다.
63         //
64         // ClassInitialize를 사용하여 클래스의 첫 번째 테스트를 실행하기 전에 코드를 실행합니다.
65         // [ClassInitialize()]
66         // public static void MyClassInitialize(TestContext testContext) { }
67         //
68         // ClassCleanup을 사용하여 클래스의 테스트를 모두 실행한 후에 코드를 실행합니다.
69         // [ClassCleanup()]
70         // public static void MyClassCleanup() { }
71         //
72         // TestInitialize를 사용하여 각 테스트를 실행하기 전에 코드를 실행합니다.
73         // [TestInitialize()]
74         // public void MyTestInitialize() { }
75         //
76         // TestCleanup을 사용하여 각 테스트를 실행한 후에 코드를 실행합니다.
77         // [TestCleanup()]
78         // public void MyTestCleanup() { }
79         //
80         #endregion
81
82
83         [TestMethod]
84         public async Task AppShortcutGetInstalledAppsTest()
85         {
86             var installedApps = await controller.GetInstalledApps();
87
88             foreach (var app in installedApps)
89             {
90                 Console.Out.WriteLine("App ID : " + app.AppID);
91                 Console.Out.WriteLine("Installed Date : " + app.Installed);
92
93                 // Err : CurrentStateDescription should not be null
94                 Assert.AreNotEqual(app.CurrentStateDescription, null,
95                     "StateDescription CurrentStateDescription is null!!!");
96
97                 // Err : removable app property check
98                 if (app.CurrentStateDescription.Label.Contains("removable") &&
99                     app.IsRemovable == false)
100                 {
101                     Assert.Fail("Removable is failed");
102                 }
103
104                 // Err : Invalid state description removing.
105                 if (app.CurrentStateDescription.Label.Contains("invalid"))
106                 {
107                     Assert.Fail("Invalid App Shortcut included!!!");
108                 }
109             }
110         }
111
112         [TestMethod]
113         public void AppShortcutGetDefaultShortcutsTest()
114         {
115             var defaultShortcuts = controller.GetDefaultShortcuts();
116
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);
121
122             Assert.AreNotEqual(defaultShortcuts.ElementAt(1).CurrentStateDescription,
123                 null, "Media Hub CurrentStateDescription is invalid!!!");
124             Assert.AreEqual(defaultShortcuts.ElementAt(1).CurrentStateDescription.Label, MediaHub);
125
126             Assert.AreNotEqual(defaultShortcuts.ElementAt(2).CurrentStateDescription,
127                 null, "Add pin CurrentStateDescription is invalid!!!");
128             Assert.AreEqual(defaultShortcuts.ElementAt(2).CurrentStateDescription.Label, AddPin);
129         }
130
131         [TestMethod]
132         public async Task AppShortcutGetPinnedAppsWithDefaultShortcutsTest()
133         {
134             var pinnedApps = await controller.GetPinnedAppsWithDefaultShortcuts();
135
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());
138
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);
143
144             Assert.AreNotEqual(pinnedApps.ElementAt(1).CurrentStateDescription,
145                 null, "Media Hub CurrentStateDescription is invalid!!!");
146             Assert.AreEqual(pinnedApps.ElementAt(1).CurrentStateDescription.Label, MediaHub);
147
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);
151
152             foreach (var shortcut in pinnedApps)
153             {
154                 // Err : shortcut should be AppShortcutInfo
155                 if ((shortcut is AppShortcutInfo) == false)
156                 {
157                     Assert.Fail("Invalid ShortCut type!!!");
158                 }
159
160                 var app = shortcut as AppShortcutInfo;
161
162                 Console.Out.WriteLine("ID : " + app.AppID);
163                 Console.Out.WriteLine("Label : " + app.CurrentStateDescription.Label);
164                 Console.Out.WriteLine("Installed : " + app.Installed);
165
166                 // Err : CurrentStateDescription should not be null
167                 Assert.AreNotEqual(app.CurrentStateDescription, null,
168                     "StateDescription CurrentStateDescription is null!!!");
169
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!!!");
174
175                 // Err : AppID should be exist
176                 if (app.AppID == null)
177                 {
178                     if (app.CurrentStateDescription.Label.CompareTo(AllApps) != 0 &&
179                         app.CurrentStateDescription.Label.CompareTo(MediaHub) != 0 &&
180                         app.CurrentStateDescription.Label.CompareTo(AddPin) != 0)
181                     {
182                         Assert.Fail("App ID is missing!!! " + app.CurrentStateDescription.Label);
183                     }
184                 }
185                 else
186                 {
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");
192                 }
193
194                 // Err : removable app property check
195                 if (app.CurrentStateDescription.Label.Contains("removable") &&
196                     app.IsRemovable == false)
197                 {
198                     Assert.Fail("Removable is failed");
199                 }
200
201                 // Err : Invalid state description removing.
202                 if (app.CurrentStateDescription.Label.Contains("invalid"))
203                 {
204                     Assert.Fail("Invalid App Shortcut included!!!");
205                 }
206             }
207         }
208
209         [TestMethod]
210         public async Task AppShortcutGetPinnedAppsAppIDsTest()
211         {
212             var pinnedAppsIDs = await controller.GetPinnedAppsAppIDs();
213
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());
217
218             foreach (var appID in pinnedAppsIDs.Keys)
219             {
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");
223
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");
229             }
230         }
231     }
232 }