Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
01/19/11 18:09:40 (14 years ago)
Author:
fruehrli
Message:

#1197
modified and new service methods

Location:
branches/ClientManagement/HeuristicLab.Services.Authentication/TestWebService
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/ClientManagement/HeuristicLab.Services.Authentication/TestWebService/TestWebService.csproj

    r4958 r5335  
    3939      <RequiredTargetFramework>3.5</RequiredTargetFramework>
    4040    </Reference>
     41    <Reference Include="System.Data" />
     42    <Reference Include="System.Data.Linq" />
    4143  </ItemGroup>
    4244  <ItemGroup>
     
    5052  </ItemGroup>
    5153  <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>
    5262    <ProjectReference Include="..\HeuristicLab.Services.Authentication\HeuristicLab.Services.Authentication.csproj">
    5363      <Project>{ED8DC6E8-57C6-49E0-8CDF-25703AC52350}</Project>
  • branches/ClientManagement/HeuristicLab.Services.Authentication/TestWebService/TestWebServiec.cs

    r5004 r5335  
    6868    }
    6969
     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
    7083    private bool CompareClients(DT.Client c1, DT.Client c2) {
    7184      return (
    7285        c1.Name == c2.Name &&
    7386        c1.Id == c2.Id &&
    74         //c1.ResourceType == c2.ResourceType &&
     87        c1.ResourceType == c2.ResourceType &&
    7588        c1.Description == c2.Description &&
    7689        c1.IPAdress == c2.IPAdress &&
     
    91104    }
    92105
     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
    93113    private static int GetNumberOfEntries(string sqlCommand) {
    94114      DA.ClientManagmentDataContext dc = new DA.ClientManagmentDataContext();
     
    117137    public DA.ResourceResourceGroup rrg2 = null;
    118138    public DA.ResourceResourceGroup rrg3 = null;
     139    public DA.ResourceResourceGroup rrg4 = null;
     140    public DA.ResourceResourceGroup rrg5 = null;
    119141    #endregion
    120    
     142
    121143    #region Additional test attributes
    122144    //
     
    142164
    143165    [TestInitialize()]
    144     public void Init() { 
     166    public void Init() {
    145167
    146168      dc = new DA.ClientManagmentDataContext();
     
    156178      }
    157179
    158      
     180
    159181      // create groups
    160182      rg1 = new DT.ResourceGroup();
    161183      rg1.Name = groupName1;
    162       rg1.Id = groupID1;     
     184      rg1.Id = groupID1;
    163185      rg1.Description = "descr rg1";
    164186      dc.GetTable<DA.Resource>().InsertOnSubmit(HL.Convert.ToEntity(rg1));
     
    167189      rg2.Name = groupName2;
    168190      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
    170196      rg2.Description = "descrrg2";
    171197      dc.GetTable<DA.Resource>().InsertOnSubmit(HL.Convert.ToEntity(rg2));
     
    181207      cl1.Name = clientName1;
    182208      cl1.Id = clientID1;
    183       cl1.ResourceGroup = groupID1;
     209
     210      IList<Guid> rgList1 = new List<Guid>();
     211      rgList.Add(groupID1);
     212      cl1.ResourceGroup = rgList1;
     213
    184214      cl1.Description = "Test-PC-1";
    185215      cl1.IPAdress = "192.168.0.10";
     
    194224      cl2.Name = clientName2;
    195225      cl2.Id = clientID2;
    196       cl2.ResourceGroup = groupID2;
     226
     227      IList<Guid> rgList2 = new List<Guid>();
     228      rgList.Add(groupID2);
     229      cl2.ResourceGroup = rgList2;
     230
    197231      cl2.Description = "Test-PC-2";
    198232      cl2.IPAdress = "192.168.0.20";
     
    210244      dc.GetTable<DA.ResourceResourceGroup>().InsertOnSubmit(rrg1);
    211245
     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
    212252      DA.ResourceResourceGroup rrg2 = new DA.ResourceResourceGroup();
    213253      rrg2.ResourceId = cl2.Id;
     
    215255      dc.GetTable<DA.ResourceResourceGroup>().InsertOnSubmit(rrg2);
    216256
    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);
    221266
    222267      dc.SubmitChanges();
     
    225270    [TestCleanup()]
    226271    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
    241286
    242287    #region TestGroup
     
    247292    [TestMethod]
    248293    public void TestAddResourceGroup() {
    249       ClientService cs = new ClientService();
     294      AuthenticationService cs = new AuthenticationService();
    250295
    251296      DT.ResourceGroup rg4 = new DT.ResourceGroup();
     
    265310
    266311    /// <summary>
    267     /// TODO
     312
    268313    /// </summary>
    269314    [TestMethod]
    270315    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);
    271330    }
    272331
     
    276335    [TestMethod]
    277336    public void TestGetResourceGroup() {
    278       ClientService cs = new ClientService();
     337      AuthenticationService cs = new AuthenticationService();
    279338      DT.ResourceGroup rg = cs.GetResourceGroup(groupID1);
    280339      Assert.AreEqual(rg.Id, groupID1);
     
    287346    [TestMethod]
    288347    public void TestGetResourceGroups() {
    289       ClientService cs = new ClientService();
     348      AuthenticationService cs = new AuthenticationService();
    290349      IEnumerable<DT.ResourceGroup> groups = cs.GetResourceGroups();
    291350      Assert.AreEqual(3, groups.Count<DT.ResourceGroup>());
     
    298357
    299358    /// <summary>
    300     /// Delete existing ResourceGroup whisch is no parent group
     359    /// Delete existing ResourceGroup which is no parent group
    301360    /// </summary>
    302361    [TestMethod]
    303362    public void TestDeleteResourceGroup1() {
    304       ClientService cs = new ClientService();
     363      AuthenticationService cs = new AuthenticationService();
    305364
    306365      int cntPrev = GetNumberOfEntries(sqlCountGroups);
    307       Assert.IsTrue(cs.DeleteResourceGroup(rg2));
     366      cs.DeleteResourceGroup(rg2);
    308367      int cntNew = GetNumberOfEntries(sqlCountGroups);
    309368      Assert.AreEqual(cntPrev, (cntNew + 1));
     
    311370
    312371    /// <summary>
    313     /// try to delete existing ResourceGroup whisch is parent group
     372    /// try to delete existing ResourceGroup wich is parent group
    314373    /// </summary>
    315374    [TestMethod]
    316375    public void TestDeleteResourceGroup2() {
    317       ClientService cs = new ClientService();
    318 
     376      AuthenticationService cs = new AuthenticationService();
    319377      int cntPrev = GetNumberOfEntries(sqlCountGroups);
    320       Assert.IsFalse(cs.DeleteResourceGroup(rg1));
     378      cs.DeleteResourceGroup(rg1);
    321379      int cntNew = GetNumberOfEntries(sqlCountGroups);
    322380      Assert.AreEqual(cntPrev, cntNew);
     
    332390    [TestMethod]
    333391    public void TestAddClient1() {
    334       ClientService cs = new ClientService();
     392      AuthenticationService cs = new AuthenticationService();
    335393
    336394      DT.Client cl3 = new DT.Client();
    337395      cl3.Name = "clientName3";
    338       cl3.ResourceGroup = groupID3;
     396
     397      IList<Guid> rgList = new List<Guid>();
     398      rgList.Add(groupID3);
     399      cl3.ResourceGroup = rgList;
     400
    339401      cl3.Description = "Test-PC-3";
    340402      cl3.IPAdress = "192.168.0.30";
     
    347409      int cntPrev = GetNumberOfEntries(sqlCountClients);
    348410      cl3.Id = cs.AddClient(cl3);
    349       Assert.AreNotEqual(Guid.Empty, cl3.Id); 
     411      Assert.AreNotEqual(Guid.Empty, cl3.Id);
    350412      int cntNew = GetNumberOfEntries(sqlCountClients);
    351413      Assert.AreEqual(cntPrev, (cntNew - 1));
     
    360422    [TestMethod]
    361423    public void TestAddClient2() {
    362       ClientService cs = new ClientService();
     424      AuthenticationService cs = new AuthenticationService();
    363425
    364426      DT.Client cl3 = new DT.Client();
    365427      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;
    367432
    368433      int cntPrev = GetNumberOfEntries(sqlCountClients);
     
    370435      Assert.AreEqual(Guid.Empty, cl3.Id);
    371436      int cntNew = GetNumberOfEntries(sqlCountClients);
    372       Assert.AreEqual(cntPrev, cntNew); 
     437      Assert.AreEqual(cntPrev, cntNew);
    373438    }
    374439
     
    378443    [TestMethod]
    379444    public void TestGetClient1() {
    380       ClientService cs = new ClientService();
     445      AuthenticationService cs = new AuthenticationService();
    381446      DT.Client cl = cs.GetClient(clientID1);
    382447      Assert.AreEqual(cl.Id, clientID1);
     
    392457    //[TestMethod]
    393458    //public void TestGetClient2() {
    394     //  ClientService cs = new ClientService();
     459    //  AuthenticationService cs = new AuthenticationService();
    395460    //  DT.Client cl = cs.GetClient(Guid.NewGuid());
    396461    //  Assert.IsNull(cl);
     
    402467    //[TestMethod]
    403468    //public void TestGetClient3() {
    404     //  ClientService cs = new ClientService();
     469    //  AuthenticationService cs = new AuthenticationService();
    405470    //  DT.Client cl = cs.GetClient(Guid.Empty);
    406471    //  Assert.IsNull(cl);
     
    416481    [TestMethod]
    417482    public void TestDeleteClient1() {
    418       ClientService cs = new ClientService();
     483      AuthenticationService cs = new AuthenticationService();
    419484
    420485      int cntPrev = GetNumberOfEntries(sqlCountClients);
    421       Assert.IsTrue(cs.DeleteClient(cl1));
     486      cs.DeleteClient(cl1);
    422487      int cntNew = GetNumberOfEntries(sqlCountClients);
    423488      Assert.AreEqual(cntPrev, (cntNew + 1));
    424489    }
    425490
    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    //}
    448517
    449518    /// <summary>
     
    452521    [TestMethod]
    453522    public void TestGetClients() {
    454       ClientService cs = new ClientService();
     523      AuthenticationService cs = new AuthenticationService();
    455524      IEnumerable<DT.Client> clients = cs.GetClients();
    456525      Assert.AreEqual(2, clients.Count<DT.Client>());
     
    466535    [TestMethod]
    467536    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();
    484538
    485539      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    //}
    515594
    516595    #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
    518627    #endregion //Testmethods
    519628  }
Note: See TracChangeset for help on using the changeset viewer.