public void GetKeywordsShouldNotThrowExceptionIfDBIsEmpty()
        {
            //Arrange
            var options = new DbContextOptionsBuilder <Project2DBContext>()
                          .UseInMemoryDatabase(databaseName: "EmptyKeywordDB1")
                          .Options;

            bool        result = true;
            KeywordRepo kRepo;

            //Act
            using (var context = new Project2DBContext(options))
            {
                kRepo = new KeywordRepo(context);
                try
                {
                    kRepo.GetKeywords();
                }
                catch
                {
                    result = false;
                }
            }
            //Assert
            Assert.True(result);
        }
        public void AddKeywordShouldAddCorrectKeywordToDB(string kw, bool useAsync)
        {
            //Arrange
            var options = new DbContextOptionsBuilder <Project2DBContext>()
                          .UseInMemoryDatabase(databaseName: "EmptyKeywordAddTesting2DB")
                          .Options;

            Keyword k = new Keyword {
                Word = kw
            };
            KeywordRepo kRepo;
            Keyword     result;

            //Act
            using (var context = new Project2DBContext(options))
            {
                kRepo = new KeywordRepo(context);
                if (useAsync)
                {
                    kRepo.AddKeywordAsync(k).Wait();
                }
                else
                {
                    kRepo.AddKeyword(k);
                }
                result = context.Keyword.Find(k.Word);
            }

            //Assert
            Assert.Equal(k, result);
        }
        public void AddKeywordShouldThrowExceptionIfKeywordIsPreset(string kw, bool useAsync)
        {
            //Arrange
            string dBName;

            if (useAsync)
            {
                dBName = "EmptyKeywordAddTestingAsync1DB";
            }
            else
            {
                dBName = "EmptyKeywordAddTesting1DB";
            }
            var options = new DbContextOptionsBuilder <Project2DBContext>()
                          .UseInMemoryDatabase(databaseName: dBName)
                          .Options;

            Keyword k = new Keyword {
                Word = kw
            };
            Keyword k2 = new Keyword {
                Word = kw
            };
            KeywordRepo kRepo;
            bool        result = false;

            using (var context = new Project2DBContext(options))
            {
                context.Keyword.Add(k2);
                context.SaveChanges();
            }

            //Act
            using (var context = new Project2DBContext(options))
            {
                kRepo = new KeywordRepo(context);
                try
                {
                    if (useAsync)
                    {
                        kRepo.AddKeywordAsync(k).Wait();
                    }
                    else
                    {
                        kRepo.AddKeyword(k);
                    }
                }
                catch (DbUpdateException)
                {
                    result = true;
                }
                catch (AggregateException)
                {
                    result = true;
                }
            }

            //Assert
            Assert.True(result);
        }
        public void DBContainsKeywordShouldReturnFalseIfKeywordNotInDB(string kw, bool useAsync)
        {
            //Arrange
            var options = new DbContextOptionsBuilder <Project2DBContext>()
                          .UseInMemoryDatabase(databaseName: "StaticFilledKeywordDB")
                          .Options;
            bool        result;
            KeywordRepo kRepo;

            //Act
            using (var context = new Project2DBContext(options))
            {
                kRepo = new KeywordRepo(context);
                if (useAsync)
                {
                    result = kRepo.DBContainsKeywordAsync(kw).Result;
                }
                else
                {
                    result = kRepo.DBContainsKeyword(kw);
                }
            }
            //Assert
            Assert.False(result);
        }
        public void DBContainsKeywordShouldReturnFalseIfIfDBIsEmpty(string kw, bool useAsync)
        {
            //Arrange
            var options = new DbContextOptionsBuilder <Project2DBContext>()
                          .UseInMemoryDatabase(databaseName: "EmptyKeywordDB3")
                          .Options;
            bool        result;
            KeywordRepo kRepo;

            //Act
            using (var context = new Project2DBContext(options))
            {
                kRepo = new KeywordRepo(context);
                if (useAsync)
                {
                    result = kRepo.DBContainsKeywordAsync(kw).Result;
                }
                else
                {
                    result = kRepo.DBContainsKeyword(kw);
                }
            }
            //If exception is throw, test will exit before reaching Assert
            //Assert
            Assert.False(result);
        }
        public void GetKeywordsShouldReturnAListWithProperNumberOfKeywords()
        {
            //Arrange
            var options = new DbContextOptionsBuilder <Project2DBContext>()
                          .UseInMemoryDatabase(databaseName: "StaticFilledKeywordDB")
                          .Options;
            KeywordRepo    kRepo;
            List <Keyword> kList;

            //Act
            using (var context = new Project2DBContext(options))
            {
                kRepo = new KeywordRepo(context);
                kList = kRepo.GetKeywords().ToList();
            }
            //Assert
            Assert.Equal(3, kList.Count);
        }