public async Task SearchOpponentAsync() { var userData = new List <DbModels.User> { new DbModels.User { Email = "[email protected]", Name = "IhaveName1", Password = "******", UserId = 1 }, new DbModels.User { Email = "[email protected]", Name = "IhaveName2", Password = "******", UserId = 2 } }.AsQueryable(); var mockUserSet = new Mock <DbSet <DbModels.User> >(); var mockMatchSet = new Mock <DbSet <DbModels.Match> >(); mockUserSet.SetupData(userData); Mock <IBoardGameDbContext> mockContext = new Mock <IBoardGameDbContext>(); mockContext.Setup(s => s.Matches).Returns(mockMatchSet.Object); mockContext.Setup(s => s.Users).Returns(mockUserSet.Object); BoardGamesOnline.Services.GameOnline.GameOnlineService mockService = new BoardGamesOnline.Services.GameOnline.GameOnlineService(new Mocks.BgDatabaseUowBuliderMock(mockContext.Object)); Task <Match> opponentTask1 = mockService.SearchOpponentAsync(new SearchOpponent { UserId = 1, GameType = GameTypes.Chess }); Task <Match> opponentTask2 = mockService.SearchOpponentAsync(new SearchOpponent { UserId = 2, GameType = GameTypes.Chess }); mockService.ConnectPlayersToMatchAsync(); Match opponent1 = await opponentTask1; Match opponent2 = await opponentTask2; Assert.NotNull(opponent1); Assert.NotNull(opponent2); //Assert.AreEqual(opponent1.Match.MatchId, 1); //Assert.AreEqual(opponent2.Match.MatchId, 1); Assert.AreEqual(opponent1.MatchUsers.Any(a => a.User.UserId == 1), true); Assert.AreEqual(opponent1.MatchUsers.Any(a => a.User.UserId == 2), true); Assert.AreEqual(opponent2.MatchUsers.Any(a => a.User.UserId == 1), true); Assert.AreEqual(opponent2.MatchUsers.Any(a => a.User.UserId == 2), true); }
public async Task CancelSearchOpponentAsync() { var mockContext = new Mock <IBoardGameDbContext>(); var mockService = new BoardGamesOnline.Services.GameOnline.GameOnlineService(new Mocks.BgDatabaseUowBuliderMock(mockContext.Object)); var searchUser = new SearchOpponent { UserId = 1, GameType = GameTypes.Chess }; //Act Task <Match> opponentTask1 = mockService.SearchOpponentAsync(searchUser); Thread.Sleep(3000); mockService.CancelSearchOpponentAsync(searchUser.UserId); Match opponent1 = await opponentTask1; Assert.IsNull(opponent1); }