public void TestCelebGuessedGoesToCorrectState() { Celeb celeb = new Celeb("Danny Dyer"); celeb.Guess(); celeb.State.Should().Be(CelebState.GUESSED); }
// get specific celeb data from site. mainlly for "ReseetRecord" method public Celeb GetCeleb(int id, string html) { Celeb celeb = new Celeb { HtmlPath = html }; try { MatchCollection clb = Regex.Matches(html, "<span class=\"itemprop\">(.+?)</span>", RegexOptions.Singleline); celeb.Id = id; celeb.Name = clb[0].Groups[1].Value; for (int i = 1; i < clb.Count; i++) { celeb.Role += clb[i].Groups[1].Value.Replace("\n", "") + " "; } clb = Regex.Matches(html, "<time datetime=\"(.+?)\">", RegexOptions.Singleline); celeb.BirthDate = DateTime.Parse(clb[0].Groups[1].Value).ToString("dd/MM/yyyy"); if (celeb.Role.IndexOf("Actress") != -1) { celeb.Gender = "Female"; } clb = Regex.Matches(html, "Picture\"\nsrc=\"https://m.media-amazon.com/images/(.+?).jpg", RegexOptions.Singleline); celeb.Image = clb[0].Value.Replace("Picture\"\nsrc=\"", ""); } catch (Exception ex) { logger.Log(this.ToString() + " : " + ex.ToString()); } return(celeb); }
public async Task <IActionResult> PutCeleb(int id, Celeb celeb) { if (id != celeb.Id) { return(BadRequest()); } _context.Entry(celeb).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!CelebExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public Game GetGameByCelebId(int CelebId) { Celeb celeb = _context.Celeb.Single(c => c.Id == CelebId); return(_context.Game.Include(g => g.Celebs) .Single(g => g.Id == celeb.GameId)); }
public void TakePhotoImpl() { if (reloadTimer > 0.0f || filmLeft <= 0) { return; } reloadTimer = reloadDuration; Celeb celeb = GameObject.FindObjectOfType <Celeb>(); float score = celeb.GetScore(); floatingScores.Add(new FloatingScore(score, celeb.transform.position + new Vector3(0.0f, 1.0f, 0.0f))); money += score; filmLeft -= 1; GetComponent <AudioSource>().PlayOneShot(shutter); GameObject.FindObjectOfType <Flash>().flash(); if (filmLeft <= 0) { FindObjectOfType <FinalScore>().GameOver(money); } }
void CreateCeleb(string type) { GameObject g = Instantiate(celebPrefab, celebSpawn.position, Quaternion.identity) as GameObject; Celeb instance = g.GetComponent <Celeb> (); if (type == "fb") { instance.SetImage(0); } if (type == "fw") { instance.SetImage(1); } if (type == "mb") { instance.SetImage(2); } if (type == "mw") { instance.SetImage(3); } float time = Random.Range(2f, 7f); //Invoke ("CreateCeleb", time); }
public async Task <IActionResult> PatchCeleb(int id, Celeb celeb) { if (id != celeb.Id) { return(BadRequest()); } var celebRetrieved = _gameService.GetCeleb(id); if (celebRetrieved.State != celeb.State) { switch (celeb.State) { case CelebState.GUESSED: _gameService.CelebGuessed(id); break; case CelebState.BURNED: _gameService.CelebBurned(id); break; } } return(NoContent()); }
public async Task <ActionResult <Celeb> > PostCeleb(Celeb celeb) { _context.Celeb.Add(celeb); await _context.SaveChangesAsync(); return(CreatedAtAction("GetCeleb", new { id = celeb.Id }, celeb)); }
public ActionResult <Celeb> PostCeleb(int gameId, Celeb celeb) { if (gameId != celeb.GameId) { throw new ArgumentException($"gameId: {gameId} doesn't equal game id in celeb: {celeb.GameId}"); } return(_gameService.AddCeleb(celeb)); }
public void CelebBurned(int celebId) { Celeb celeb = _context.Celeb.Single(c => c.Id == celebId); celeb.Burn(); _context.Celeb.Update(celeb); _context.SaveChanges(); }
public void TestAttemptToThrowBurnedCelebBackIntoHat() { Celeb celeb = new Celeb("Danny Dyer"); celeb.Burn(); celeb.Invoking(c => c.PutBackIntoHat()) .Should().Throw <InvalidOperationException>(); }
public void TestCelebGuessedWhenStateInvalid() { Celeb celeb = new Celeb("Danny Dyer"); celeb.Guess(); celeb.Invoking(c => c.Guess()) .Should().Throw <InvalidOperationException>(); }
public static Celeb AddCelebToGame(Celeb celeb, Game game) { var request = new RestRequest($"{GAMES_RESOURCE}/{game.Id}/{CELEBS_RESOURCE}"); request.AddJsonBody(celeb); var response = Client.Post <Celeb>(request); return(response.Data); }
public ResponseObj Create(Celeb celeb) { var result = celebRepo.AddCeleb(celeb); return(new ResponseObj { Success = result > 0 }); }
public static void UpdateCeleb(Celeb celeb) { var request = new RestRequest($"{CELEBS_RESOURCE}/{celeb.Id}"); request.AddJsonBody(celeb); var response = Client.Patch(request); response.StatusCode.Should().Be(HttpStatusCode.NoContent); }
private static ListViewItem CelebItem(Celeb celeb) => new ListViewItem( new[] { celeb.Id, celeb.Name, celeb.BirthDate, string.Join(", ", celeb.Titles), celeb.Sex.ToString() });
public void TestGameStateCelebGuessedGame() { Game game = new Game(); var geezer = new Celeb("Danny Dyer"); game.AddCeleb(geezer); game.AddCeleb(new Celeb("Geoff Capes")); game.State.Should().Be(RoundState.ROUND_READY_TO_START); geezer.Guess(); game.State.Should().Be(RoundState.ROUND_IN_PROGRESS); }
public bool Update(Celeb celeb) { IEnumerable <Celeb> existing = GetAllCelebs(); var newList = existing.ToList(); var list = newList.Where(o => o.Id != celeb.Id).ToList(); list.Add(celeb); InternalSave(list); return(true); }
public ResponseObj Delete(Celeb celeb) { var celebToDelete = celebRepo .GetCelebs(x => x.CelebId == celeb.CelebId) .SingleOrDefault(); var result = celebRepo.DeleteCeleb(celebToDelete); return(new ResponseObj { Success = result > 0 }); }
public async Task <ActionResult <Celeb> > Put(string id, [FromBody] Celeb value) { if (!this.db.Celebs.TryGetValue(id, out _)) { return(NotFound()); } var entity = this.db.Celebs[id] = value.ToEntity(id); await this.db.CommitAsync(); return(entity.AsDTO()); }
public async Task <ActionResult> Post([FromBody] Celeb celeb) { try { this.db.Celebs.Add(celeb.Id, celeb.ToEntity()); await this.db.CommitAsync(); return(Ok()); } catch (ArgumentException) { return(BadRequest()); } }
public void TestGameStateAllCelebsGuessedGame() { Game game = new Game(); var geezer = new Celeb("Danny Dyer"); game.AddCeleb(geezer); var geoff = new Celeb("Geoff Capes"); game.AddCeleb(geoff); game.State.Should().Be(RoundState.ROUND_READY_TO_START); geezer.Guess(); geoff.Guess(); game.State.Should().Be(RoundState.ROUND_COMPLETE); }
public ResponseObj Edit(Celeb celeb) { var celebEdit = celebRepo .GetCelebs(x => x.CelebId == celeb.CelebId) .SingleOrDefault(); celebEdit.CelebName = celeb.CelebName; celebEdit.CelebCountry = celeb.CelebCountry; celebEdit.CelebAge = celeb.CelebAge; var result = celebRepo.Save(); return(new ResponseObj { Success = result > 0 }); }
// reuse for all json file modification methods private string EditRecord(Action type, int id, JObject celeb) { string json = string.Empty; try { if (File.Exists(filePath)) { json = File.ReadAllText(filePath); List <Celeb> data = JsonConvert.DeserializeObject <List <Celeb> >(json); switch (type) { case Action.REMOVE: { var itemToRemove = data.SingleOrDefault(r => r.Id == id); data.Remove(itemToRemove); break; } case Action.ADD: { Celeb clb = celeb.ToObject <Celeb>(); clb.Id = data.Last().Id + 1; data.Add(clb); break; } case Action.UPDATE: { int index = data.FindIndex(a => a.Id == id); Celeb clb = celeb.ToObject <Celeb>(); clb.Id = id; data[index] = clb; break; } } json = JsonConvert.SerializeObject(data); File.WriteAllText(filePath, json); } } catch (Exception ex) { logger.Log(this.ToString() + " : " + ex.ToString()); } return(json); }
public void TestGetNullBackIfNoneInHat() { Game game = new Game(); var geezer = new Celeb("Danny Dyer"); game.AddCeleb(geezer); var geoff = new Celeb("Geoff Capes"); game.AddCeleb(geoff); geezer.Guess(); geoff.Burn(); game.GetRandomCelebFromHat().Should().BeNull(); }
public void TestAddCeleb() { Game newGame = GameAPI.CreateGame("New Game"); Celeb celeb = GameAPI.AddCelebToGame(new Celeb() { Name = "Name 1", GameId = newGame.Id }, newGame); Celeb celeb2 = GameAPI.AddCelebToGame(new Celeb() { Name = "Name 2", GameId = newGame.Id }, newGame); Game gameRetrieved = GameAPI.GetGameById(newGame.Id); gameRetrieved.Celebs.Should().HaveCount(2); gameRetrieved.Celebs.Should().ContainEquivalentOf(celeb); gameRetrieved.Celebs.Should().ContainEquivalentOf(celeb2); }
// get all celebs from web site private HashSet <Celeb> GetCelebs(MatchCollection coll) { HashSet <Celeb> celebs = new HashSet <Celeb>(); int id = 0; try { Parallel.ForEach <string>(coll.Cast <Match>().Select(p => p.Value).ToArray(), (m) => { string url = m.Replace("=\"", baseUrl); string html = GetHtml(url); Celeb celeb = GetCeleb(id, html); celebs.Add(celeb); id++; }); } catch (Exception ex) { logger.Log(this.ToString() + " : " + ex.ToString()); } return(celebs); }
public void TestGetRandomCeleb() { Game game = new Game(); var geezer = new Celeb("Danny Dyer"); game.AddCeleb(geezer); var geoff = new Celeb("Geoff Capes"); game.AddCeleb(geoff); var john = new Celeb("John Peel"); game.AddCeleb(john); var bill = new Celeb("Bill Bailey"); game.AddCeleb(bill); var jake = new Celeb("Jake Gyllenhaal"); game.AddCeleb(jake); geezer.Guess(); geoff.Guess(); john.Guess(); jake.Guess(); game.GetRandomCelebFromHat().Should().Be(bill); }
public void TestCelebGuessed() { Game newGame = GameAPI.CreateGame("New Game"); Celeb celeb = GameAPI.AddCelebToGame(new Celeb() { Name = "Name 1", GameId = newGame.Id }, newGame); Celeb celeb2 = GameAPI.AddCelebToGame(new Celeb() { Name = "Name 2", GameId = newGame.Id }, newGame); Celeb celeb3 = GameAPI.AddCelebToGame(new Celeb() { Name = "Name 3", GameId = newGame.Id }, newGame); celeb2.Guess(); GameAPI.UpdateCeleb(celeb2); Celeb retrievedCeleb = GameAPI.GetCeleb(celeb2.Id); retrievedCeleb.State.Should().Be(CelebState.GUESSED); }
public int DeleteCeleb(Celeb celeb) { _context.Celebs.Remove(celeb); return(Save()); }