Free cookie consent management tool by TermsFeed Policy Generator

source: branches/HeuristicLab.Services.Authentication Prototype/UnitTests/HeuristicLabRoleProviderTest.cs @ 3955

Last change on this file since 3955 was 3955, checked in by bfarka, 14 years ago

created impl and test of AddUsersToRoles (#1046)

File size: 9.6 KB
Line 
1using Service.Provider;
2using Microsoft.VisualStudio.TestTools.UnitTesting;
3using System.Linq;
4using System.Collections.Generic;
5namespace UnitTests {
6  /// <summary>
7  ///This is a test class for HeuristicLabRoleProviderTest and is intended
8  ///to contain all HeuristicLabRoleProviderTest Unit Tests
9  ///</summary>
10  [TestClass()]
11  public class HeuristicLabRoleProviderTest : AbstractHeuristicLabTest {
12    private TestContext testContextInstance;
13    private const string TEST_ROLE_NAME = "testRole";
14    /// <summary>
15    ///Gets or sets the test context which provides
16    ///information about and functionality for the current test run.
17    ///</summary>
18    public TestContext TestContext {
19      get {
20        return testContextInstance;
21      }
22      set {
23        testContextInstance = value;
24      }
25    }
26
27    #region Additional test attributes
28    //
29    //You can use the following additional attributes as you write your tests:
30    //
31    //Use ClassInitialize to run code before running the first test in the class
32    //[ClassInitialize()]
33    //public static void MyClassInitialize(TestContext testContext)
34    //{
35    //}
36    //
37    //Use ClassCleanup to run code after all tests in a class have run
38    //[ClassCleanup()]
39    //public static void MyClassCleanup()
40    //{
41    //}
42    //
43    //Use TestInitialize to run code before running each test
44    //[TestInitialize()]
45    //public void MyTestInitialize()
46    //{
47    //}
48    //
49    //Use TestCleanup to run code after each test has run
50    //[TestCleanup()]
51    //public void MyTestCleanup()
52    //{
53    //}
54    //
55    #endregion
56
57
58    /// <summary>
59    ///A test for ApplicationName
60    ///</summary>
61    [TestMethod()]
62    public void ApplicationNameTest() {
63      HeuristicLabRoleProvider target = new HeuristicLabRoleProvider();
64      string expected = "JavaIsEvenCooler";
65      string actual;
66      target.ApplicationName = expected;
67      actual = target.ApplicationName;
68      Assert.AreEqual(expected, actual);
69    }
70
71    /// <summary>
72    ///tests if the RoleExits method works --> test is done in a positiv and negativ way
73    ///</summary>
74    [TestMethod()]
75    public void RoleExistsTest() {
76      HeuristicLabRoleProvider target = new HeuristicLabRoleProvider();
77      Persistence.HeuristicLabRole role = new Persistence.HeuristicLabRole();
78      role.RoleName = TEST_ROLE_NAME;
79      db.HeuristicLabRole.InsertOnSubmit((Persistence.HeuristicLabRole)role);
80      db.SubmitChanges();
81      Assert.IsTrue(target.RoleExists(TEST_ROLE_NAME));
82      Assert.IsFalse(target.RoleExists(TEST_ROLE_NAME + TEST_ROLE_NAME));
83    }
84
85    /// <summary>
86    ///A test for RemoveUsersFromRoles
87    ///</summary>
88    [TestMethod()]
89    public void RemoveUsersFromRolesTest() {
90      HeuristicLabRoleProvider target = new HeuristicLabRoleProvider(); // TODO: Initialize to an appropriate value
91      string[] usernames = null; // TODO: Initialize to an appropriate value
92      string[] roleNames = null; // TODO: Initialize to an appropriate value
93      target.RemoveUsersFromRoles(usernames, roleNames);
94      Assert.Inconclusive("A method that does not return a value cannot be verified.");
95    }
96
97    /// <summary>
98    ///A test for IsUserInRole
99    ///</summary>
100    [TestMethod()]
101    public void IsUserInRoleTest() {
102      HeuristicLabRoleProvider target = new HeuristicLabRoleProvider(); // TODO: Initialize to an appropriate value
103      string username = string.Empty; // TODO: Initialize to an appropriate value
104      string roleName = string.Empty; // TODO: Initialize to an appropriate value
105      bool expected = false; // TODO: Initialize to an appropriate value
106      bool actual;
107      actual = target.IsUserInRole(username, roleName);
108      Assert.AreEqual(expected, actual);
109      Assert.Inconclusive("Verify the correctness of this test method.");
110    }
111
112    /// <summary>
113    ///A test for GetUsersInRole
114    ///</summary>
115    [TestMethod()]
116    public void GetUsersInRoleTest() {
117      HeuristicLabRoleProvider target = new HeuristicLabRoleProvider(); // TODO: Initialize to an appropriate value
118      string roleName = string.Empty; // TODO: Initialize to an appropriate value
119      string[] expected = null; // TODO: Initialize to an appropriate value
120      string[] actual;
121      actual = target.GetUsersInRole(roleName);
122      Assert.AreEqual(expected, actual);
123      Assert.Inconclusive("Verify the correctness of this test method.");
124    }
125
126    /// <summary>
127    ///A test for GetRolesForUser
128    ///</summary>
129    [TestMethod()]
130    public void GetRolesForUserTest() {
131      HeuristicLabRoleProvider target = new HeuristicLabRoleProvider(); // TODO: Initialize to an appropriate value
132      string username = string.Empty; // TODO: Initialize to an appropriate value
133      string[] expected = null; // TODO: Initialize to an appropriate value
134      string[] actual;
135      actual = target.GetRolesForUser(username);
136      Assert.AreEqual(expected, actual);
137      Assert.Inconclusive("Verify the correctness of this test method.");
138    }
139
140    /// <summary>
141    ///A test for GetAllRoles
142    ///</summary>
143    [TestMethod()]
144    public void GetAllRolesTest() {
145      HeuristicLabRoleProvider target = new HeuristicLabRoleProvider();
146      List<string> roleNames = new List<string>();
147      roleNames.Add("Pascal");
148      roleNames.Add("Java");
149      roleNames.Add("Pascal");
150      roleNames.Add("VisalBasic");
151      foreach (string s in roleNames) {
152        target.CreateRole(s);
153      }
154      target.CreateRole(null);
155      string[] roles = target.GetAllRoles();
156      foreach(string role in roles)
157      {
158        Assert.IsTrue(roleNames.Remove(role));
159      }
160      Assert.IsTrue(roleNames.Count == 0);
161    }
162
163    /// <summary>
164    ///A test for FindUsersInRole
165    ///</summary>
166    [TestMethod()]
167    public void FindUsersInRoleTest() {
168      HeuristicLabRoleProvider target = new HeuristicLabRoleProvider(); // TODO: Initialize to an appropriate value
169      string roleName = string.Empty; // TODO: Initialize to an appropriate value
170      string usernameToMatch = string.Empty; // TODO: Initialize to an appropriate value
171      string[] expected = null; // TODO: Initialize to an appropriate value
172      string[] actual;
173      actual = target.FindUsersInRole(roleName, usernameToMatch);
174      Assert.AreEqual(expected, actual);
175      Assert.Inconclusive("Verify the correctness of this test method.");
176    }
177
178    /// <summary>
179    ///A test for DeleteRole
180    ///</summary>
181    [TestMethod()]
182    public void DeleteRoleTest() {
183      HeuristicLabRoleProvider target = new HeuristicLabRoleProvider(); // TODO: Initialize to an appropriate value
184      string roleName = string.Empty; // TODO: Initialize to an appropriate value
185      bool throwOnPopulatedRole = false; // TODO: Initialize to an appropriate value
186      bool expected = false; // TODO: Initialize to an appropriate value
187      bool actual;
188      actual = target.DeleteRole(roleName, throwOnPopulatedRole);
189      Assert.AreEqual(expected, actual);
190      Assert.Inconclusive("Verify the correctness of this test method.");
191    }
192
193    /// <summary>
194    ///A test for CreateRole
195    ///</summary>
196    [TestMethod()]
197    public void CreateRoleTest() {
198      HeuristicLabRoleProvider target = new HeuristicLabRoleProvider();
199      target.CreateRole("role1");
200      target.CreateRole("role2");
201      target.CreateRole("role3", true);
202      Assert.IsTrue(db.HeuristicLabRole.Count(r => r.RoleName == "role1" && r.IsPermission == false) == 1);
203      Assert.IsTrue(db.HeuristicLabRole.Count(r => r.RoleName == "role2" && r.IsPermission == false) == 1);
204      Assert.IsTrue(db.HeuristicLabRole.Count(r => r.RoleName == "role3" && r.IsPermission == true) == 1);
205    }
206
207    protected int getUserRolesCount() {
208      return db.HeuristicLabUserRole.Count();
209           
210     
211    }
212
213
214    /// <summary>
215    ///A test for AddUsersToRoles
216    ///</summary>
217    [TestMethod()]
218    public void AddUsersToRolesTest() {
219      HeuristicLabRoleProvider target = new HeuristicLabRoleProvider(); // TODO: Initialize to an appropriate value
220      Dictionary<string, Persistence.HeuristicLabUser> users = new Dictionary<string, Persistence.HeuristicLabUser>();
221      List<string> roles = new List<string>();
222      users.Add("dkhan", new Persistence.HeuristicLabUser("dkhan", "foo", "password", "comment"));
223      users.Add("hmayr", new Persistence.HeuristicLabUser("hmayr", "foo", "password", "comment"));
224      users.Add("bfarka", new Persistence.HeuristicLabUser("bfarka", "foo", "password", "comment"));
225
226      roles.Add("admin");
227      roles.Add("users");
228      //testing to create roles with users that doesn't exists
229      target.AddUsersToRoles(users.Keys.ToArray(), roles.ToArray());
230      Assert.IsTrue(getUserRolesCount() == 0);
231
232      foreach (string role in roles)
233      {
234        target.CreateRole(role);
235      }
236      target.AddUsersToRoles(users.Keys.ToArray(), roles.ToArray());
237      Assert.IsTrue(getUserRolesCount() == 0);
238      foreach (Persistence.HeuristicLabUser user in users.Values) {
239        db.HeuristicLabUsers.InsertOnSubmit(user);
240      }
241      db.SubmitChanges();
242      target.AddUsersToRoles(users.Keys.ToArray(), roles.ToArray());
243      Assert.IsTrue(getUserRolesCount() == (roles.Count + users.Count));
244
245    }
246
247    /// <summary>
248    ///A test for HeuristicLabRoleProvider Constructor
249    ///</summary>
250    [TestMethod()]
251    public void HeuristicLabRoleProviderConstructorTest() {
252      HeuristicLabRoleProvider target = new HeuristicLabRoleProvider();
253      Assert.IsNotNull(target);
254    }
255  }
256
257
258
259}
Note: See TracBrowser for help on using the repository browser.