public void Get_Random_Question_By_Level() { BitcoinShowDBContext context = DbContextFactory.GetContext(); #region mock data int[] easyIds = new int[5]; for (int i = 0; i < 4; i++) { Question easyQuestion = new Question(); easyQuestion.Answer = new Option { Text = "Option 1 easyQuestion ${easyQuestion.Id}", QuestionId = easyQuestion.Id }; easyQuestion.Title = "Question 1"; easyQuestion.Level = LevelEnum.Easy; var options = RandomOptions(4).ToList(); options.ForEach(o => { context.Options.Add(o); }); context.SaveChanges(); easyQuestion.Answer = options[0]; context.Questions.Add(easyQuestion); easyQuestion.Options = options; options.ForEach(o => { o.Question = easyQuestion; context.Options.Update(o); }); context.SaveChanges(); easyIds[i] = easyQuestion.Id; } #endregion mock data QuestionRepository repository = new QuestionRepository(context); Question question = repository.GetByLevel(LevelEnum.Easy, easyIds); Assert.Null(question); question = repository.GetByLevel(LevelEnum.Easy, new int[] { easyIds[0], easyIds[4] }); Assert.NotNull(question); var filter = easyIds .Select((value, index) => new { value, index }) .Where(item => item.index == 0 || item.index == 4) .Select(item => item.value); Assert.True(easyIds.Contains(question.Id)); Assert.False(filter.Contains(question.Id)); }