public void RemoveBadgeAccess_ShouldReturnTrue() { var repo = new BadgesRepo(); var badge = new Badge(1, new List <string>()); repo.AddBadgeToCollection(badge); repo.AddBadgeAccess(1, "A1"); bool wasRemoved = repo.RemoveBadgeAccess(1, "A1"); Assert.IsTrue(wasRemoved); }
public void UpdateBadgeAccess() { Console.Clear(); Badge badge = new Badge(); Console.Write("Enter the Badge ID: "); // Verifying user input string possibleID = Console.ReadLine(); if (Int32.TryParse(possibleID, out int userInput)) { badge.BadgeID = Convert.ToInt32(possibleID); } else { Console.WriteLine("\n" + "Invalid Badge ID, please try again.\n" + "Press any key to continue..."); Console.ReadKey(); UpdateBadgeAccess(); } // Verifying the badge exists if (accessLog.DoesListContainBadgeID(badge) == true) { Console.Clear(); // Displays chosen badge ID Console.WriteLine($"Badge ID: {accessLog.DisplayBadgeID(userInput)}"); // Displays chosen badge door access separated by ',' Console.WriteLine($"Current door access: {accessLog.DisplayBadgeAccess(userInput)}"); Console.WriteLine(""); Console.WriteLine("What would you like to do: \n" + "[1] Add a door access\n" + "[2] Remove a door access\n" + "[3] Cancel\n" + ""); string updateOption = Console.ReadLine(); Console.Clear(); switch (updateOption) { // AddBadgeAccess() case "1": Console.WriteLine($"Current door access: {accessLog.DisplayBadgeAccess(userInput)}"); Console.Write("\n" + "What door access would you like to add?: "); // Setting all proper inputs to correct format string addAccess = Console.ReadLine().ToUpper(); if (possibleDoors.Contains(addAccess)) { if (accessLog.CheckAssignedBadgeAccess(userInput, addAccess) == true) { Console.WriteLine("\n" + "Current badge has already been given access to chosen door. \n" + "Press any key to continue..."); Console.ReadKey(); MainMenu(); } else { Console.Write($"\n" + $"You want to add\n" + $"\n" + $"Door access: {addAccess} \n" + $"To Badge ID: {accessLog.DisplayBadgeID(userInput)}\n" + $"\n" + $"Correct (y/n)?: "); string confirmUpdate = Console.ReadLine(); if (confirmUpdate == "y" || confirmUpdate == "Y") { accessLog.AddBadgeAccess(userInput, addAccess); Console.WriteLine("\n" + "Door access added."); } else { Console.WriteLine("\n" + "Update cancelled."); } } } else { Console.WriteLine("\n" + "Assignment of unrecognized door, could not complete request.\n" + "Press any key to continue..."); Console.ReadKey(); MainMenu(); } break; // RemoveBadgeAccess() case "2": Console.WriteLine($"Current door access: {accessLog.DisplayBadgeAccess(userInput)}"); Console.Write("\n" + "What door access would you like to remove?: "); string removeAccess = Console.ReadLine().ToUpper(); // Verifying proper input if (possibleDoors.Contains(removeAccess)) { // Verifying badge being updated has been assigned access to door for removal if (accessLog.CheckAssignedBadgeAccess(userInput, removeAccess) == true) { Console.Write($"\n" + $"You want to remove\n" + $"\n" + $"Door access: {removeAccess} \n" + $"From Badge ID: {accessLog.DisplayBadgeID(userInput)}\n" + $"\n" + $"Correct (y/n)?"); string confirmRemoval = Console.ReadLine(); if (confirmRemoval == "y" || confirmRemoval == "Y") { accessLog.RemoveBadgeAccess(userInput, removeAccess); Console.WriteLine("\n" + "Door access removed"); } else { Console.WriteLine("\n" + "Removal cancelled."); } } else { Console.WriteLine($"\n" + $"Selected badge currently does not have access to door {removeAccess}.\n" + $"Press any key to continue..."); Console.ReadKey(); MainMenu(); } } else { Console.WriteLine("\n" + "Please enter proper door access.\n" + "Press any key to continue..."); Console.ReadKey(); MainMenu(); } break; default: MainMenu(); break; } // ReturnToMainMenu() Console.WriteLine("Press any key to continue..."); Console.ReadKey(); MainMenu(); // } else { Console.WriteLine("\n" + "Selected Badge ID does not exist.\n" + "Press any key to continue..."); Console.ReadKey(); MainMenu(); } }