1 | using System;
|
---|
2 |
|
---|
3 | using System.Collections.Generic;
|
---|
4 |
|
---|
5 | using HeuristicLab.Services.Authentication.DataTransfer;
|
---|
6 |
|
---|
7 |
|
---|
8 | namespace HeuristicLab.Services.Authentication.TestClient
|
---|
9 | {
|
---|
10 | class TestClient
|
---|
11 | {
|
---|
12 | static void Main(string[] args)
|
---|
13 | {
|
---|
14 |
|
---|
15 |
|
---|
16 |
|
---|
17 | AuthenticationService auth = new AuthenticationService();
|
---|
18 |
|
---|
19 | try
|
---|
20 | {
|
---|
21 |
|
---|
22 |
|
---|
23 | //Console.WriteLine("Insert new application");
|
---|
24 | //Application app1 = new Application() { ApplicationName="SPR Application", Description="SPR Application"};
|
---|
25 | //app1 = auth.InsertApplication(app1);
|
---|
26 |
|
---|
27 | //if (app1 != null)
|
---|
28 | //{
|
---|
29 | // Console.WriteLine("okay");
|
---|
30 | //}
|
---|
31 | //else
|
---|
32 | //{
|
---|
33 | // Console.WriteLine("error");
|
---|
34 | //}
|
---|
35 | //Console.WriteLine("--------------------------");
|
---|
36 |
|
---|
37 | //Console.WriteLine("Insert user SPRTEST");
|
---|
38 | //Membership membership = new Membership() { Email="aaa@bbb.com", Password="aaa", PasswordAnswer="bar", PasswordQuestion="foo?", PasswordSalt="aaa"};
|
---|
39 | //User user1 = new User(){ UserName="SPRTEST", IsAnonymous=false, LastActivityDate=DateTime.Now, ApplicationId=app1.ApplicationId, Membership=membership};
|
---|
40 | //auth.InsertUser(user1);
|
---|
41 | //Console.WriteLine("--------------------------");
|
---|
42 |
|
---|
43 | //Console.WriteLine("Get user SPRTEST");
|
---|
44 | //User user2 = auth.GetUser(app1.ApplicationId, "SPRTEST");
|
---|
45 | //if (user2 != null)
|
---|
46 | //{
|
---|
47 | // Console.WriteLine("id=" + user2.UserId);
|
---|
48 | //}
|
---|
49 | //else
|
---|
50 | //{
|
---|
51 | // Console.WriteLine("not found!");
|
---|
52 | //}
|
---|
53 | //Console.WriteLine("--------------------------");
|
---|
54 |
|
---|
55 |
|
---|
56 | //Console.WriteLine("Get user Einstein");
|
---|
57 | //User user3 = auth.GetUser(app1.ApplicationId, "Einstein");
|
---|
58 | //if (user3 != null)
|
---|
59 | //{
|
---|
60 | // Console.WriteLine("id=" + user2.UserId);
|
---|
61 | //}
|
---|
62 | //else
|
---|
63 | //{
|
---|
64 | // Console.WriteLine("not found!");
|
---|
65 | //}
|
---|
66 | //Console.WriteLine("--------------------------");
|
---|
67 |
|
---|
68 |
|
---|
69 | //Console.WriteLine("Insert role Role1");
|
---|
70 | //Role role1 = new Role() { RoleName = "Role1", Description = "first test role", ApplicationId = app1.ApplicationId };
|
---|
71 |
|
---|
72 | //if (auth.InsertRole(role1))
|
---|
73 | //{
|
---|
74 | // Console.WriteLine("okay");
|
---|
75 | //}
|
---|
76 | //else
|
---|
77 | //{
|
---|
78 | // Console.WriteLine("error");
|
---|
79 | //}
|
---|
80 | //Console.WriteLine("--------------------------");
|
---|
81 |
|
---|
82 | //Console.WriteLine("Get Role Role1");
|
---|
83 | //Role role2 = auth.GetRole(app1.ApplicationId, "Role1");
|
---|
84 | //if (role2 != null)
|
---|
85 | //{
|
---|
86 | // Console.WriteLine("id=" + role2.RoleId);
|
---|
87 | //}
|
---|
88 | //else
|
---|
89 | //{
|
---|
90 | // Console.WriteLine("not found!");
|
---|
91 | //}
|
---|
92 | //Console.WriteLine("--------------------------");
|
---|
93 | //Console.WriteLine("Get Role Role2");
|
---|
94 | //Role role3 = auth.GetRole(app1.ApplicationId, "Role2");
|
---|
95 | //if (role3 != null)
|
---|
96 | //{
|
---|
97 | // Console.WriteLine("id=" + role3.RoleId);
|
---|
98 | //}
|
---|
99 | //else
|
---|
100 | //{
|
---|
101 | // Console.WriteLine("not found!");
|
---|
102 | //}
|
---|
103 | //Console.WriteLine("--------------------------");
|
---|
104 |
|
---|
105 |
|
---|
106 | //Console.WriteLine("GetRoles");
|
---|
107 | //IEnumerable<Role> list3 = auth.GetRoles(app1.ApplicationId);
|
---|
108 |
|
---|
109 | //foreach (Role role in list3)
|
---|
110 | //{
|
---|
111 | // Console.WriteLine(role.RoleName);
|
---|
112 | //}
|
---|
113 | //Console.WriteLine("--------------------------");
|
---|
114 | //Console.WriteLine("Is User SPRTEST In Role1");
|
---|
115 | //if (auth.IsUserInRole(role2.RoleId, user2.UserId))
|
---|
116 | //{
|
---|
117 | // Console.WriteLine("true");
|
---|
118 | //}
|
---|
119 | //else
|
---|
120 | //{
|
---|
121 | // Console.WriteLine("false");
|
---|
122 | //}
|
---|
123 | //Console.WriteLine("--------------------------");
|
---|
124 |
|
---|
125 |
|
---|
126 |
|
---|
127 | //Console.WriteLine("Add User SPRTEST To Role1");
|
---|
128 | //if (auth.AddUserToRole(role2.RoleId, user2.UserId))
|
---|
129 | //{
|
---|
130 | // Console.WriteLine("okay");
|
---|
131 | //}
|
---|
132 | //else
|
---|
133 | //{
|
---|
134 | // Console.WriteLine("error");
|
---|
135 | //}
|
---|
136 | //Console.WriteLine("--------------------------");
|
---|
137 |
|
---|
138 | //Console.WriteLine("Is User SPRTEST In Role1");
|
---|
139 | //if (auth.IsUserInRole(role2.RoleId, user2.UserId))
|
---|
140 | //{
|
---|
141 | // Console.WriteLine("true");
|
---|
142 | //}
|
---|
143 | //else
|
---|
144 | //{
|
---|
145 | // Console.WriteLine("false");
|
---|
146 | //}
|
---|
147 | //Console.WriteLine("--------------------------");
|
---|
148 |
|
---|
149 | //Console.WriteLine("Add User SPRTEST To Role2");
|
---|
150 | //if (role3 != null && auth.AddUserToRole(role3.RoleId, user2.UserId))
|
---|
151 | //{
|
---|
152 | // Console.WriteLine("okay");
|
---|
153 | //}
|
---|
154 | //else
|
---|
155 | //{
|
---|
156 | // Console.WriteLine("error");
|
---|
157 | //}
|
---|
158 | //Console.WriteLine("--------------------------");
|
---|
159 |
|
---|
160 |
|
---|
161 |
|
---|
162 | //IEnumerable<User> list1 = auth.GetUsers(app1.ApplicationId);
|
---|
163 | //Console.WriteLine("Get Users");
|
---|
164 | //foreach (var item in list1)
|
---|
165 | //{
|
---|
166 | // Console.WriteLine( item.UserName);
|
---|
167 | //}
|
---|
168 |
|
---|
169 | //Console.WriteLine("--------------------------");
|
---|
170 | //User user4 = auth.GetUser(app1.ApplicationId, "SPRTEST");
|
---|
171 | //if (user4 != null)
|
---|
172 | //{
|
---|
173 | // IEnumerable<Role> roles = auth.GetRolesForUser(user4.UserId);
|
---|
174 | // Console.WriteLine("Get Roles for user SPRTEST");
|
---|
175 | // foreach (Role r in roles)
|
---|
176 | // {
|
---|
177 | // Console.WriteLine(r.RoleName);
|
---|
178 | // }
|
---|
179 | //}
|
---|
180 | ///*
|
---|
181 | //Console.WriteLine("--------------------------");
|
---|
182 | //Console.WriteLine("Remove SPRTEST From Role1");
|
---|
183 | //if (auth.RemoveUserFromRole(role2.RoleId, user4.UserId))
|
---|
184 | //{
|
---|
185 | // Console.WriteLine("okay");
|
---|
186 | //}
|
---|
187 | //else
|
---|
188 | //{
|
---|
189 | // Console.WriteLine("error");
|
---|
190 | //}
|
---|
191 | //*/
|
---|
192 | //Console.WriteLine("--------------------------");
|
---|
193 | //User user5 = auth.GetUser(app1.ApplicationId, "SPRTEST");
|
---|
194 | //if (user5 != null)
|
---|
195 | //{
|
---|
196 | // IEnumerable<Role> roles = auth.GetRolesForUser(user5.UserId);
|
---|
197 | // Console.WriteLine("Get Roles for user SPRTEST");
|
---|
198 | // foreach (Role r in roles)
|
---|
199 | // {
|
---|
200 | // Console.WriteLine(r.RoleName);
|
---|
201 | // }
|
---|
202 | //}
|
---|
203 | ///*
|
---|
204 | //Console.WriteLine("--------------------------");
|
---|
205 | //Console.WriteLine("Delete User SPRTEST");
|
---|
206 | //if (auth.DeleteUser(user4.UserId))
|
---|
207 | //{
|
---|
208 | // Console.WriteLine("okay");
|
---|
209 | //}
|
---|
210 | //else
|
---|
211 | //{
|
---|
212 | // Console.WriteLine("error");
|
---|
213 | //}
|
---|
214 | //Console.WriteLine("--------------------------");
|
---|
215 | //*/
|
---|
216 | //IEnumerable<User> list2 = auth.GetUsers(app1.ApplicationId);
|
---|
217 | //Console.WriteLine("Get Users");
|
---|
218 | //foreach (var item in list2)
|
---|
219 | //{
|
---|
220 | // Console.WriteLine(item.UserName);
|
---|
221 | //}
|
---|
222 |
|
---|
223 | //Console.WriteLine("--------------------------");
|
---|
224 | //Console.WriteLine("Update user SPRTEST");
|
---|
225 | //User user6 = auth.GetUser(app1.ApplicationId,"SPRTEST");
|
---|
226 |
|
---|
227 | //if (user6 != null)
|
---|
228 | //{
|
---|
229 | // user6.LoweredUserName = "new lowered name";
|
---|
230 | // user6.Membership.Email = "new email";
|
---|
231 | // auth.UpdateUser(user6);
|
---|
232 | //}
|
---|
233 |
|
---|
234 |
|
---|
235 |
|
---|
236 |
|
---|
237 | }
|
---|
238 | catch (Exception e)
|
---|
239 | {
|
---|
240 | Console.WriteLine(e.Message);
|
---|
241 | }
|
---|
242 |
|
---|
243 | // User form
|
---|
244 |
|
---|
245 | System.Windows.Forms.Application.Run(new UserManagement());
|
---|
246 |
|
---|
247 | }
|
---|
248 | }
|
---|
249 | }
|
---|