public async Task Create_awaiting_match_if_user_has_none_awaiting_matches_already(int userId) { var awaitingMatches = new List <AwaitingMatch> { new AwaitingMatch { UserId = 1 }, new AwaitingMatch { UserId = 2 }, new AwaitingMatch { UserId = 3 }, new AwaitingMatch { UserId = 4 } }; var mockMatchRepo = new Mock <IMatchRepository>(); var mockUserRepo = new Mock <IUserRepository>(); var mockConfiguration = new Mock <IConfiguration>(); mockMatchRepo.Setup(repo => repo.RetrieveAwaitingMatches()) .ReturnsAsync(awaitingMatches.Where(x => x.UserId == userId).ToList()); mockMatchRepo.Setup(repo => repo.AddAwaitingMatch(It.IsAny <AwaitingMatch>())) .Callback <AwaitingMatch>(aw => { awaitingMatches.Add(aw); }).Returns(Task.CompletedTask); var mockMatchService = new MatchService(mockUserRepo.Object, mockMatchRepo.Object, mockConfiguration.Object); await mockMatchService.AddToAwaitingMatch(userId); var isAwaitingMatchAdded = awaitingMatches.Any(x => x.UserId == userId); Assert.True(isAwaitingMatchAdded); }