Exemple #1
0
        public async void AddQuestionAsyncShouldThrowExcpetion()
        {
            // arrange
            var options = new DbContextOptionsBuilder <PH_DbContext>()
                          .UseInMemoryDatabase("AddQuestionAsyncShouldThrowExcpetion")
                          .Options;

            using var actContext = new PH_DbContext(options);
            var repo = new ForumRepo(actContext);

            var newQuestion = new Question();

            try
            {
                await repo.AddQuestionAsync(newQuestion);
            }
            catch (InvalidOperationException ex)
            {
                Assert.Equal("There is no user logged in.", ex.Message);
            }
        }
Exemple #2
0
        public async void AddQuestionAsyncShouldAdd()
        {
            // arrange
            var options = new DbContextOptionsBuilder <PH_DbContext>()
                          .UseInMemoryDatabase("AddQuestionAsyncShouldAdd")
                          .Options;

            using var actContext = new PH_DbContext(options);
            var repo = new ForumRepo(actContext);

            Users newUsers = new Users()
            {
                FirstName = "Rando",
                LastName  = "Random",
                Email     = "*****@*****.**",
                Username  = "******",
                Password  = "******",
                Phone     = "1231231234",
                //PointAvailable = 100
            };

            actContext.Add(newUsers);
            actContext.SaveChanges();

            var newQuestion = new Question()
            {
                AuthorName = "randorandom"
            };

            // act
            await repo.AddQuestionAsync(newQuestion);

            //actContext.SaveChanges();

            // assert
            using var assertContext = new PH_DbContext(options);
            var ques = assertContext.Questions.Select(q => newQuestion);

            Assert.NotNull(ques);
        }