Fixing other null-refs
[profile/tv/apps/dotnet/home.git] / LibCommon.Shared / Stubs / ApplicationManagerAPITestStub.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 LibTVRefCommonPortable.Utils;
18 using System;
19 using System.Collections.Generic;
20 using System.Threading.Tasks;
21
22 namespace LibTVRefCommonPortable.Stubs
23 {
24     /// <summary>
25     /// A unit testing stub of IApplicationManagerAPIs.
26     /// </summary>
27     public class ApplicationManagerAPITestStub : IApplicationManagerAPIs
28     {
29         /// <summary>
30         /// A method provides installed application list.
31         /// </summary>
32         /// <returns>An installed application list</returns>
33         public Task<IEnumerable<InstalledApp>> GetAllInstalledApplication()
34         {
35             return Task.Run(() =>
36             {
37                 List<InstalledApp> installedApps = new List<InstalledApp>();
38
39                 installedApps.Add(new InstalledApp
40                 {
41                     Applabel = "app1",
42                     AppID = "app1",
43                     IconPath = "path/app1",
44                     InstalledTime = new DateTime(2017, 05, 02),
45                 });
46
47                 installedApps.Add(new InstalledApp
48                 {
49                     Applabel = "app2.removable",
50                     AppID = "app2.removable",
51                     IconPath = "path/app2",
52                     InstalledTime = new DateTime(2017, 05, 02),
53                 });
54
55                 installedApps.Add(new InstalledApp
56                 {
57                     Applabel = "invalid.app3.noid",
58                     IconPath = "path/app3",
59                     InstalledTime = new DateTime(2017, 05, 02),
60                 });
61
62                 installedApps.Add(new InstalledApp
63                 {
64                     Applabel = "app4.noicon",
65                     AppID = "app4.noicon",
66                     InstalledTime = new DateTime(2017, 05, 02),
67                 });
68
69                 installedApps.Add(new InstalledApp
70                 {
71                     Applabel = "app5.nolabel",
72                     AppID = "app5.nolabel",
73                     IconPath = "path/app5",
74                     InstalledTime = new DateTime(2017, 05, 02),
75                 });
76
77                 installedApps.Add(new InstalledApp
78                 {
79                     Applabel = "invalid.org.tizen.xahome",
80                     AppID = "org.tizen.xahome",
81                     IconPath = "path/app3",
82                     InstalledTime = new DateTime(2017, 05, 02),
83                 });
84
85                 installedApps.Add(new InstalledApp
86                 {
87                     Applabel = "invalid.org.tizen.xaapps",
88                     AppID = "org.tizen.xaapps",
89                     IconPath = "path/app4",
90                     InstalledTime = new DateTime(2017, 05, 02),
91                 });
92
93                 installedApps.Add(new InstalledApp
94                 {
95                     Applabel = "invalid.org.tizen.xamediahub",
96                     AppID = "org.tizen.xamediahub",
97                     IconPath = "path/app5",
98                     InstalledTime = new DateTime(2017, 05, 02),
99                 });
100
101                 installedApps.Add(new InstalledApp
102                 {
103                     Applabel = "invalid.org.tizen.settings",
104                     AppID = "org.tizen.settings",
105                     IconPath = "path/app6",
106                     InstalledTime = new DateTime(2017, 05, 02),
107                 });
108
109                 return (IEnumerable<InstalledApp>)installedApps;
110             });
111         }
112
113         /// <summary>
114         /// Gets the app ID by the app label
115         /// </summary>
116         /// <param name="appLabel">the app label to get</param>
117         /// <returns>the app ID of the app label</returns>
118         public Task<string> GetAppIDbyAppLabel(string appLabel)
119         {
120             throw new NotImplementedException();
121         }
122
123         /// <summary>
124         /// Checks whether application is removable
125         /// </summary>
126         /// <param name="appID">The app ID to get</param>
127         /// <returns>If the application is removable, true; otherwise, false</returns>
128         public bool GetAppInfoRemovable(string appID)
129         {
130             return appID.Contains("removable");
131         }
132
133         /// <summary>
134         /// A method provides application information which is matched with the given app ID.
135         /// </summary>
136         /// <param name="applicationId">An application ID</param>
137         /// <returns>An installed application information</returns>
138         public InstalledApp GetInstalledApplication(string applicationId)
139         {
140             return new InstalledApp
141             {
142                 AppID = applicationId,
143                 Applabel = applicationId,
144                 IconPath = "path/" + applicationId,
145                 InstalledTime = DateUtils.GetRandomDate(),
146             };
147         }
148     }
149 }