public async Task CheckCreateValidGameInvite() { using var contextFactory = new TestTriviaGameContextFactory(); using TriviaRankContext context = contextFactory.CreateContext(); var insertedPlayer1 = new Player { Username = "******", Password = "******", Birthday = DateTime.Now, Points = 100, FirstName = "Bart", LastName = "Simpson" }; var insertedPlayer2 = new Player { Username = "******", Password = "******", Birthday = DateTime.Now, Points = 200, FirstName = "Milhouse", LastName = "Vanhouten" }; await context.Players.AddAsync(insertedPlayer1); await context.Players.AddAsync(insertedPlayer2); context.SaveChanges(); var game1 = new Game { GameName = "new game 1", OwnerId = insertedPlayer1.Id, StartDate = DateTimeOffset.Now, EndDate = DateTimeOffset.Now, GameMode = true, TotalQuestions = 10, IsPublic = true }; await context.Games.AddAsync(game1); context.SaveChanges(); var repo = new OutboxRepository(context); await repo.createGameInvite(game1.Id, insertedPlayer2.Id); var invitedGame = (await repo.getGameInvites(insertedPlayer2.Id)).FirstOrDefault(); Assert.Equal(game1.Id, invitedGame.Id); }
public async Task DeleteFriendInvite() { using var contextFactory = new TestTriviaGameContextFactory(); using TriviaRankContext context = contextFactory.CreateContext(); var insertedPlayer1 = new Player { Username = "******", Password = "******", Birthday = DateTime.Now, Points = 100, FirstName = "Bart", LastName = "Simpson" }; var insertedPlayer2 = new Player { Username = "******", Password = "******", Birthday = DateTime.Now, Points = 200, FirstName = "Milhouse", LastName = "Vanhouten" }; await context.Players.AddAsync(insertedPlayer1); await context.Players.AddAsync(insertedPlayer2); context.SaveChanges(); var repo = new OutboxRepository(context); await repo.createFriendInvite(insertedPlayer1.Username, insertedPlayer2.Username); await repo.deleteFriendInvite(insertedPlayer1.Username, insertedPlayer2.Username); Assert.Empty((await repo.getFriendInvites(insertedPlayer2.Id)).Where(p => p.Id == insertedPlayer1.Id)); }
public async Task CheckValidExisitingPlayer() { using var contextFactory = new TestTriviaGameContextFactory(); using TriviaRankContext context = contextFactory.CreateContext(); var insertedPlayer = new Player { Username = "******", Password = "******", Birthday = DateTime.Now, Points = 100, FirstName = "Test", LastName = "Player" }; await context.Players.AddAsync(insertedPlayer); context.SaveChanges(); var repo = new PlayerRepository(context); PlayerModel player = await repo.getPlayerById(insertedPlayer.Id); Assert.Equal(insertedPlayer.Id, player.Id); Assert.Equal(insertedPlayer.Username, player.Username); Assert.Equal(insertedPlayer.Birthday, player.Birthday); Assert.Equal(insertedPlayer.Points, player.Points); Assert.Equal(insertedPlayer.FirstName, player.FirstName); Assert.Equal(insertedPlayer.LastName, player.LastName); }
public async Task CheckValidFriendsAdded() { using var contextFactory = new TestTriviaGameContextFactory(); using TriviaRankContext context = contextFactory.CreateContext(); var insertedPlayer1 = new Player { Username = "******", Password = "******", Birthday = DateTime.Now, Points = 100, FirstName = "Bob", LastName = "Smith" }; var insertedFriend2 = new Player { Username = "******", Password = "******", Birthday = DateTime.Now, Points = 200, FirstName = "Jim", LastName = "Jones" }; var insertedFriend3 = new Player { Username = "******", Password = "******", Birthday = DateTime.Now, Points = 300, FirstName = "Bill", LastName = "Johnson" }; var numPlayersBefore = context.Players.Count(); await context.Players.AddAsync(insertedPlayer1); await context.Players.AddAsync(insertedFriend2); await context.Players.AddAsync(insertedFriend3); context.SaveChanges(); var repo = new PlayerRepository(context); await repo.createFriend(insertedPlayer1.Id, insertedFriend2.Id); await repo.createFriend(insertedFriend2.Id, insertedFriend3.Id); Assert.Equal(2, (await repo.getFriendsOfPlayer(insertedFriend2.Id)).Count()); }
public async Task CreateGame_Success() { //arrange using var contextfactory = new TestTriviaGameContextFactory(); using TriviaRankContext context = contextfactory.CreateContext(); var insertOwner = new Player { Username = "******", Password = "******", Birthday = DateTime.Now, Points = 100, FirstName = "Test", LastName = "Player" }; await context.Players.AddAsync(insertOwner); context.SaveChanges(); var newGame = new GameModel { OwnerId = insertOwner.Id, GameName = "some game", TotalQuestions = 10, IsPublic = true, StartDate = DateTimeOffset.Now, EndDate = DateTimeOffset.Now.AddMinutes(10), GameMode = true }; //act var repo = new GameRepository(context); var insertedGame = await repo.CreateGame(newGame); //assert var dbGame = await context.Games.OrderBy(x => x.Id).LastAsync(); Assert.Equal(insertedGame.Id, dbGame.Id); Assert.Equal(insertedGame.GameName, dbGame.GameName); Assert.Equal(insertedGame.OwnerId, dbGame.OwnerId); Assert.Equal(insertedGame.StartDate, dbGame.StartDate); Assert.Equal(insertedGame.EndDate, dbGame.EndDate); Assert.Equal(insertedGame.GameMode, dbGame.GameMode); Assert.Equal(insertedGame.TotalQuestions, dbGame.TotalQuestions); Assert.Equal(insertedGame.IsPublic, dbGame.IsPublic); }
public async Task CheckValidLastNMessages() { using var contextFactory = new TestTriviaGameContextFactory(); using TriviaRankContext context = contextFactory.CreateContext(); var messages = new String[] { "Hello!", "Hello Again!", "Hello Again2!" }; var insertedPlayer1 = new Player { Username = "******", Password = "******", Birthday = DateTime.Now, Points = 100, FirstName = "Larry", LastName = "Larman" }; var insertedPlayer2 = new Player { Username = "******", Password = "******", Birthday = DateTime.Now, Points = 100, FirstName = "Jimbo", LastName = "Jones" }; await context.Players.AddAsync(insertedPlayer1); await context.Players.AddAsync(insertedPlayer2); context.SaveChanges(); var repo = new MessageRepository(context); await repo.createMessage(insertedPlayer1.Id, insertedPlayer2.Id, messages[0]); await repo.createMessage(insertedPlayer1.Id, insertedPlayer2.Id, messages[1]); await repo.createMessage(insertedPlayer1.Id, insertedPlayer2.Id, messages[2]); var repoMessages = (await repo.getLastNMessages(insertedPlayer1.Id, insertedPlayer2.Id, 3)).ToArray(); foreach (var index in Enumerable.Range(0, 3)) { Assert.Equal(messages[index], repoMessages[index].Body); } }
public async Task <QuestionsDTO> AddQuestions(QuestionsDTO questions) { foreach (var question in questions.Results) { Question dbQuestion = new Question() { Category = question.Category, Difficulty = question.Difficulty, Question1 = question.Question, CorrectAnswer = question.CorrectAnswer }; if (question.Type.Equals("boolean")) { dbQuestion.Type = false; } else { dbQuestion.Type = true; } if (question.IncorrectAnswers.Count > 1) { dbQuestion.IncorrectAnswer1 = question.IncorrectAnswers[0]; dbQuestion.IncorrectAnswer2 = question.IncorrectAnswers[1]; dbQuestion.IncorrectAnswer3 = question.IncorrectAnswers[2]; } else { dbQuestion.IncorrectAnswer1 = question.IncorrectAnswers[0]; } await _context.AddAsync(dbQuestion); } _context.SaveChanges(); foreach (var question in questions.Results) { question.Id = _context.Questions.Where(x => x.Question1.Equals(question.Question)).Select(x => x.Id).First(); } return(questions); }
public async Task CheckValidAddedMessage() { using var contextFactory = new TestTriviaGameContextFactory(); using TriviaRankContext context = contextFactory.CreateContext(); var testBody = "Hello Test2!"; var insertedPlayer1 = new Player { Username = "******", Password = "******", Birthday = DateTime.Now, Points = 100, FirstName = "Larry", LastName = "Larman" }; var insertedPlayer2 = new Player { Username = "******", Password = "******", Birthday = DateTime.Now, Points = 100, FirstName = "Jimbo", LastName = "Jones" }; await context.Players.AddAsync(insertedPlayer1); await context.Players.AddAsync(insertedPlayer2); context.SaveChanges(); var repo = new MessageRepository(context); await repo.createMessage(insertedPlayer1.Id, insertedPlayer2.Id, testBody); var body = (await repo.getLastNMessages(insertedPlayer1.Id, insertedPlayer2.Id, 1)).FirstOrDefault().Body; Assert.Equal(testBody, body); }
public async Task CheckValidNumIndexedPlayers() { using var contextFactory = new TestTriviaGameContextFactory(); using TriviaRankContext context = contextFactory.CreateContext(); var insertedPlayer1 = new Player { Username = "******", Password = "******", Birthday = DateTime.Now, Points = 100, FirstName = "Bob", LastName = "Smith" }; var insertedPlayer2 = new Player { Username = "******", Password = "******", Birthday = DateTime.Now, Points = 100, FirstName = "Bob", LastName = "Smith" }; var insertedPlayer3 = new Player { Username = "******", Password = "******", Birthday = DateTime.Now, Points = 100, FirstName = "Bob", LastName = "Smith" }; var insertedPlayer4 = new Player { Username = "******", Password = "******", Birthday = DateTime.Now, Points = 100, FirstName = "Bob", LastName = "Smith" }; var insertedPlayer5 = new Player { Username = "******", Password = "******", Birthday = DateTime.Now, Points = 100, FirstName = "Bob", LastName = "Smith" }; await context.Players.AddAsync(insertedPlayer1); await context.Players.AddAsync(insertedPlayer2); await context.Players.AddAsync(insertedPlayer3); await context.Players.AddAsync(insertedPlayer4); await context.Players.AddAsync(insertedPlayer5); context.SaveChanges(); var repo = new PlayerRepository(context); Assert.Equal(2, (await repo.getNPlayers(2, 0)).Count()); Assert.Equal(2, (await repo.getNPlayers(2, 1)).Count()); Assert.Single((await repo.getNPlayers(1, 2))); Assert.Single((await repo.getNPlayers(2, 2))); }
public async Task CheckValidPlayerGames() { using var contextFactory = new TestTriviaGameContextFactory(); using TriviaRankContext context = contextFactory.CreateContext(); var insertedPlayer1 = new Player { Username = "******", Password = "******", Birthday = DateTime.Now, Points = 100, FirstName = "Bob", LastName = "Smith" }; var insertedPlayer2 = new Player { Username = "******", Password = "******", Birthday = DateTime.Now, Points = 100, FirstName = "Bob", LastName = "Smith" }; await context.Players.AddAsync(insertedPlayer1); await context.Players.AddAsync(insertedPlayer2); context.SaveChanges(); var insertedGame1 = new Game { GameName = "randomGame", OwnerId = insertedPlayer1.Id, StartDate = DateTimeOffset.Now, EndDate = DateTimeOffset.Now, GameMode = true, TotalQuestions = 10, IsPublic = true }; await context.Games.AddAsync(insertedGame1); context.SaveChanges(); var insertedGamePlayer1 = new GamePlayer { GameId = insertedGame1.Id, PlayerId = insertedPlayer2.Id, TotalCorrect = 8 }; await context.GamePlayers.AddAsync(insertedGamePlayer1); context.SaveChanges(); var repo = new PlayerRepository(context); GameModel createdGame = (await repo.getPlayerGames(insertedPlayer2.Id, null)).FirstOrDefault(); Assert.Equal(insertedGame1.Id, createdGame.Id); Assert.Equal(insertedGame1.GameName, createdGame.GameName); Assert.Equal(insertedGame1.OwnerId, createdGame.OwnerId); Assert.Equal(insertedGame1.StartDate, createdGame.StartDate); Assert.Equal(insertedGame1.EndDate, createdGame.EndDate); Assert.Equal(insertedGame1.GameMode, createdGame.GameMode); Assert.Equal(insertedGame1.TotalQuestions, createdGame.TotalQuestions); Assert.Equal(insertedGame1.IsPublic, createdGame.IsPublic); }
public async Task SearchAllGames_GameIsValid_Success() { //arrange using var contextfactory = new TestTriviaGameContextFactory(); using TriviaRankContext context = contextfactory.CreateContext(); var insertOwner = new Player { Username = "******", Password = "******", Birthday = DateTime.Now, Points = 100, FirstName = "Test", LastName = "Player" }; await context.AddAsync(insertOwner); context.SaveChanges(); var insertedGames = new List <Game>(); for (var i = 1; i < 5; i++) { var game = new Game { GameName = "CoolGameDude" + i, GameMode = true, OwnerId = 1, StartDate = DateTimeOffset.Now, EndDate = DateTimeOffset.Now.AddMinutes(20.0), TotalQuestions = i + 10, IsPublic = true }; await context.AddAsync(game); } for (var i = 1; i < 5; i++) { var game = new Game { GameName = "CoolGameDude" + i, GameMode = true, OwnerId = 1, StartDate = DateTimeOffset.Now, EndDate = DateTimeOffset.Now, TotalQuestions = i + 10, IsPublic = true }; await context.AddAsync(game); } context.SaveChanges(); var repo = new GameRepository(context); var dbGames = new List <GameModel>(); //act dbGames = await repo.SearchAllGames(); //assert Assert.NotEmpty(dbGames); }