public void UpdateExistingBadge_ShouldReturnTrue() //Update { //Arrange Badge oldBadge = new Badge(001, new List <string> { "A1", "A2" }); Badge newBadge = new Badge(001, new List <string> { "A2", "A3", "B5" }); Badge_Repo repo = new Badge_Repo(); repo.AddBadge(oldBadge); //Act bool updateResult = repo.UpdateExistingBadge(oldBadge.BadgeID, newBadge); //Assert Assert.IsTrue(updateResult); }
public void EditBadge() { Console.Clear(); Header(); Console.WriteLine("=-=-=-=- Update a Badge -=-=-=-="); Console.WriteLine("What is the badge number to update:"); int badgeNum = Convert.ToInt32(Console.ReadLine()); Badge badgeToUpdate = _repo.GetABadgeByID(badgeNum); List <string> doorsOnBadge = new List <string>(); if (badgeToUpdate != null) { doorsOnBadge = badgeToUpdate.Doors; bool looper = true; while (looper) { Console.Clear(); Header(); Console.WriteLine("=-=-=-=- Update a Badge -=-=-=-="); string doorsResult = string.Join(",", badgeToUpdate.Doors); Console.WriteLine($"Badge #{badgeToUpdate.BadgeID} has access to doors: {doorsResult}."); Console.WriteLine("What would you like to do?"); Console.WriteLine(" 1> Remove a door"); Console.WriteLine(" 2> Add a door"); Console.WriteLine(" 3> Finish Updating Badge"); string menuSelect = Console.ReadLine(); switch (menuSelect) { case "1": Console.WriteLine("Which door would you like to remove?"); string doorToRemove = Console.ReadLine(); doorsOnBadge.Remove(doorToRemove); badgeToUpdate.Doors = doorsOnBadge; Console.WriteLine("Door Removed"); doorsResult = string.Join(",", badgeToUpdate.Doors); Console.WriteLine($"Badge #{badgeToUpdate.BadgeID} has access to doors: {doorsResult}."); Console.WriteLine("Press any key to continue."); Console.ReadKey(); break; case "2": Console.WriteLine("Which door would you like to add?"); string doorToAdd = Console.ReadLine(); doorsOnBadge.Add(doorToAdd); badgeToUpdate.Doors = doorsOnBadge; Console.WriteLine("Door Added"); doorsResult = string.Join(",", badgeToUpdate.Doors); Console.WriteLine($"Badge #{badgeToUpdate.BadgeID} has access to doors: {doorsResult}."); Console.WriteLine("Press any key to continue."); Console.ReadKey(); break; case "3": looper = false; break; } } bool wasUpdate = _repo.UpdateExistingBadge(badgeNum, badgeToUpdate); if (wasUpdate == true) { Console.WriteLine("Badge updated successfully"); } else { Console.WriteLine("Oops! Something went wrong. Please try update again."); } } else { Console.WriteLine("Badge ID not found."); } Console.WriteLine("Press any key to return to the main menu"); Console.ReadKey(); }