[4953] | 1 | using System;
|
---|
| 2 | using System.Text;
|
---|
| 3 | using System.Collections.Generic;
|
---|
| 4 | using System.Linq;
|
---|
| 5 | using Microsoft.VisualStudio.TestTools.UnitTesting;
|
---|
[5004] | 6 | using HeuristicLab.Services.Authentication;
|
---|
| 7 | using HL = HeuristicLab.Services.Authentication;
|
---|
| 8 | using DA = HeuristicLab.Services.Authentication.DataAccess;
|
---|
| 9 | using DT = HeuristicLab.Services.Authentication.DataTransfer;
|
---|
| 10 | using System.Data;
|
---|
| 11 | using System.Data.Common;
|
---|
| 12 | using System.Data.Linq;
|
---|
| 13 | using System.Collections;
|
---|
[4953] | 14 |
|
---|
[5004] | 15 | namespace TestWebService {
|
---|
| 16 | [TestClass]
|
---|
| 17 | public class WebserviceUnitTest {
|
---|
[4953] | 18 |
|
---|
[5004] | 19 | private string sqlCountClients = @"SELECT COUNT(*) FROM Resource where ResourceType = 'Client'";
|
---|
| 20 | private string sqlCountGroups = @"SELECT COUNT(*) FROM Resource where ResourceType = 'ResourceGroup'";
|
---|
| 21 |
|
---|
| 22 | #region TestIdsAndNames
|
---|
| 23 | private Guid groupID1 = Guid.NewGuid();
|
---|
| 24 | private string groupName1 = "groupName1";
|
---|
| 25 | private Guid groupID2 = Guid.NewGuid();
|
---|
| 26 | private string groupName2 = "groupName2";
|
---|
| 27 | private Guid groupID3 = Guid.NewGuid();
|
---|
| 28 | private string groupName3 = "groupName3";
|
---|
| 29 |
|
---|
| 30 | private Guid clientID1 = Guid.NewGuid();
|
---|
| 31 | private string clientName1 = "clientName1";
|
---|
| 32 | private Guid clientID2 = Guid.NewGuid();
|
---|
| 33 | private string clientName2 = "clientName2";
|
---|
| 34 | #endregion
|
---|
| 35 |
|
---|
| 36 | #region ValidationMethods
|
---|
| 37 | class ClientEqualityComparer : IEqualityComparer<DT.Client> {
|
---|
| 38 | public bool Equals(DT.Client c1, DT.Client c2) {
|
---|
| 39 | return (
|
---|
| 40 | c1.Name == c2.Name &&
|
---|
| 41 | c1.Id == c2.Id &&
|
---|
| 42 | c1.Description == c2.Description &&
|
---|
| 43 | c1.IPAdress == c2.IPAdress &&
|
---|
| 44 | c1.NumberOfProcessors == c2.NumberOfProcessors &&
|
---|
| 45 | c1.NumberOfThreads == c2.NumberOfThreads &&
|
---|
| 46 | c1.OperatingSystem == c2.OperatingSystem &&
|
---|
| 47 | c1.ProcessorType == c2.ProcessorType
|
---|
| 48 | );
|
---|
| 49 | }
|
---|
| 50 |
|
---|
| 51 | public int GetHashCode(DT.Client obj) {
|
---|
| 52 | throw new NotImplementedException();
|
---|
| 53 | }
|
---|
[4953] | 54 | }
|
---|
[5004] | 55 |
|
---|
| 56 | class ResourceGroupEqualityComparer : IEqualityComparer<DT.ResourceGroup> {
|
---|
| 57 | public bool Equals(DT.ResourceGroup rg1, DT.ResourceGroup rg2) {
|
---|
| 58 | return (
|
---|
| 59 | rg1.Name == rg2.Name &&
|
---|
| 60 | rg1.Id == rg2.Id &&
|
---|
| 61 | rg1.Description == rg2.Description
|
---|
| 62 | );
|
---|
| 63 | }
|
---|
| 64 |
|
---|
| 65 | public int GetHashCode(DT.ResourceGroup obj) {
|
---|
| 66 | throw new NotImplementedException();
|
---|
| 67 | }
|
---|
| 68 | }
|
---|
| 69 |
|
---|
[5335] | 70 | class ResourceEqualityComparer : IEqualityComparer<DT.Resource> {
|
---|
| 71 | public bool Equals(DT.Resource rg1, DT.Resource rg2) {
|
---|
| 72 | return (
|
---|
| 73 | rg1.Name == rg2.Name &&
|
---|
| 74 | rg1.Id == rg2.Id
|
---|
| 75 | );
|
---|
| 76 | }
|
---|
| 77 |
|
---|
| 78 | public int GetHashCode(DT.Resource obj) {
|
---|
| 79 | throw new NotImplementedException();
|
---|
| 80 | }
|
---|
| 81 | }
|
---|
| 82 |
|
---|
[5004] | 83 | private bool CompareClients(DT.Client c1, DT.Client c2) {
|
---|
| 84 | return (
|
---|
| 85 | c1.Name == c2.Name &&
|
---|
| 86 | c1.Id == c2.Id &&
|
---|
[5335] | 87 | c1.ResourceType == c2.ResourceType &&
|
---|
[5004] | 88 | c1.Description == c2.Description &&
|
---|
| 89 | c1.IPAdress == c2.IPAdress &&
|
---|
| 90 | c1.NumberOfProcessors == c2.NumberOfProcessors &&
|
---|
| 91 | c1.NumberOfThreads == c2.NumberOfThreads &&
|
---|
| 92 | c1.OperatingSystem == c2.OperatingSystem &&
|
---|
| 93 | c1.ProcessorType == c2.ProcessorType
|
---|
| 94 | );
|
---|
| 95 | }
|
---|
| 96 |
|
---|
| 97 | private bool CompareGroups(DT.ResourceGroup r1, DT.ResourceGroup r2) {
|
---|
| 98 | return (
|
---|
| 99 | r1.Name == r2.Name &&
|
---|
| 100 | r1.Id == r2.Id &&
|
---|
| 101 | //c1.ResourceType == c2.ResourceType &&
|
---|
| 102 | r1.Description == r2.Description
|
---|
| 103 | );
|
---|
| 104 | }
|
---|
| 105 |
|
---|
[5335] | 106 | private bool CompareResources(DT.Resource r1, DT.Resource r2) {
|
---|
| 107 | return (
|
---|
| 108 | r1.Name == r2.Name &&
|
---|
| 109 | r1.Id == r2.Id
|
---|
| 110 | );
|
---|
| 111 | }
|
---|
| 112 |
|
---|
[5004] | 113 | private static int GetNumberOfEntries(string sqlCommand) {
|
---|
| 114 | DA.ClientManagmentDataContext dc = new DA.ClientManagmentDataContext();
|
---|
| 115 | try {
|
---|
| 116 | IEnumerable<int> cnt = dc.ExecuteQuery<int>(sqlCommand);
|
---|
| 117 | return (int)cnt.First();
|
---|
| 118 | }
|
---|
| 119 | catch (Exception e) {
|
---|
| 120 | return 0;
|
---|
| 121 | }
|
---|
| 122 | }
|
---|
| 123 | #endregion
|
---|
| 124 |
|
---|
| 125 | #region PublicResources
|
---|
| 126 | DA.ClientManagmentDataContext dc = null;
|
---|
| 127 |
|
---|
| 128 | public DT.Client cl1 = null;
|
---|
| 129 | public DT.Client cl2 = null;
|
---|
| 130 | public DT.Client cl3 = null;
|
---|
| 131 |
|
---|
| 132 | public DT.ResourceGroup rg1 = null;
|
---|
| 133 | public DT.ResourceGroup rg2 = null;
|
---|
| 134 | public DT.ResourceGroup rg3 = null;
|
---|
| 135 |
|
---|
| 136 | public DA.ResourceResourceGroup rrg1 = null;
|
---|
| 137 | public DA.ResourceResourceGroup rrg2 = null;
|
---|
| 138 | public DA.ResourceResourceGroup rrg3 = null;
|
---|
[5335] | 139 | public DA.ResourceResourceGroup rrg4 = null;
|
---|
| 140 | public DA.ResourceResourceGroup rrg5 = null;
|
---|
[5004] | 141 | #endregion
|
---|
[5335] | 142 |
|
---|
[5004] | 143 | #region Additional test attributes
|
---|
| 144 | //
|
---|
| 145 | // You can use the following additional attributes as you write your tests:
|
---|
| 146 | //
|
---|
| 147 | // Use ClassInitialize to run code before running the first test in the class
|
---|
| 148 | // [ClassInitialize()]
|
---|
| 149 | // public static void MyClassInitialize(TestContext testContext) { }
|
---|
| 150 | //
|
---|
| 151 | // Use ClassCleanup to run code after all tests in a class have run
|
---|
| 152 | // [ClassCleanup()]
|
---|
| 153 | // public static void MyClassCleanup() { }
|
---|
| 154 | //
|
---|
| 155 | // Use TestInitialize to run code before running each test
|
---|
| 156 | // [TestInitialize()]
|
---|
| 157 | // public void MyTestInitialize() { }
|
---|
| 158 | //
|
---|
| 159 | // Use TestCleanup to run code after each test has run
|
---|
| 160 | // c
|
---|
| 161 | // public void MyTestCleanup() { }
|
---|
| 162 | //
|
---|
| 163 | #endregion
|
---|
| 164 |
|
---|
| 165 | [TestInitialize()]
|
---|
[5335] | 166 | public void Init() {
|
---|
[5004] | 167 |
|
---|
| 168 | dc = new DA.ClientManagmentDataContext();
|
---|
| 169 | if (dc.DatabaseExists()) {
|
---|
| 170 | //dc.DeleteDatabase();
|
---|
| 171 | dc.ExecuteCommand("delete from ResourceResourceGroup");
|
---|
| 172 | dc.ExecuteCommand("delete from Resource");
|
---|
| 173 | dc.SubmitChanges();
|
---|
| 174 | }
|
---|
| 175 | else {
|
---|
| 176 | dc.CreateDatabase();
|
---|
| 177 | dc.SubmitChanges();
|
---|
| 178 | }
|
---|
| 179 |
|
---|
[5335] | 180 |
|
---|
[5004] | 181 | // create groups
|
---|
| 182 | rg1 = new DT.ResourceGroup();
|
---|
| 183 | rg1.Name = groupName1;
|
---|
[5335] | 184 | rg1.Id = groupID1;
|
---|
[5004] | 185 | rg1.Description = "descr rg1";
|
---|
| 186 | dc.GetTable<DA.Resource>().InsertOnSubmit(HL.Convert.ToEntity(rg1));
|
---|
| 187 |
|
---|
| 188 | rg2 = new DT.ResourceGroup();
|
---|
| 189 | rg2.Name = groupName2;
|
---|
| 190 | rg2.Id = groupID2;
|
---|
[5335] | 191 |
|
---|
| 192 | IList<Guid> rgList = new List<Guid>();
|
---|
| 193 | rgList.Add(rg1.Id);
|
---|
| 194 | rg2.ResourceGroup = rgList;
|
---|
| 195 |
|
---|
[5004] | 196 | rg2.Description = "descrrg2";
|
---|
| 197 | dc.GetTable<DA.Resource>().InsertOnSubmit(HL.Convert.ToEntity(rg2));
|
---|
| 198 |
|
---|
| 199 | rg3 = new DT.ResourceGroup();
|
---|
| 200 | rg3.Name = groupName3;
|
---|
| 201 | rg3.Id = groupID3;
|
---|
| 202 | rg3.Description = "descrrg3";
|
---|
| 203 | dc.GetTable<DA.Resource>().InsertOnSubmit(HL.Convert.ToEntity(rg3));
|
---|
| 204 |
|
---|
| 205 | // create clients
|
---|
| 206 | cl1 = new DT.Client();
|
---|
| 207 | cl1.Name = clientName1;
|
---|
| 208 | cl1.Id = clientID1;
|
---|
[5335] | 209 |
|
---|
| 210 | IList<Guid> rgList1 = new List<Guid>();
|
---|
| 211 | rgList.Add(groupID1);
|
---|
| 212 | cl1.ResourceGroup = rgList1;
|
---|
| 213 |
|
---|
[5004] | 214 | cl1.Description = "Test-PC-1";
|
---|
| 215 | cl1.IPAdress = "192.168.0.10";
|
---|
| 216 | cl1.NumberOfProcessors = "2";
|
---|
| 217 | cl1.NumberOfThreads = "4";
|
---|
| 218 | cl1.OperatingSystem = "WINXP";
|
---|
| 219 | cl1.MemorySize = "2048";
|
---|
| 220 | cl1.ProcessorType = "AMD";
|
---|
| 221 | dc.GetTable<DA.Resource>().InsertOnSubmit(HL.Convert.ToEntity(cl1));
|
---|
| 222 |
|
---|
| 223 | cl2 = new DT.Client();
|
---|
| 224 | cl2.Name = clientName2;
|
---|
| 225 | cl2.Id = clientID2;
|
---|
[5335] | 226 |
|
---|
| 227 | IList<Guid> rgList2 = new List<Guid>();
|
---|
| 228 | rgList.Add(groupID2);
|
---|
| 229 | cl2.ResourceGroup = rgList2;
|
---|
| 230 |
|
---|
[5004] | 231 | cl2.Description = "Test-PC-2";
|
---|
| 232 | cl2.IPAdress = "192.168.0.20";
|
---|
| 233 | cl2.NumberOfProcessors = "4";
|
---|
| 234 | cl2.NumberOfThreads = "4";
|
---|
| 235 | cl2.OperatingSystem = "Vista";
|
---|
| 236 | cl2.MemorySize = "4096";
|
---|
| 237 | cl2.ProcessorType = "Intel";
|
---|
| 238 | dc.GetTable<DA.Resource>().InsertOnSubmit(HL.Convert.ToEntity(cl2));
|
---|
| 239 |
|
---|
| 240 | // ResourceResourceGroups
|
---|
| 241 | rrg1 = new DA.ResourceResourceGroup();
|
---|
| 242 | rrg1.ResourceId = cl1.Id;
|
---|
| 243 | rrg1.ResourceGroupId = rg1.Id;
|
---|
| 244 | dc.GetTable<DA.ResourceResourceGroup>().InsertOnSubmit(rrg1);
|
---|
| 245 |
|
---|
[5335] | 246 | // ResourceResourceGroups
|
---|
| 247 | rrg5 = new DA.ResourceResourceGroup();
|
---|
| 248 | rrg5.ResourceId = cl1.Id;
|
---|
| 249 | rrg5.ResourceGroupId = rg2.Id;
|
---|
| 250 | dc.GetTable<DA.ResourceResourceGroup>().InsertOnSubmit(rrg5);
|
---|
| 251 |
|
---|
[5004] | 252 | DA.ResourceResourceGroup rrg2 = new DA.ResourceResourceGroup();
|
---|
| 253 | rrg2.ResourceId = cl2.Id;
|
---|
| 254 | rrg2.ResourceGroupId = rg2.Id;
|
---|
| 255 | dc.GetTable<DA.ResourceResourceGroup>().InsertOnSubmit(rrg2);
|
---|
| 256 |
|
---|
[5335] | 257 | //DA.ResourceResourceGroup rrg3 = new DA.ResourceResourceGroup();
|
---|
| 258 | //rrg3.ResourceId = rg3.Id;
|
---|
| 259 | //rrg3.ResourceGroupId = rg1.Id;
|
---|
| 260 | //dc.GetTable<DA.ResourceResourceGroup>().InsertOnSubmit(rrg3);
|
---|
[5004] | 261 |
|
---|
[5335] | 262 | rrg4 = new DA.ResourceResourceGroup();
|
---|
| 263 | rrg4.ResourceId = rg2.Id;
|
---|
| 264 | rrg4.ResourceGroupId = rg1.Id;
|
---|
| 265 | dc.GetTable<DA.ResourceResourceGroup>().InsertOnSubmit(rrg4);
|
---|
| 266 |
|
---|
[5004] | 267 | dc.SubmitChanges();
|
---|
| 268 | }
|
---|
| 269 |
|
---|
| 270 | [TestCleanup()]
|
---|
| 271 | public void CleanUp() {
|
---|
[5335] | 272 | //dc = new DA.ClientManagmentDataContext();
|
---|
| 273 | //if (dc.DatabaseExists()) {
|
---|
| 274 | // //dc.DeleteDatabase();
|
---|
| 275 | // dc.ExecuteCommand("delete from ResourceResourceGroup");
|
---|
| 276 | // dc.ExecuteCommand("delete from Resource");
|
---|
| 277 | // dc.SubmitChanges();
|
---|
| 278 | //}
|
---|
| 279 | //else {
|
---|
| 280 | // dc.CreateDatabase();
|
---|
| 281 | // dc.SubmitChanges();
|
---|
| 282 | //}
|
---|
[5004] | 283 | }
|
---|
| 284 |
|
---|
[5335] | 285 | #region TestMethods
|
---|
[5004] | 286 |
|
---|
| 287 | #region TestGroup
|
---|
| 288 |
|
---|
| 289 | /// <summary>
|
---|
| 290 | /// Add ResourceGroup
|
---|
| 291 | /// </summary>
|
---|
| 292 | [TestMethod]
|
---|
| 293 | public void TestAddResourceGroup() {
|
---|
[5335] | 294 | AuthenticationService cs = new AuthenticationService();
|
---|
[5004] | 295 |
|
---|
| 296 | DT.ResourceGroup rg4 = new DT.ResourceGroup();
|
---|
| 297 | rg4.Name = "groupName4";
|
---|
| 298 | rg4.Description = "descrrg4";
|
---|
| 299 | dc.GetTable<DA.Resource>().InsertOnSubmit(HL.Convert.ToEntity(rg4));
|
---|
| 300 |
|
---|
| 301 | int cntPrev = GetNumberOfEntries(sqlCountGroups);
|
---|
| 302 | rg4.Id = cs.AddResourceGroup(rg4);
|
---|
| 303 | Assert.AreNotEqual(Guid.Empty, rg4.Id);
|
---|
| 304 | int cntNew = GetNumberOfEntries(sqlCountGroups);
|
---|
| 305 | Assert.AreEqual(cntPrev, (cntNew - 1));
|
---|
| 306 |
|
---|
| 307 | DA.ResourceGroup group = dc.Resources.OfType<DA.ResourceGroup>().First(x => x.Id == rg4.Id);
|
---|
| 308 | Assert.IsTrue(CompareGroups(HL.Convert.ToDto(group), rg4));
|
---|
| 309 | }
|
---|
| 310 |
|
---|
| 311 | /// <summary>
|
---|
[5335] | 312 |
|
---|
[5004] | 313 | /// </summary>
|
---|
| 314 | [TestMethod]
|
---|
| 315 | public void TestUpdateResourceGroup() {
|
---|
[5335] | 316 | AuthenticationService cs = new AuthenticationService();
|
---|
| 317 |
|
---|
| 318 | DA.ResourceGroup group = dc.Resources.OfType<DA.ResourceGroup>().First(x => x.Id == rg1.Id);
|
---|
| 319 | DT.ResourceGroup modGroup = HeuristicLab.Services.Authentication.Convert.ToDto(group);
|
---|
| 320 |
|
---|
| 321 |
|
---|
| 322 | modGroup.Name = "clientName1_modified";
|
---|
| 323 |
|
---|
| 324 | IList<Guid> rgList = new List<Guid>();
|
---|
| 325 | rgList.Add(groupID3);
|
---|
| 326 | modGroup.ResourceGroup = rgList;
|
---|
| 327 | modGroup.Description = "Test-group_modifiet";
|
---|
| 328 |
|
---|
| 329 | cs.UpdateResourceGroup(modGroup);
|
---|
[5004] | 330 | }
|
---|
| 331 |
|
---|
| 332 | /// <summary>
|
---|
| 333 | /// GetResourceGroup with existing id
|
---|
| 334 | /// </summary>
|
---|
| 335 | [TestMethod]
|
---|
| 336 | public void TestGetResourceGroup() {
|
---|
[5335] | 337 | AuthenticationService cs = new AuthenticationService();
|
---|
[5004] | 338 | DT.ResourceGroup rg = cs.GetResourceGroup(groupID1);
|
---|
| 339 | Assert.AreEqual(rg.Id, groupID1);
|
---|
| 340 | Assert.IsTrue(CompareGroups(rg, rg1));
|
---|
| 341 | }
|
---|
| 342 |
|
---|
| 343 | /// <summary>
|
---|
| 344 | /// GetResourceGroups
|
---|
| 345 | /// </summary>
|
---|
| 346 | [TestMethod]
|
---|
| 347 | public void TestGetResourceGroups() {
|
---|
[5335] | 348 | AuthenticationService cs = new AuthenticationService();
|
---|
[5004] | 349 | IEnumerable<DT.ResourceGroup> groups = cs.GetResourceGroups();
|
---|
| 350 | Assert.AreEqual(3, groups.Count<DT.ResourceGroup>());
|
---|
| 351 | Assert.IsTrue(
|
---|
| 352 | groups.Contains(rg1, new ResourceGroupEqualityComparer()) &&
|
---|
| 353 | groups.Contains(rg2, new ResourceGroupEqualityComparer()) &&
|
---|
| 354 | groups.Contains(rg3, new ResourceGroupEqualityComparer())
|
---|
| 355 | );
|
---|
| 356 | }
|
---|
| 357 |
|
---|
| 358 | /// <summary>
|
---|
[5335] | 359 | /// Delete existing ResourceGroup which is no parent group
|
---|
[5004] | 360 | /// </summary>
|
---|
| 361 | [TestMethod]
|
---|
| 362 | public void TestDeleteResourceGroup1() {
|
---|
[5335] | 363 | AuthenticationService cs = new AuthenticationService();
|
---|
[5004] | 364 |
|
---|
| 365 | int cntPrev = GetNumberOfEntries(sqlCountGroups);
|
---|
[5335] | 366 | cs.DeleteResourceGroup(rg2);
|
---|
[5004] | 367 | int cntNew = GetNumberOfEntries(sqlCountGroups);
|
---|
| 368 | Assert.AreEqual(cntPrev, (cntNew + 1));
|
---|
| 369 | }
|
---|
| 370 |
|
---|
| 371 | /// <summary>
|
---|
[5335] | 372 | /// try to delete existing ResourceGroup wich is parent group
|
---|
[5004] | 373 | /// </summary>
|
---|
| 374 | [TestMethod]
|
---|
| 375 | public void TestDeleteResourceGroup2() {
|
---|
[5335] | 376 | AuthenticationService cs = new AuthenticationService();
|
---|
[5004] | 377 | int cntPrev = GetNumberOfEntries(sqlCountGroups);
|
---|
[5335] | 378 | cs.DeleteResourceGroup(rg1);
|
---|
[5004] | 379 | int cntNew = GetNumberOfEntries(sqlCountGroups);
|
---|
| 380 | Assert.AreEqual(cntPrev, cntNew);
|
---|
| 381 | }
|
---|
| 382 | #endregion
|
---|
| 383 |
|
---|
| 384 |
|
---|
| 385 | #region TestClient
|
---|
| 386 |
|
---|
| 387 | /// <summary>
|
---|
| 388 | /// AddClient
|
---|
| 389 | /// </summary>
|
---|
| 390 | [TestMethod]
|
---|
| 391 | public void TestAddClient1() {
|
---|
[5335] | 392 | AuthenticationService cs = new AuthenticationService();
|
---|
[5004] | 393 |
|
---|
| 394 | DT.Client cl3 = new DT.Client();
|
---|
| 395 | cl3.Name = "clientName3";
|
---|
[5335] | 396 |
|
---|
| 397 | IList<Guid> rgList = new List<Guid>();
|
---|
| 398 | rgList.Add(groupID3);
|
---|
| 399 | cl3.ResourceGroup = rgList;
|
---|
| 400 |
|
---|
[5004] | 401 | cl3.Description = "Test-PC-3";
|
---|
| 402 | cl3.IPAdress = "192.168.0.30";
|
---|
| 403 | cl3.NumberOfProcessors = "2";
|
---|
| 404 | cl3.NumberOfThreads = "2";
|
---|
| 405 | cl3.OperatingSystem = "Vista";
|
---|
| 406 | cl3.MemorySize = "4096";
|
---|
| 407 | cl3.ProcessorType = "Intel";
|
---|
| 408 |
|
---|
| 409 | int cntPrev = GetNumberOfEntries(sqlCountClients);
|
---|
| 410 | cl3.Id = cs.AddClient(cl3);
|
---|
[5335] | 411 | Assert.AreNotEqual(Guid.Empty, cl3.Id);
|
---|
[5004] | 412 | int cntNew = GetNumberOfEntries(sqlCountClients);
|
---|
| 413 | Assert.AreEqual(cntPrev, (cntNew - 1));
|
---|
| 414 |
|
---|
| 415 | DA.Client client = dc.Resources.OfType<DA.Client>().First(x => x.Id == cl3.Id);
|
---|
| 416 | Assert.IsTrue(CompareClients(HL.Convert.ToDto(client), cl3));
|
---|
| 417 | }
|
---|
| 418 |
|
---|
| 419 | /// <summary>
|
---|
| 420 | /// try to AddClient with not existing ResourceGroup
|
---|
| 421 | /// </summary>
|
---|
| 422 | [TestMethod]
|
---|
| 423 | public void TestAddClient2() {
|
---|
[5335] | 424 | AuthenticationService cs = new AuthenticationService();
|
---|
[5004] | 425 |
|
---|
| 426 | DT.Client cl3 = new DT.Client();
|
---|
| 427 | cl3.Name = "clientNamexxxx";
|
---|
| 428 |
|
---|
[5335] | 429 | IList<Guid> rgList = new List<Guid>();
|
---|
| 430 | rgList.Add(Guid.NewGuid());
|
---|
| 431 | cl3.ResourceGroup = rgList;
|
---|
| 432 |
|
---|
[5004] | 433 | int cntPrev = GetNumberOfEntries(sqlCountClients);
|
---|
| 434 | cl3.Id = cs.AddClient(cl3);
|
---|
| 435 | Assert.AreEqual(Guid.Empty, cl3.Id);
|
---|
| 436 | int cntNew = GetNumberOfEntries(sqlCountClients);
|
---|
[5335] | 437 | Assert.AreEqual(cntPrev, cntNew);
|
---|
[5004] | 438 | }
|
---|
| 439 |
|
---|
| 440 | /// <summary>
|
---|
| 441 | /// GetClient by Id
|
---|
| 442 | /// </summary>
|
---|
| 443 | [TestMethod]
|
---|
| 444 | public void TestGetClient1() {
|
---|
[5335] | 445 | AuthenticationService cs = new AuthenticationService();
|
---|
[5004] | 446 | DT.Client cl = cs.GetClient(clientID1);
|
---|
| 447 | Assert.AreEqual(cl.Id, clientID1);
|
---|
| 448 | Assert.IsTrue(CompareClients(cl, cl1));
|
---|
| 449 | }
|
---|
| 450 |
|
---|
| 451 | /// <summary>
|
---|
| 452 | /// causes error
|
---|
| 453 | /// !!!!!!!!!!!!!!!!!!!!!!
|
---|
| 454 | ///
|
---|
| 455 | /// try GetClient with not existin id
|
---|
| 456 | /// </summary>
|
---|
| 457 | //[TestMethod]
|
---|
| 458 | //public void TestGetClient2() {
|
---|
[5335] | 459 | // AuthenticationService cs = new AuthenticationService();
|
---|
[5004] | 460 | // DT.Client cl = cs.GetClient(Guid.NewGuid());
|
---|
| 461 | // Assert.IsNull(cl);
|
---|
| 462 | //}
|
---|
| 463 |
|
---|
| 464 | ///// <summary>
|
---|
| 465 | ///// Test of Method "Client GetClient(Guid id)"
|
---|
| 466 | ///// </summary>
|
---|
| 467 | //[TestMethod]
|
---|
| 468 | //public void TestGetClient3() {
|
---|
[5335] | 469 | // AuthenticationService cs = new AuthenticationService();
|
---|
[5004] | 470 | // DT.Client cl = cs.GetClient(Guid.Empty);
|
---|
| 471 | // Assert.IsNull(cl);
|
---|
| 472 | //}
|
---|
| 473 |
|
---|
| 474 | //[TestMethod]
|
---|
| 475 | //public void TestUpdateClient() {
|
---|
| 476 | //}
|
---|
| 477 |
|
---|
| 478 | /// <summary>
|
---|
| 479 | /// delete existing client
|
---|
| 480 | /// </summary>
|
---|
| 481 | [TestMethod]
|
---|
| 482 | public void TestDeleteClient1() {
|
---|
[5335] | 483 | AuthenticationService cs = new AuthenticationService();
|
---|
[5004] | 484 |
|
---|
| 485 | int cntPrev = GetNumberOfEntries(sqlCountClients);
|
---|
[5335] | 486 | cs.DeleteClient(cl1);
|
---|
[5004] | 487 | int cntNew = GetNumberOfEntries(sqlCountClients);
|
---|
| 488 | Assert.AreEqual(cntPrev, (cntNew + 1));
|
---|
| 489 | }
|
---|
| 490 |
|
---|
[5335] | 491 | ///// <summary>
|
---|
| 492 | ///// try to delete not existing client
|
---|
| 493 | ///// </summary>
|
---|
| 494 | //[TestMethod]
|
---|
| 495 | //public void TestDeleteClient2() {
|
---|
| 496 | // AuthenticationService cs = new AuthenticationService();
|
---|
| 497 | // DT.Client cl3 = new DT.Client();
|
---|
| 498 | // cl3.Name = "clientName3";
|
---|
[5004] | 499 |
|
---|
[5335] | 500 | // IList<Guid> rgList = new List<Guid>();
|
---|
| 501 | // rgList.Add(groupID3);
|
---|
| 502 | // cl3.ResourceGroup = rgList;
|
---|
[5004] | 503 |
|
---|
[5335] | 504 | // cl3.Description = "Test-PC-3";
|
---|
| 505 | // cl3.IPAdress = "192.168.0.30";
|
---|
| 506 | // cl3.NumberOfProcessors = "2";
|
---|
| 507 | // cl3.NumberOfThreads = "2";
|
---|
| 508 | // cl3.OperatingSystem = "Vista";
|
---|
| 509 | // cl3.MemorySize = "4096";
|
---|
| 510 | // cl3.ProcessorType = "Intel";
|
---|
| 511 |
|
---|
| 512 | // int cntPrev = GetNumberOfEntries(sqlCountClients);
|
---|
| 513 | // cs.DeleteClient(cl3);
|
---|
| 514 | // int cntNew = GetNumberOfEntries(sqlCountClients);
|
---|
| 515 | // Assert.AreEqual(cntPrev, cntNew);
|
---|
| 516 | //}
|
---|
| 517 |
|
---|
[5004] | 518 | /// <summary>
|
---|
| 519 | /// get all clients
|
---|
| 520 | /// </summary>
|
---|
| 521 | [TestMethod]
|
---|
| 522 | public void TestGetClients() {
|
---|
[5335] | 523 | AuthenticationService cs = new AuthenticationService();
|
---|
[5004] | 524 | IEnumerable<DT.Client> clients = cs.GetClients();
|
---|
| 525 | Assert.AreEqual(2, clients.Count<DT.Client>());
|
---|
| 526 | Assert.IsTrue(
|
---|
| 527 | clients.Contains(cl1, new ClientEqualityComparer()) &&
|
---|
| 528 | clients.Contains(cl2, new ClientEqualityComparer())
|
---|
| 529 | );
|
---|
| 530 | }
|
---|
| 531 |
|
---|
| 532 | /// <summary>
|
---|
| 533 | /// update existing client
|
---|
| 534 | /// </summary>
|
---|
| 535 | [TestMethod]
|
---|
| 536 | public void TestUpdateClient1() {
|
---|
[5335] | 537 | AuthenticationService cs = new AuthenticationService();
|
---|
[5004] | 538 |
|
---|
[5335] | 539 | DA.Client client = dc.Resources.OfType<DA.Client>().First(x => x.Id == cl1.Id);
|
---|
| 540 | DT.Client modClient = HeuristicLab.Services.Authentication.Convert.ToDto(client);
|
---|
[5004] | 541 |
|
---|
[5335] | 542 | //cl1.Id ;
|
---|
| 543 | //cl1.ResourceType ;
|
---|
| 544 | modClient.Name = "clientName1_modified";
|
---|
| 545 |
|
---|
| 546 | IList<Guid> rgList = new List<Guid>();
|
---|
| 547 | rgList.Add(groupID3);
|
---|
| 548 | modClient.ResourceGroup = rgList;
|
---|
| 549 |
|
---|
| 550 | modClient.Description = "Test-PC-1_modifiet";
|
---|
| 551 | modClient.IPAdress = "192.168.0.11";
|
---|
| 552 | modClient.NumberOfProcessors = "4";
|
---|
| 553 | modClient.NumberOfThreads = "2";
|
---|
| 554 | modClient.OperatingSystem = "Vista";
|
---|
| 555 | modClient.MemorySize = "2196";
|
---|
| 556 | modClient.ProcessorType = "Intel";
|
---|
| 557 |
|
---|
| 558 | cs.UpdateClient(modClient);
|
---|
| 559 |
|
---|
| 560 | //DA.Client client1 = dc.Resources.OfType<DA.Client>().First(x => x.Id == cl1.Id);
|
---|
| 561 | //Assert.IsTrue(CompareClients(HL.Convert.ToDto(client1), modClient));
|
---|
[5004] | 562 | }
|
---|
| 563 |
|
---|
[5335] | 564 | ///// <summary>
|
---|
| 565 | ///// try to update not existing client
|
---|
| 566 | ///// </summary>
|
---|
| 567 | //[TestMethod]
|
---|
| 568 | //public void TestUpdateClient2() {
|
---|
| 569 | // AuthenticationService cs = new AuthenticationService();
|
---|
| 570 | // DT.Client cl3 = new DT.Client();
|
---|
| 571 | // cl3.Id = Guid.NewGuid();
|
---|
| 572 | // cl3.Name = "clientName3";
|
---|
| 573 |
|
---|
| 574 | // IList<Guid> rgList = new List<Guid>();
|
---|
| 575 | // rgList.Add(groupID3);
|
---|
| 576 | // cl3.ResourceGroup = rgList;
|
---|
| 577 |
|
---|
| 578 | // cl3.Description = "Test-PC-3";
|
---|
| 579 | // cl3.IPAdress = "192.168.0.30";
|
---|
| 580 | // cl3.NumberOfProcessors = "2";
|
---|
| 581 | // cl3.NumberOfThreads = "2";
|
---|
| 582 | // cl3.OperatingSystem = "Vista";
|
---|
| 583 | // cl3.MemorySize = "4096";
|
---|
| 584 | // cl3.ProcessorType = "Intel";
|
---|
| 585 |
|
---|
| 586 | // int cntPrev = GetNumberOfEntries(sqlCountClients);
|
---|
| 587 | // //Assert.IsFalse(cs.UpdateClient(cl3));
|
---|
| 588 | // int cntNew = GetNumberOfEntries(sqlCountClients);
|
---|
| 589 | // Assert.AreEqual(cntPrev, cntNew);
|
---|
| 590 |
|
---|
| 591 | // DA.Client client = dc.Resources.OfType<DA.Client>().First(x => x.Id == cl3.Id);
|
---|
| 592 | // Assert.IsNull(client);
|
---|
| 593 | //}
|
---|
| 594 |
|
---|
| 595 | #endregion
|
---|
| 596 |
|
---|
[5004] | 597 | /// <summary>
|
---|
[5335] | 598 | /// get Members
|
---|
[5004] | 599 | /// </summary>
|
---|
| 600 | [TestMethod]
|
---|
[5335] | 601 | public void TestGetMembers() {
|
---|
| 602 | AuthenticationService cs = new AuthenticationService();
|
---|
| 603 | IEnumerable<DT.Resource> members = cs.GetMembers(rg1.Id);
|
---|
| 604 | Assert.AreEqual(2, members.Count());
|
---|
| 605 | }
|
---|
[5004] | 606 |
|
---|
[5335] | 607 | /// <summary>
|
---|
| 608 | /// get ResourceGroupsOf
|
---|
| 609 | /// </summary>
|
---|
| 610 | [TestMethod]
|
---|
| 611 | public void TestGetResourceGroupsOf() {
|
---|
| 612 | AuthenticationService cs = new AuthenticationService();
|
---|
| 613 | IEnumerable<DT.Resource> resGroups = cs.GetResourceGroupsOf(cl1.Id);
|
---|
| 614 | Assert.AreEqual(2, resGroups.Count());
|
---|
| 615 | }
|
---|
[5004] | 616 |
|
---|
[5335] | 617 | /// <summary>
|
---|
| 618 | /// get Members
|
---|
| 619 | /// </summary>
|
---|
| 620 | [TestMethod]
|
---|
| 621 | public void TestGetRootResources() {
|
---|
| 622 | AuthenticationService cs = new AuthenticationService();
|
---|
| 623 | IEnumerable<DT.Resource> rootResourceList = cs.GetRootResources();
|
---|
| 624 | Assert.AreEqual(2, rootResourceList.Count());
|
---|
[5004] | 625 | }
|
---|
| 626 |
|
---|
| 627 | #endregion //Testmethods
|
---|
| 628 | }
|
---|
[4953] | 629 | }
|
---|