public void CanNotLookupPick() { IPickRepository repo = new PickInMemoryRepository(); Service service = new Service(repo, new PickManual()); UserPickResponse actual = service.LookupPick(10); Assert.IsFalse(actual.Success); }
public void PicksCannotBeDuplicate() { IPickRepository repo = new PickInMemoryRepository(); Service service = new Service(repo, new PickRandom()); UserPickResponse actual = service.UserPick("test", 1, 1, 1, 1, 1, 50); Assert.IsFalse(actual.Success); Assert.IsNull(actual.PickResponse); }
public void UserCanNotChooseLessThan1orGreaterThan69() { IPickRepository repo = new PickInMemoryRepository(); Service service = new Service(repo, new PickRandom()); UserPickResponse actual = service.UserPick("test", -1, -2, 70, 71, 100, 50); Assert.IsFalse(actual.Success); Assert.IsNull(actual.PickResponse); }
public void UserCanChooseBetween1to69() { IPickRepository repo = new PickInMemoryRepository(); Service service = new Service(repo, new PickRandom()); UserPickResponse actual = service.UserPick("test", 1, 2, 69, 50, 20, 10); Assert.IsTrue(actual.Success); Assert.AreEqual(1, actual.PickResponse.NumberOne); Assert.AreEqual(2, actual.PickResponse.NumberTwo); Assert.AreEqual(69, actual.PickResponse.NumberThree); Assert.AreEqual(50, actual.PickResponse.NumberFour); Assert.AreEqual(20, actual.PickResponse.NumberFive); Assert.AreEqual(10, actual.PickResponse.Powerball); }
public UserPickResponse UserPick(string name, int pick1, int pick2, int pick3, int pick4, int pick5, int powerball) { UserPickResponse response = new UserPickResponse(); //check to make sure all numbers are unique List <int> numbers = new List <int>() { pick1, pick2, pick3, pick4, pick5 }; if (numbers.Distinct().Count() != 5) { response.Success = false; response.Message = "Your numbers are not all unique. There is a duplicate somewhere."; return(response); } if (numbers.Where(n => n < 1 || n > 69).Count() > 0) { response.Success = false; response.Message = "One or more of the pick is not between 1-69."; return(response); } if (powerball < 1 || powerball > 26) { response.Success = false; response.Message = "The powerball is not between 1-26"; return(response); } //create new pick then add it to the repository Pick userPick = new Pick { Name = name, NumberOne = pick1, NumberTwo = pick2, NumberThree = pick3, NumberFour = pick4, NumberFive = pick5, Powerball = powerball }; response.Success = true; response.PickResponse = userPick; repo.AddPick(userPick); return(response); }
public UserPickResponse LookupPick(int id) { UserPickResponse response = new UserPickResponse(); var picks = repo.GetPicksList(); foreach (var p in picks) { if (p.ID == id) { response.Success = true; response.PickResponse = p; return(response); } } response.Success = false; response.Message = $"ID {id} cannot be found."; return(response); }
public void LookupPick() { Console.Clear(); UserPickResponse response = new UserPickResponse(); Console.WriteLine("Pick Lookup:"); ConsoleIO.LineSeparator(); do {//get input from user Console.Write("What is the ID of the pick you want to lookup: "); int userInput; if (int.TryParse(Console.ReadLine(), out userInput)) { response = service.LookupPick(userInput); break; } else//make sure input is a number { Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine("Not a valid input. Needs to be a number."); Console.ResetColor(); } } while (true); //display pick or no pick found if (response.Success) { ConsoleIO.DisplayHeader(); ConsoleIO.DisplayPickInfo(response.PickResponse); } else { Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine(response.Message); Console.ResetColor(); } Console.WriteLine(); Console.WriteLine("Press any key to continue..."); Console.ReadKey(); }