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