- Timestamp:
- 01/19/11 18:09:40 (14 years ago)
- Location:
- branches/ClientManagement/HeuristicLab.Services.Authentication/TestWebService
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/ClientManagement/HeuristicLab.Services.Authentication/TestWebService/TestWebService.csproj
r4958 r5335 39 39 <RequiredTargetFramework>3.5</RequiredTargetFramework> 40 40 </Reference> 41 <Reference Include="System.Data" /> 42 <Reference Include="System.Data.Linq" /> 41 43 </ItemGroup> 42 44 <ItemGroup> … … 50 52 </ItemGroup> 51 53 <ItemGroup> 54 <ProjectReference Include="..\HeuristicLab.Services.Authentication.DataAccess\HeuristicLab.Services.Authentication.DataAccess.csproj"> 55 <Project>{AC7C2117-034E-4301-8A43-C869930D404E}</Project> 56 <Name>HeuristicLab.Services.Authentication.DataAccess</Name> 57 </ProjectReference> 58 <ProjectReference Include="..\HeuristicLab.Services.Authentication.DataTransfer\HeuristicLab.Services.Authentication.DataTransfer.csproj"> 59 <Project>{73E5113E-A293-4384-8B16-3CE38F2CFDC9}</Project> 60 <Name>HeuristicLab.Services.Authentication.DataTransfer</Name> 61 </ProjectReference> 52 62 <ProjectReference Include="..\HeuristicLab.Services.Authentication\HeuristicLab.Services.Authentication.csproj"> 53 63 <Project>{ED8DC6E8-57C6-49E0-8CDF-25703AC52350}</Project> -
branches/ClientManagement/HeuristicLab.Services.Authentication/TestWebService/TestWebServiec.cs
r5004 r5335 68 68 } 69 69 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 70 83 private bool CompareClients(DT.Client c1, DT.Client c2) { 71 84 return ( 72 85 c1.Name == c2.Name && 73 86 c1.Id == c2.Id && 74 //c1.ResourceType == c2.ResourceType &&87 c1.ResourceType == c2.ResourceType && 75 88 c1.Description == c2.Description && 76 89 c1.IPAdress == c2.IPAdress && … … 91 104 } 92 105 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 93 113 private static int GetNumberOfEntries(string sqlCommand) { 94 114 DA.ClientManagmentDataContext dc = new DA.ClientManagmentDataContext(); … … 117 137 public DA.ResourceResourceGroup rrg2 = null; 118 138 public DA.ResourceResourceGroup rrg3 = null; 139 public DA.ResourceResourceGroup rrg4 = null; 140 public DA.ResourceResourceGroup rrg5 = null; 119 141 #endregion 120 142 121 143 #region Additional test attributes 122 144 // … … 142 164 143 165 [TestInitialize()] 144 public void Init() { 166 public void Init() { 145 167 146 168 dc = new DA.ClientManagmentDataContext(); … … 156 178 } 157 179 158 180 159 181 // create groups 160 182 rg1 = new DT.ResourceGroup(); 161 183 rg1.Name = groupName1; 162 rg1.Id = groupID1; 184 rg1.Id = groupID1; 163 185 rg1.Description = "descr rg1"; 164 186 dc.GetTable<DA.Resource>().InsertOnSubmit(HL.Convert.ToEntity(rg1)); … … 167 189 rg2.Name = groupName2; 168 190 rg2.Id = groupID2; 169 rg2.ResourceGroup = rg1.Id; 191 192 IList<Guid> rgList = new List<Guid>(); 193 rgList.Add(rg1.Id); 194 rg2.ResourceGroup = rgList; 195 170 196 rg2.Description = "descrrg2"; 171 197 dc.GetTable<DA.Resource>().InsertOnSubmit(HL.Convert.ToEntity(rg2)); … … 181 207 cl1.Name = clientName1; 182 208 cl1.Id = clientID1; 183 cl1.ResourceGroup = groupID1; 209 210 IList<Guid> rgList1 = new List<Guid>(); 211 rgList.Add(groupID1); 212 cl1.ResourceGroup = rgList1; 213 184 214 cl1.Description = "Test-PC-1"; 185 215 cl1.IPAdress = "192.168.0.10"; … … 194 224 cl2.Name = clientName2; 195 225 cl2.Id = clientID2; 196 cl2.ResourceGroup = groupID2; 226 227 IList<Guid> rgList2 = new List<Guid>(); 228 rgList.Add(groupID2); 229 cl2.ResourceGroup = rgList2; 230 197 231 cl2.Description = "Test-PC-2"; 198 232 cl2.IPAdress = "192.168.0.20"; … … 210 244 dc.GetTable<DA.ResourceResourceGroup>().InsertOnSubmit(rrg1); 211 245 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 212 252 DA.ResourceResourceGroup rrg2 = new DA.ResourceResourceGroup(); 213 253 rrg2.ResourceId = cl2.Id; … … 215 255 dc.GetTable<DA.ResourceResourceGroup>().InsertOnSubmit(rrg2); 216 256 217 DA.ResourceResourceGroup rrg3 = new DA.ResourceResourceGroup(); 218 rrg3.ResourceId = rg1.Id; 219 rrg3.ResourceGroupId = rg3.Id; 220 dc.GetTable<DA.ResourceResourceGroup>().InsertOnSubmit(rrg3); 257 //DA.ResourceResourceGroup rrg3 = new DA.ResourceResourceGroup(); 258 //rrg3.ResourceId = rg3.Id; 259 //rrg3.ResourceGroupId = rg1.Id; 260 //dc.GetTable<DA.ResourceResourceGroup>().InsertOnSubmit(rrg3); 261 262 rrg4 = new DA.ResourceResourceGroup(); 263 rrg4.ResourceId = rg2.Id; 264 rrg4.ResourceGroupId = rg1.Id; 265 dc.GetTable<DA.ResourceResourceGroup>().InsertOnSubmit(rrg4); 221 266 222 267 dc.SubmitChanges(); … … 225 270 [TestCleanup()] 226 271 public void CleanUp() { 227 dc = new DA.ClientManagmentDataContext();228 if (dc.DatabaseExists()) {229 //dc.DeleteDatabase();230 dc.ExecuteCommand("delete from ResourceResourceGroup");231 dc.ExecuteCommand("delete from Resource");232 dc.SubmitChanges();233 }234 else {235 dc.CreateDatabase();236 dc.SubmitChanges();237 }238 } 239 240 #region TestMethods 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 //} 283 } 284 285 #region TestMethods 241 286 242 287 #region TestGroup … … 247 292 [TestMethod] 248 293 public void TestAddResourceGroup() { 249 ClientService cs = new ClientService();294 AuthenticationService cs = new AuthenticationService(); 250 295 251 296 DT.ResourceGroup rg4 = new DT.ResourceGroup(); … … 265 310 266 311 /// <summary> 267 /// TODO 312 268 313 /// </summary> 269 314 [TestMethod] 270 315 public void TestUpdateResourceGroup() { 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); 271 330 } 272 331 … … 276 335 [TestMethod] 277 336 public void TestGetResourceGroup() { 278 ClientService cs = new ClientService();337 AuthenticationService cs = new AuthenticationService(); 279 338 DT.ResourceGroup rg = cs.GetResourceGroup(groupID1); 280 339 Assert.AreEqual(rg.Id, groupID1); … … 287 346 [TestMethod] 288 347 public void TestGetResourceGroups() { 289 ClientService cs = new ClientService();348 AuthenticationService cs = new AuthenticationService(); 290 349 IEnumerable<DT.ResourceGroup> groups = cs.GetResourceGroups(); 291 350 Assert.AreEqual(3, groups.Count<DT.ResourceGroup>()); … … 298 357 299 358 /// <summary> 300 /// Delete existing ResourceGroup whi sch is no parent group359 /// Delete existing ResourceGroup which is no parent group 301 360 /// </summary> 302 361 [TestMethod] 303 362 public void TestDeleteResourceGroup1() { 304 ClientService cs = new ClientService();363 AuthenticationService cs = new AuthenticationService(); 305 364 306 365 int cntPrev = GetNumberOfEntries(sqlCountGroups); 307 Assert.IsTrue(cs.DeleteResourceGroup(rg2));366 cs.DeleteResourceGroup(rg2); 308 367 int cntNew = GetNumberOfEntries(sqlCountGroups); 309 368 Assert.AreEqual(cntPrev, (cntNew + 1)); … … 311 370 312 371 /// <summary> 313 /// try to delete existing ResourceGroup w hisch is parent group372 /// try to delete existing ResourceGroup wich is parent group 314 373 /// </summary> 315 374 [TestMethod] 316 375 public void TestDeleteResourceGroup2() { 317 ClientService cs = new ClientService(); 318 376 AuthenticationService cs = new AuthenticationService(); 319 377 int cntPrev = GetNumberOfEntries(sqlCountGroups); 320 Assert.IsFalse(cs.DeleteResourceGroup(rg1));378 cs.DeleteResourceGroup(rg1); 321 379 int cntNew = GetNumberOfEntries(sqlCountGroups); 322 380 Assert.AreEqual(cntPrev, cntNew); … … 332 390 [TestMethod] 333 391 public void TestAddClient1() { 334 ClientService cs = new ClientService();392 AuthenticationService cs = new AuthenticationService(); 335 393 336 394 DT.Client cl3 = new DT.Client(); 337 395 cl3.Name = "clientName3"; 338 cl3.ResourceGroup = groupID3; 396 397 IList<Guid> rgList = new List<Guid>(); 398 rgList.Add(groupID3); 399 cl3.ResourceGroup = rgList; 400 339 401 cl3.Description = "Test-PC-3"; 340 402 cl3.IPAdress = "192.168.0.30"; … … 347 409 int cntPrev = GetNumberOfEntries(sqlCountClients); 348 410 cl3.Id = cs.AddClient(cl3); 349 Assert.AreNotEqual(Guid.Empty, cl3.Id); 411 Assert.AreNotEqual(Guid.Empty, cl3.Id); 350 412 int cntNew = GetNumberOfEntries(sqlCountClients); 351 413 Assert.AreEqual(cntPrev, (cntNew - 1)); … … 360 422 [TestMethod] 361 423 public void TestAddClient2() { 362 ClientService cs = new ClientService();424 AuthenticationService cs = new AuthenticationService(); 363 425 364 426 DT.Client cl3 = new DT.Client(); 365 427 cl3.Name = "clientNamexxxx"; 366 cl3.ResourceGroup = Guid.NewGuid(); 428 429 IList<Guid> rgList = new List<Guid>(); 430 rgList.Add(Guid.NewGuid()); 431 cl3.ResourceGroup = rgList; 367 432 368 433 int cntPrev = GetNumberOfEntries(sqlCountClients); … … 370 435 Assert.AreEqual(Guid.Empty, cl3.Id); 371 436 int cntNew = GetNumberOfEntries(sqlCountClients); 372 Assert.AreEqual(cntPrev, cntNew); 437 Assert.AreEqual(cntPrev, cntNew); 373 438 } 374 439 … … 378 443 [TestMethod] 379 444 public void TestGetClient1() { 380 ClientService cs = new ClientService();445 AuthenticationService cs = new AuthenticationService(); 381 446 DT.Client cl = cs.GetClient(clientID1); 382 447 Assert.AreEqual(cl.Id, clientID1); … … 392 457 //[TestMethod] 393 458 //public void TestGetClient2() { 394 // ClientService cs = new ClientService();459 // AuthenticationService cs = new AuthenticationService(); 395 460 // DT.Client cl = cs.GetClient(Guid.NewGuid()); 396 461 // Assert.IsNull(cl); … … 402 467 //[TestMethod] 403 468 //public void TestGetClient3() { 404 // ClientService cs = new ClientService();469 // AuthenticationService cs = new AuthenticationService(); 405 470 // DT.Client cl = cs.GetClient(Guid.Empty); 406 471 // Assert.IsNull(cl); … … 416 481 [TestMethod] 417 482 public void TestDeleteClient1() { 418 ClientService cs = new ClientService();483 AuthenticationService cs = new AuthenticationService(); 419 484 420 485 int cntPrev = GetNumberOfEntries(sqlCountClients); 421 Assert.IsTrue(cs.DeleteClient(cl1));486 cs.DeleteClient(cl1); 422 487 int cntNew = GetNumberOfEntries(sqlCountClients); 423 488 Assert.AreEqual(cntPrev, (cntNew + 1)); 424 489 } 425 490 426 /// <summary> 427 /// try to delete not existing client 428 /// </summary> 429 [TestMethod] 430 public void TestDeleteClient2() { 431 ClientService cs = new ClientService(); 432 DT.Client cl3 = new DT.Client(); 433 cl3.Name = "clientName3"; 434 cl3.ResourceGroup = groupID3; 435 cl3.Description = "Test-PC-3"; 436 cl3.IPAdress = "192.168.0.30"; 437 cl3.NumberOfProcessors = "2"; 438 cl3.NumberOfThreads = "2"; 439 cl3.OperatingSystem = "Vista"; 440 cl3.MemorySize = "4096"; 441 cl3.ProcessorType = "Intel"; 442 443 int cntPrev = GetNumberOfEntries(sqlCountClients); 444 Assert.IsFalse(cs.DeleteClient(cl3)); 445 int cntNew = GetNumberOfEntries(sqlCountClients); 446 Assert.AreEqual(cntPrev, cntNew); 447 } 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"; 499 500 // IList<Guid> rgList = new List<Guid>(); 501 // rgList.Add(groupID3); 502 // cl3.ResourceGroup = rgList; 503 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 //} 448 517 449 518 /// <summary> … … 452 521 [TestMethod] 453 522 public void TestGetClients() { 454 ClientService cs = new ClientService();523 AuthenticationService cs = new AuthenticationService(); 455 524 IEnumerable<DT.Client> clients = cs.GetClients(); 456 525 Assert.AreEqual(2, clients.Count<DT.Client>()); … … 466 535 [TestMethod] 467 536 public void TestUpdateClient1() { 468 ClientService cs = new ClientService(); 469 DT.Client cl1 = new DT.Client(); 470 cl1.Name = "clientName1_modified"; 471 cl1.ResourceGroup = groupID3; 472 cl1.Description = "Test-PC-1_modifiet"; 473 cl1.IPAdress = "192.168.0.11"; 474 cl1.NumberOfProcessors = "4"; 475 cl1.NumberOfThreads = "2"; 476 cl1.OperatingSystem = "Vista"; 477 cl1.MemorySize = "2096"; 478 cl1.ProcessorType = "Intel"; 479 480 int cntPrev = GetNumberOfEntries(sqlCountClients); 481 Assert.IsTrue(cs.UpdateClient(cl1)); 482 int cntNew = GetNumberOfEntries(sqlCountClients); 483 Assert.AreEqual(cntPrev, cntNew); 537 AuthenticationService cs = new AuthenticationService(); 484 538 485 539 DA.Client client = dc.Resources.OfType<DA.Client>().First(x => x.Id == cl1.Id); 486 Assert.IsTrue(CompareClients(HL.Convert.ToDto(client), cl1)); 487 } 488 489 /// <summary> 490 /// try to update not existing client 491 /// </summary> 492 [TestMethod] 493 public void TestUpdateClient2() { 494 ClientService cs = new ClientService(); 495 DT.Client cl3 = new DT.Client(); 496 cl3.Id = Guid.NewGuid(); 497 cl3.Name = "clientName3"; 498 cl3.ResourceGroup = groupID3; 499 cl3.Description = "Test-PC-3"; 500 cl3.IPAdress = "192.168.0.30"; 501 cl3.NumberOfProcessors = "2"; 502 cl3.NumberOfThreads = "2"; 503 cl3.OperatingSystem = "Vista"; 504 cl3.MemorySize = "4096"; 505 cl3.ProcessorType = "Intel"; 506 507 int cntPrev = GetNumberOfEntries(sqlCountClients); 508 Assert.IsFalse(cs.UpdateClient(cl3)); 509 int cntNew = GetNumberOfEntries(sqlCountClients); 510 Assert.AreEqual(cntPrev, cntNew); 511 512 DA.Client client = dc.Resources.OfType<DA.Client>().First(x => x.Id == cl3.Id); 513 Assert.IsNull(client); 514 } 540 DT.Client modClient = HeuristicLab.Services.Authentication.Convert.ToDto(client); 541 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)); 562 } 563 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 //} 515 594 516 595 #endregion 517 596 597 /// <summary> 598 /// get Members 599 /// </summary> 600 [TestMethod] 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 } 606 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 } 616 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()); 625 } 626 518 627 #endregion //Testmethods 519 628 }
Note: See TracChangeset
for help on using the changeset viewer.