Beispiel #1
0
        public void GetByPredicateQuestions_AddThreeNewQuestionsThenRetrieveOneQuestion_ReturnCorrectQuestion()
        {
            //ARRANGE
            var options    = new DbContextOptionsBuilder().UseInMemoryDatabase(MethodBase.GetCurrentMethod().Name).Options;
            var context    = new ApplicationContext(options);
            var repository = new QuestionRepository(context);
            var question1  = new Question
            {
                Message   = "Test question 1",
                PostDate  = DateTime.Now,
                State     = QuestionState.Waiting,
                IsDeleted = false,
                Requester = new ApplicationUser {
                    Id = "aaaaabbbbbcccccdddd", Email = "*****@*****.**"
                }
            };
            var question2 = new Question
            {
                Message   = "Test question 2",
                PostDate  = DateTime.Now,
                State     = QuestionState.Waiting,
                IsDeleted = false,
                Requester = new ApplicationUser {
                    Id = "bbbbbcccccddddeeeeee", Email = "*****@*****.**"
                }
            };
            var question3 = new Question
            {
                Message   = "Test question 3",
                PostDate  = DateTime.Now,
                State     = QuestionState.Waiting,
                IsDeleted = false,
                Requester = new ApplicationUser {
                    Id = "cccccbbbbbcccccdddd", Email = "*****@*****.**"
                }
            };
            var addedQuestion1 = repository.Insert(question1);
            var addedQuestion2 = repository.Insert(question2);
            var addedQuestion3 = repository.Insert(question3);

            context.SaveChanges();
            //ACT
            var result = repository.GetByPredicate(q => q.Message.Equals("Test question 2"));

            //ASSERT
            Assert.IsNotNull(result);
            Assert.AreEqual(1, result.Count());
            Assert.AreEqual("Test question 2", result.First().Message);
        }