public void GetNextChallengeBoardCategory() { var repository = new TestRepository(); // create a game with some challenges var board = new Board(); repository.Add(board); var game = new Game() { BoardId = board.Id }; repository.Add(game); var category = new ChallengeCategory(); repository.Add(category); var challenge1 = new Challenge() { ChallengeCategoryId = category.Id }; var challenge2 = new Challenge() { ChallengeCategoryId = category.Id }; var challenge3 = new Challenge() { ChallengeCategoryId = category.Id }; var challenges = new Challenge[] { challenge1, challenge2, challenge3 }; repository.AddAll(challenges); repository.Add(new BoardChallengeCategory() { BoardId = board.Id, ChallengeCategoryId = category.Id }); // keep getting the next challenge until all challenges should have been used var usedChallenges = new List<Challenge>(); foreach (Challenge challenge in challenges) { usedChallenges.Add(game.GetNextChallenge(0)); } // verify that all challenges were used CollectionAssert.AreEqual(challenges.Select(x => x.Id).OrderBy(x => x), usedChallenges.Select(x => x.Id).OrderBy(x => x)); // verify that more challenges can be retrieved Assert.IsNotNull(game.GetNextChallenge(0)); }
public async Task AddChallengeCategory(ChallengeCategory category) { var date = DateTime.Now; category.CreationDate = date; _context.ChallengeCategories.Add(category); await _context.SaveChangesAsync(); }
public async Task <List <Challenge> > GetChallengesAsync(ChallengeCategory category) { if (category != ChallengeCategory.Unknown) { return(_context.Challenges.Where(c => c.Category == category).ToList()); } else { return(_context.Challenges.ToList()); } }
public async Task <ActionResult> GetChallenges([FromQuery] ChallengeCategory category = ChallengeCategory.Unknown) { try { var challenges = await _manager.GetChallengesAsync(category); return(new OkObjectResult(challenges)); } catch (KeyNotFoundException) { return(new NotFoundResult()); } catch (Exception e) { return(new ObjectResult($"Unexpected exception during execution: {e.Message}") { StatusCode = 500 }); } }
public List<ChallengeCategory> GetChallengeCategories(int instance_Id) { using (var context = new greenMoneyEntities()) { var categories = context.ChallengeCategories .OrderBy(c => c.Name); List<ChallengeCategory> list = new List<ChallengeCategory>(); foreach (var category in categories) { ChallengeCategory model = new ChallengeCategory(); Utils.CopyProperties(category, model); //if ((instance_Id != 5) || (instance_Id == 5 && category.Id != 4)) //for all instances Invite neighbour is not shown if (category.Id != 4) { list.Add(model); } } return list; } }
public List<ChallengeCategory> GetChallengeCategories() { using (var context = new greenMoneyEntities()) { var categories = context.ChallengeCategories .OrderBy(c => c.Name); List<ChallengeCategory> list = new List<ChallengeCategory>(); foreach (var category in categories) { ChallengeCategory model = new ChallengeCategory(); Utils.CopyProperties(category, model); list.Add(model); } return list; } }
public void GetNextChallengeMultipleBoardCategories() { var repository = new TestRepository(); // create a game with some challenges var board = new Board(); repository.Add(board); var game = new Game() { BoardId = board.Id }; repository.Add(game); var category1 = new ChallengeCategory(); var category2 = new ChallengeCategory(); repository.Add(category1); repository.Add(category2); var challenge1 = new Challenge() { ChallengeCategoryId = category1.Id }; var challenge2 = new Challenge() { ChallengeCategoryId = category1.Id }; var challenge3 = new Challenge() { ChallengeCategoryId = category2.Id }; var challenge4 = new Challenge() { ChallengeCategoryId = category2.Id }; var challenge5 = new Challenge() { ChallengeCategoryId = category2.Id }; var challenges = new Challenge[] { challenge1, challenge2, challenge3, challenge4, challenge5 }; repository.AddAll(challenges); repository.Add(new BoardChallengeCategory() { BoardId = board.Id, ChallengeCategoryId = category1.Id }); repository.Add(new BoardChallengeCategory() { BoardId = board.Id, ChallengeCategoryId = category2.Id }); // get some challenges (which ones will be used is indeterminate) for (int i = 0; i < 10; i++) { game.GetNextChallenge(0); } }
public ChallengeCategory GetChallengeCategoryByName(string category) { using (var context = new greenMoneyEntities()) { var selectedCategory = context.ChallengeCategories .FirstOrDefault(x => !string.IsNullOrEmpty(x.ShortName) && x.ShortName.ToLower().Equals(category.ToLower())); if (category != null) { var model = new ChallengeCategory(); Utils.CopyProperties(selectedCategory, model); return model; } return null; } }
private Board CreateBoardData(TestRepository repository) { var image = new Image() { Filename = "test.jpg" }; repository.Add(image); var board = new Board() { ImageId = image.Id, Active = true, Description = "test1", Name = "test3", OwnerId = 4, TurnsToEnd = 50, NameCardsToEnd = 10, SafeHavenCardsToEnd = 5 }; repository.Add(board); var space1 = new Space() { BoardId = board.Id, Order = 10 }; var space2 = new Space() { BoardId = board.Id, Order = 20 }; var space3 = new Space() { BoardId = board.Id, Order = 30 }; repository.AddAll(new Space[] { space1, space2, space3 }); var category1 = new ChallengeCategory() { Name = "test1", OwnerId = 2 }; var category2 = new ChallengeCategory() { Name = "test3", OwnerId = 4 }; var category3 = new ChallengeCategory() { Name = "test4", OwnerId = 4 }; var categories = new ChallengeCategory[] { category1, category2, category3 }; repository.AddAll(categories); repository.Add(new SpaceChallengeCategory() { SpaceId = space1.Id, ChallengeCategoryId = category1.Id }); repository.Add(new SpaceChallengeCategory() { SpaceId = space2.Id, ChallengeCategoryId = category3.Id }); var challenge1 = new Challenge() { Question = "test1", ChallengeCategoryId = category1.Id, OwnerId = 3 }; var challenge2 = new Challenge() { Question = "test2", ChallengeCategoryId = category2.Id, OwnerId = 4 }; repository.AddAll(new Challenge[] { challenge1, challenge2 }); repository.Add(new BoardChallengeCategory() { BoardId = board.Id, ChallengeCategoryId = category1.Id }); repository.Add(new BoardChallengeCategory() { BoardId = board.Id, ChallengeCategoryId = category2.Id }); return board; }
public async Task <List <UserChallenge> > GetUserChallengesAsync(string email, ChallengeCategory category) { var result = await _context.UserChallenges .Include(uc => uc.Challenge) .Where(uc => uc.UserEmail == email && uc.Challenge.Category == category) .ToListAsync(); return(result); }