internal static int GetIDFromUser(string prompt) { int output; Console.WriteLine(prompt); PickRepository repo = new PickRepository(Settings.FilePath); List <Pick> picks = repo.List(); int id = 0; bool isValid = false; while (!isValid) { string input = Console.ReadLine(); if (!int.TryParse(input, out output)) { Console.WriteLine("Enter a valid number."); } else if (output < 0 || output > picks.Count()) { Console.WriteLine("Pick ID does not exist"); } else { id = output; isValid = true; } } return(id); }
public void Execute() { Console.Clear(); Console.WriteLine("Lookup a pick."); Console.WriteLine(); PickRepository repo = new PickRepository(Settings.FilePath); List <Pick> picks = repo.List(); int index = ConsoleIO.GetIDFromUser("What is your Pick ID?"); foreach (var pick in picks) { if (pick.PickID == index) { Console.WriteLine($"Pick ID: {pick.PickID}"); Console.WriteLine($"Name: {pick.FirstName} {pick.LastName}"); Console.WriteLine($"Numbers: {pick.PickNumbers[0]},{pick.PickNumbers[1]}," + $"{pick.PickNumbers[2]},{pick.PickNumbers[3]},{pick.PickNumbers[4]},"); Console.WriteLine($"Powerball: {pick.Powerball}"); Console.WriteLine("\nPress any key to continue..."); Console.ReadKey(); } } }
public void CanAddPickToFile() { PickRepository repo = new PickRepository(_filePath); Pick newPick = new Pick(); newPick.PickID = 105; newPick.FirstName = "Ryan"; newPick.LastName = "Sheehan"; newPick.PickNumbers[0] = 1; newPick.PickNumbers[1] = 2; newPick.PickNumbers[2] = 3; newPick.PickNumbers[3] = 4; newPick.PickNumbers[4] = 5; newPick.Powerball = 6; repo.Add(newPick); List <Pick> picks = repo.List(); Assert.AreEqual(5, picks.Count()); Pick check = picks[4]; Assert.AreEqual(105, check.PickID); Assert.AreEqual("Ryan", check.FirstName); Assert.AreEqual("Sheehan", check.LastName); Assert.AreEqual(1, check.PickNumbers[0]); Assert.AreEqual(2, check.PickNumbers[1]); Assert.AreEqual(3, check.PickNumbers[2]); Assert.AreEqual(4, check.PickNumbers[3]); Assert.AreEqual(5, check.PickNumbers[4]); Assert.AreEqual(6, check.Powerball); }
//private IPickRepository _creator; //public AddPickWorkflow(IPickRepository concrete) //{ // _creator = concrete; //} public void Execute() { Console.Clear(); Console.WriteLine("Add your picks!"); Console.WriteLine(); Pick pick = new Pick(); pick.PickID = PickID.GetPickID(); pick.FirstName = ConsoleIO.GetStringFromUser("Enter your first name: "); pick.LastName = ConsoleIO.GetStringFromUser("Enter your last name: "); pick.PickNumbers = ConsoleIO.GetPickNumbers("Choose your 5 numbers: "); pick.Powerball = ConsoleIO.GetPowerball("Choose your POWERBALL: "); Console.WriteLine(); Console.WriteLine($"Pick ID: {pick.PickID}. {pick.FirstName} {pick.LastName}, you chose " + $"{pick.PickNumbers[0]},{pick.PickNumbers[1]},{pick.PickNumbers[2]},{pick.PickNumbers[3]}," + $"{pick.PickNumbers[4]} with a POWERBALL of {pick.Powerball}"); Console.WriteLine(); if (ConsoleIO.GetYesOrNo("Add the following information?") == "Y") { PickRepository repo = new PickRepository(Settings.FilePath); repo.Add(pick); Console.WriteLine("Your pick has been added!"); Console.WriteLine("Press any key to continue..."); Console.ReadKey(); } else { Console.WriteLine("Pick cancelled!"); Console.WriteLine("Press any key to continue..."); Console.ReadKey(); } }
public static IPickRepository Create() { IPickRepository repo = null; //add descision logic here. Grab setting from file string repoType = ConfigurationManager.AppSettings["repoType"]; //switch based on setting value switch (repoType) { case "memory": repo = new PickInMemoryRepo(); break; case "file": repo = new PickRepository(Settings.FilePath); break; default: //select proper exception TODO throw new Exception("unexpected setting for repo type"); //case "another repo" } //instantiate correct repo //return repo repo = new PickRepository(Settings.FilePath); return(repo); }
public static void FindPickByName() { Console.Clear(); Console.Write("Enter name of pick owner : "); string name = Console.ReadLine(); PickRepository pickFinder = new PickRepository(); List <Pick> results = pickFinder.FindByName(name); if (results.Count == 0) { Console.Clear(); Console.WriteLine("That name is not currently the owner of any existing pick."); Console.WriteLine(); Console.WriteLine("Press enter to return to the Main Menu."); Console.ReadLine(); } else { Console.Clear(); PickDisplay.DisplayHeader(); foreach (Pick result in results) { PickDisplay.DisplayPick(result); } Console.WriteLine(); Console.WriteLine("Press enter to return to the Main Menu."); Console.ReadLine(); } }
public void FastGrabQuickPick() { Pick pick = QuickPickLickitySplit(Name.GetName()); PickRepository repo = new PickRepository(); repo.ToFile(repo.Create(pick)); }
public void Create() { PickRepository repo = new PickRepository(); Pick pick = PickBalls.Create(); pick = repo.Create(pick); repo.ToFile(pick); }
internal static int GetPickID() { PickRepository repo = new PickRepository(Settings.FilePath); List <Pick> picks = repo.List(); int id = picks.Count() + 1; return(id); }
public List <Pick> GetPickList(int draftId) { IPickRepository pickRepository = new PickRepository(); IDraftRepository dr = new DraftRepository(); var draft = dr.GetById(draftId); var ret = pickRepository.GetPicksByDraft(draft); return(ret == null ? new List <Pick>() : ret.ToList()); }
public void CanGetPickListByDraftAndMember() { IPickRepository repository = new PickRepository(); repository.PickCard(_drafts[0], _members[0], _cards[0]); repository.PickCard(_drafts[0], _members[0], _cards[1]); repository.PickCard(_drafts[0], _members[0], _cards[2]); ICollection <Pick> picks = repository.GetPicksByDraftAndMember(_drafts[0], _members[0]); Assert.AreEqual(3, picks.Count); }
public bool IsCardPicked(int draftId, int cardId) { IPickRepository pr = new PickRepository(); IDraftRepository dr = new DraftRepository(); ICardRepository cr = new CardRepository(); var draft = dr.GetById(draftId); var card = cr.GetById(cardId); var picks = pr.GetPicksByCardAndDraft(card, draft); return(picks.Count > 0); }
public void ShowWinners() { PickRepository repo = new PickRepository(); Pick winningPick = GetWinningPick(); List <Pick> winners = repo.FindBestMatches(winningPick).ToList(); PickDisplay.DisplayWinningHeader(); PickDisplay.DisplayWinningPick(winningPick); foreach (Pick p in winners) { PickDisplay.DisplayWinningPick(p); } Console.ReadLine(); }
public void CannotPickSameCardTwiceDifferentMembers() { IPickRepository repository = new PickRepository(); repository.PickCard(_drafts[0], _members[0], _cards[0]); try { repository.PickCard(_drafts[0], _members[1], _cards[0]); } catch (GenericADOException) { return; } Assert.Fail("Should not be able to pick same card twice"); }
public bool PickCard(int draftId, int memberId, int cardId) { if (!IsMyTurn(draftId, memberId)) { return(FuturePickCard(draftId, memberId, cardId)); } IDraftRepository dr = new DraftRepository(); IMemberRepository mr = new MemberRepository(); ICardRepository cr = new CardRepository(); var draft = dr.GetById(draftId); var member = mr.GetById(memberId); var card = cr.GetById(cardId); if (draft.Finished || !draft.Started) { return(false); } IPickRepository pickRepository = new PickRepository(); try { var pick = pickRepository.PickCard(draft, member, card); } catch (GenericADOException) { return(false); } var picks = pickRepository.GetPicksByDraft(draft); IDraftMemberPositionsRepository dmpr = new DraftMemberPositionsRepository(); var nextMemberDraftPosition = dmpr.GetDraftMemberPositionByDraftAndPosition(draft, GetNextPickPosition(picks.Count, draft.DraftSize)); draft.CurrentTurn = nextMemberDraftPosition.Member; IDraftRepository draftRepository = new DraftRepository(); draftRepository.Update(draft); TryFuturePick(draftId); return(true); }
public static void FindPickByID() { Console.Clear(); int identifier = 0; bool validIdentifier = false; while (!validIdentifier) { Console.Write("Enter a three digit ID number to display pick : "); string input = Console.ReadLine(); if (!int.TryParse(input, out identifier)) { Console.Clear(); Console.WriteLine("That was not even a number!"); } else if (identifier < 100 || identifier > 999) { Console.Clear(); Console.WriteLine("That was not a three digit number!"); } else { validIdentifier = true; } } PickRepository pickFinder = new PickRepository(); Pick result = pickFinder.FindById(identifier); if (result.Identifier < 100 || result.Identifier > 999) { Console.Clear(); Console.WriteLine("That ID is not linked to any existing pick."); Console.WriteLine(); Console.WriteLine("Press enter to return to the Main Menu."); Console.ReadLine(); } else { Console.Clear(); PickDisplay.DisplayHeader(); PickDisplay.DisplayPick(result); Console.WriteLine(); Console.WriteLine("Press enter to return to the Main Menu."); Console.ReadLine(); } }
public void CanMakePick() { IPickRepository repository = new PickRepository(); var pick = repository.PickCard(_drafts[0], _members[0], _cards[0]); // use session to try to load the pick using (ISession session = _sessionFactory.OpenSession()) { var fromDb = session.Get <Pick>(pick.Id); // Test that the pick was successfully inserted Assert.IsNotNull(fromDb); Assert.AreNotSame(pick, fromDb); Assert.AreEqual(pick.Member.FullName, fromDb.Member.FullName); Assert.AreEqual(pick.Draft.Name, fromDb.Draft.Name); Assert.AreEqual(pick.Card.Name, fromDb.Card.Name); } }
public async void RetrievePicksTest_Scenario_ReturnsPicksFromDynamoClientWithLimitAndDescending() { var _dynamoClient = new Mock <IAmazonDynamoDB>(); var _pickMapper = new Mock <IDynamoMapper <Pick> >(); var dynamoQueryResponse = new QueryResponse(); var expectedPick = new Pick(); dynamoQueryResponse.Items.Add(new Dictionary <string, AttributeValue> { { "DraftId", new AttributeValue { S = "test" } }, { "Id", new AttributeValue { N = "1" } }, { "PlayerId", new AttributeValue { S = "test player id" } }, { "Selection", new AttributeValue { S = "test selection" } } }); _dynamoClient .Setup(x => x.QueryAsync(It.IsAny <QueryRequest>(), It.IsAny <CancellationToken>())) .ReturnsAsync(dynamoQueryResponse); _pickMapper .Setup(pm => pm.Map(It.IsAny <Dictionary <string, AttributeValue> >())) .Returns(expectedPick); var pickRepository = new PickRepository(_dynamoClient.Object, _pickMapper.Object); var result = await pickRepository.RetrieveByDraftId("testDraftId", true, 1); Assert.Equal(expectedPick, result[0]); _dynamoClient.Verify(dc => dc.QueryAsync(It.Is <QueryRequest>(req => req.ScanIndexForward == false && req.Limit == 1), It.IsAny <CancellationToken>()), Times.Once); }
public void CanReadDataFromFile() { PickRepository repo = new PickRepository(_filePath); List <Pick> picks = repo.List(); Assert.AreEqual(4, picks.Count); Pick check = picks[0]; Assert.AreEqual(101, check.PickID); Assert.AreEqual("Ryan", check.FirstName); Assert.AreEqual("Sheehan", check.LastName); Assert.AreEqual(1, check.PickNumbers[0]); Assert.AreEqual(2, check.PickNumbers[1]); Assert.AreEqual(3, check.PickNumbers[2]); Assert.AreEqual(4, check.PickNumbers[3]); Assert.AreEqual(5, check.PickNumbers[4]); Assert.AreEqual(6, check.Powerball); }
public async void PutTest_Scenario_PutsPickInDynamoClient() { var pickToAdd = new Pick() { DraftId = "testDraftId", Id = 1, PlayerId = "testId", Selection = "potato wedges" }; var expectedRequest = new PutItemRequest { TableName = "Picks", Item = new Dictionary <string, AttributeValue> { { "DraftId", new AttributeValue { S = "test" } }, { "Id", new AttributeValue { N = "1" } }, { "PlayerId", new AttributeValue { S = "test player id" } }, { "Selection", new AttributeValue { S = "test selection" } } } }; var _dynamoClient = new Mock <IAmazonDynamoDB>(); var _pickMapper = new Mock <IDynamoMapper <Pick> >(); var pickRepository = new PickRepository(_dynamoClient.Object, _pickMapper.Object); await pickRepository.Put(pickToAdd); _dynamoClient.Verify(dc => dc.PutItemAsync(It.Is <PutItemRequest>(req => req.Item["Selection"].S == pickToAdd.Selection), It.IsAny <CancellationToken>()), Times.Once); }
public void GetFastBallsQuickNowGo() { Console.Clear(); bool validInput = false; int number = 0; while (!validInput) { Console.Write("Gimme a number : "); string input = Console.ReadLine(); if (int.TryParse(input, out number)) { validInput = true; } else { Console.Clear(); Console.WriteLine("Try again, Mr. Not-Smart"); } } PickRepository repo = new PickRepository(); List <Pick> allOfThem = new List <Pick>(); for (int i = number; i > 0; i--) { Pick pick = QuickPickLickitySplit(Name.GetName()); allOfThem.Add(pick); } foreach (Pick p in allOfThem) { repo.ToFile(repo.Create(p)); } Console.Clear(); Console.WriteLine("It is done."); Console.ReadLine(); }
public List <Pick> GetLatestPicksByPlayer(int draftId, int memberId) { IDraftRepository dr = new DraftRepository(); IPickRepository pr = new PickRepository(); IMemberRepository mr = new MemberRepository(); var draft = dr.GetById(draftId); var member = mr.GetById(memberId); var picksCollection = pr.GetPicksByDraftAndMember(draft, member); if (picksCollection == null) { return(new List <Pick>()); } var picks = picksCollection.ToList(); picks.Sort((p1, p2) => p1.CreatedDate.CompareTo(p2.CreatedDate)); return(picks); }
public PickApiController(PickRepository repository) { this.repository = repository; this.OnCreated(); }
public PickService(PickRepository pickRepository) { this.pickRepository = pickRepository; }