Free cookie consent management tool by TermsFeed Policy Generator

source: branches/ClientUserManagement/HeuristicLab.Services.Access-3.3.Tests/UnitTest.cs @ 6852

Last change on this file since 6852 was 6852, checked in by ascheibe, 13 years ago

#1648 worked on webservice

File size: 5.4 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2011 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
4 *
5 * This file is part of HeuristicLab.
6 *
7 * HeuristicLab is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * HeuristicLab is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
19 */
20#endregion
21
22using System;
23using System.Collections.Generic;
24using System.Linq;
25using Microsoft.VisualStudio.TestTools.UnitTesting;
26using DA = HeuristicLab.Services.Access.DataAccess;
27using DT = HeuristicLab.Services.Access.DataTransfer;
28
29namespace HeuristicLab.Services.Access.Tests {
30  [TestClass]
31  public class UnitTest {
32
33    [TestMethod]
34    public void ClearDB() {
35      using (DA.ClientManagementDataContext context = new DA.ClientManagementDataContext()) {
36        context.ExecuteCommand("DELETE FROM dbo.ResourceResourceGroup");
37        context.ExecuteCommand("DELETE FROM dbo.Resource");
38        context.ExecuteCommand("DELETE FROM dbo.ClientConfiguration");
39        context.ExecuteCommand("DELETE FROM dbo.ClientError");
40        context.ExecuteCommand("DELETE FROM dbo.ClientLog");
41        context.ExecuteCommand("DELETE FROM dbo.ClientType");
42        context.ExecuteCommand("DELETE FROM dbo.Country");
43        context.ExecuteCommand("DELETE FROM dbo.OperatingSystem");
44        context.ExecuteCommand("DELETE FROM dbo.ResourcePlugin");
45        context.ExecuteCommand("DELETE FROM dbo.Plugin");
46        context.ExecuteCommand("DELETE FROM dbo.UserGroupUserGroup");
47        context.ExecuteCommand("DELETE FROM dbo.UserGroup");
48      }
49    }
50
51    [TestMethod]
52    public void AddClientTest() {
53      ClearDB();
54      AccessService service = new AccessService();
55      DT.ClientConfiguration config = new DT.ClientConfiguration() { Description = "fatConfig", Hash = "xyz" };
56      DT.Country country = new DT.Country() { Name = "Austria" };
57      DT.ClientType clientType = new DT.ClientType() { Name = "Client" };
58      DT.OperatingSystem os = new DT.OperatingSystem() { Name = "Windows 7" };
59
60      DT.Client client = new DT.Client() {
61        ClientConfiguration = config,
62        ClientType = clientType,
63        Country = country,
64        Description = "testClient",
65        HeuristicLabVersion = "3.3.6",
66        MemorySize = 512,
67        NumberOfCores = 4,
68        Name = "testClient",
69        OperatingSystem = os,
70        ProcessorType = "Intel i7",
71        Timestamp = DateTime.Now
72      };
73
74      Guid id = service.AddClient(client);
75      Assert.IsTrue(service.ClientExists(id));
76      Assert.AreEqual(1, service.GetAllClients().Count());
77
78      service.DeleteClient(service.GetAllClients().First());
79      Assert.AreEqual(0, service.GetAllClients().Count());
80    }
81
82    [TestMethod]
83    public void AddGroupTest() {
84      ClearDB();
85      AccessService service = new AccessService();
86
87      DT.ClientGroup parentGroup = new DT.ClientGroup() { Name = "Parent", Description = "Parent Group" };
88      DT.ClientGroup childGroup = new DT.ClientGroup() { Name = "Child", Description = "Child Group" };
89      DT.ClientGroup otherGroup = new DT.ClientGroup() { Name = "Other", Description = "Other Group" };
90
91      parentGroup.Id = service.AddClientGroup(parentGroup);
92      childGroup.Id = service.AddClientGroup(childGroup);
93      otherGroup.Id = service.AddClientGroup(otherGroup);
94
95      List<Guid> groupGuids = new List<Guid>();
96      groupGuids.Add(parentGroup.Id);
97      groupGuids.Add(childGroup.Id);
98
99      Assert.AreEqual(3, service.GetAllClientGroups().Count());
100      var childParentList = service.GetClientGroups(groupGuids);
101      Assert.AreEqual(2, childParentList.Count());
102
103      service.AddResourceToGroup(childGroup, parentGroup);
104      var mapping = service.GetClientGroupMapping();
105      Assert.AreEqual(1, mapping.Count());
106      Assert.AreEqual(mapping.First().Child, childGroup.Id);
107      Assert.AreEqual(mapping.First().Parent, parentGroup.Id);
108
109      service.DeleteClientGroup(otherGroup);
110      Assert.AreEqual(2, service.GetAllClientGroups().Count());
111
112      service.RemoveResourceFromGroup(childGroup, parentGroup);
113      Assert.AreEqual(0, service.GetClientGroupMapping().Count());
114    }
115
116    [TestMethod]
117    public void AddClientLogTest() {
118      ClearDB();
119      AccessService service = new AccessService();
120
121      DT.Client client = new DT.Client() {
122        Description = "testClient",
123        HeuristicLabVersion = "3.3.6",
124        MemorySize = 512,
125        NumberOfCores = 4,
126        Name = "testClient",
127        ProcessorType = "Intel i7",
128        Timestamp = DateTime.Now
129      };
130
131      client.Id = service.AddClient(client);
132      Assert.IsTrue(service.ClientExists(client.Id));
133
134      DateTime now = DateTime.Now;
135      DT.ClientLog log = new DT.ClientLog() { Message = "testMessage", ResourceId = client.Id, Timestamp = now };
136      service.AddClientLog(log);
137      Assert.AreEqual(1, service.GetClientLogsSince(now).Count());
138    }
139
140
141  }
142}
Note: See TracBrowser for help on using the repository browser.