public void FillListView() { listViewUser.Items.Clear(); List <UserModel> users = UserOverview.GetAllUsers(); List <IncidentModel> incidents = IncidentOverview.GetIncidents(); foreach (UserModel user in users) { int NumberOfTickets = 0; foreach (var incident in incidents) { if (user.UserId == incident.UserId) { NumberOfTickets++; } } ListViewItem item = new ListViewItem(user.UserId.ToString()); item.SubItems.Add(user.Email); item.SubItems.Add(user.FirstName); item.SubItems.Add(user.LastName); item.SubItems.Add(NumberOfTickets.ToString()); item.SubItems.Add(user.TypeOfUser); listViewUser.Items.Add(item); } }
public void GetAllUsers_Authorized_200() { var controller = new UserManagementController(); var admin = _ut.CreateUserObject(); admin.IsAdministrator = true; var adminSession = _ut.CreateSessionObject(admin); _ut.CreateSessionInDb(adminSession); var expectedStatusCode = HttpStatusCode.OK; var endpoint = API_Route_Local + "/users"; controller.Request = new HttpRequestMessage { RequestUri = new Uri(endpoint) }; controller.Request.Headers.Add("token", adminSession.Token); IHttpActionResult actionresult = controller.GetAllUsers(); Assert.IsInstanceOfType(actionresult, typeof(NegotiatedContentResult <List <GetAllUsersResponseDataItem> >)); var contentresult = actionresult as NegotiatedContentResult <List <GetAllUsersResponseDataItem> >; Assert.AreEqual(expectedStatusCode, contentresult.StatusCode); }
//vul de LV. public void ListViewLoad() { //activeer sorter. LvwColumnSorter = new ListViewColumnSorter(); this.lv_incidents.ListViewItemSorter = LvwColumnSorter; //leeg alles. Incidents.Clear(); Users.Clear(); lv_incidents.Items.Clear(); lv_incidents.Refresh(); //vul de lijsten. Incidents = IncidentOverview.GetIncidents(); Users = UserController.GetAllUsers(); //vul de LV aan met items per Incident foreach (IncidentModel incident in Incidents) { ListViewItem item = new ListViewItem(incident.IncidentId.ToString()); item.SubItems.Add(incident.Subject); foreach (UserModel user in Users) { if (incident.UserId == user.UserId) { item.SubItems.Add(user.Email); item.SubItems.Add(user.FirstName + " " + user.LastName); item.SubItems.Add(user.UserId.ToString()); break; } } item.SubItems.Add(incident.DateCreated.ToString("dd/MM/yyyy H:mm")); item.SubItems.Add(incident.Status); lv_incidents.Items.Add(item); } lv_incidents.Refresh(); //maak de LV kopjes groot genoeg. foreach (ColumnHeader ch in this.lv_incidents.Columns) { ch.Width = -2; } }
public void GetAllUsers_UserIsNotAdministrator_400() { newUser = _tu.CreateUserObject(); newUser.IsAdministrator = false; Session newSession = _tu.CreateSessionObject(newUser); _tu.CreateSessionInDb(newSession); var endpoint = API_ROUTE_LOCAL + "/users"; _umController.Request = new HttpRequestMessage { RequestUri = new Uri(endpoint) }; var request = new HttpRequestMessage(); request.Headers.Add("token", newSession.Token); _umController.Request = request; //user is not adminstrator and therefore cannot return all users. // should result in an UserIsNotAdministratorException // and return a 401 NegotiatedContentResult <string> response = (NegotiatedContentResult <string>)_umController.GetAllUsers(); Assert.AreEqual(HttpStatusCode.Unauthorized, response.StatusCode); Assert.AreEqual("Non-administrators cannot view all users.", response.Content.ToString()); }
public void FakeSessionToken_Unauthorized_401() { var controller = new UserManagementController(); var expectedStatusCode = HttpStatusCode.Unauthorized; var endpoint = API_Route_Local + "/users"; controller.Request = new HttpRequestMessage { RequestUri = new Uri(endpoint) }; // fake token header added controller.Request.Headers.Add("token", "thisisafaketoken"); NegotiatedContentResult <string> actionresult = (NegotiatedContentResult <string>)controller.GetAllUsers(); Assert.AreEqual(expectedStatusCode, actionresult.StatusCode); }
public void GetAllUsers_Unauthorized_401() { var controller = new UserManagementController(); var admin = _ut.CreateUserObject(); admin.IsAdministrator = false; var adminSession = _ut.CreateSessionObject(admin); _ut.CreateSessionInDb(adminSession); var expectedStatusCode = HttpStatusCode.Unauthorized; var endpoint = API_Route_Local + "/users"; controller.Request = new HttpRequestMessage { RequestUri = new Uri(endpoint) }; controller.Request.Headers.Add("token", adminSession.Token); NegotiatedContentResult <string> actionresult = (NegotiatedContentResult <string>)controller.GetAllUsers(); Assert.AreEqual(expectedStatusCode, actionresult.StatusCode); }