Ejemplo n.º 1
0
        public void TestSelectWordsWithoutSynset()
        {
            //arrange
            LocalWordDB sut = new LocalWordDB();

            sut.CreateDatabase();

            List <DbWord> wordlist = new List <DbWord>
            {
                defaultDbWord,
                defaultDbWord2,
                new DbWord {
                    Word = "test3", SynsetId = null, CreationDate = DateTime.Today
                }
            };

            foreach (DbWord word in wordlist)
            {
                sut.TryAddWord(word.Word, word.SynsetId).Should().BeTrue();
            }
            //act-assert


            sut.TryGetWordsWithoutSynset(1000, out IEnumerable <DbWord> outdbWords).Should().Be(1);

            outdbWords.First().Should().Be(wordlist.Last());

            //restore
            sut.DeleteDatabase();
        }
Ejemplo n.º 2
0
        public void TestSelectManyWords()
        {
            //arrange
            LocalWordDB sut = new LocalWordDB();

            sut.CreateDatabase();

            List <DbWord> wordlist = new List <DbWord>
            {
                defaultDbWord,
                defaultDbWord2
            };

            sut.TryAddWord(defaultDbWord.Word, defaultDbWord.SynsetId).Should().BeTrue();
            sut.TryAddWord(defaultDbWord2.Word, defaultDbWord2.SynsetId).Should().BeTrue();
            //act-assert


            sut.TryGetWords(wordlist, out IEnumerable <DbWord> data2);

            DbWord[] wordSelected = data2.ToArray();

            for (int i = 0; i < wordlist.Count; i++)
            {
                wordSelected[i].Should().Be(wordlist[i]);
            }

            //restore
            sut.DeleteDatabase();
        }
Ejemplo n.º 3
0
        public void TestSelectManyManyMoreWords(int argsize)
        {
            //arrange
            LocalWordDB sut = new LocalWordDB();

            sut.CreateDatabase();

            List <DbWord> wordlist = new List <DbWord>();

            for (int i = 0; i < argsize; i++)
            {
                wordlist.Add(new DbWord {
                    Word = Guid.NewGuid().ToString(), SynsetId = Guid.NewGuid().ToString(), CreationDate = DateTime.Today
                });
            }
            wordlist.Add(defaultDbWord);
            wordlist.Add(defaultDbWord2);

            sut.TryAddWord(defaultDbWord.Word, defaultDbWord.SynsetId).Should().BeTrue();
            sut.TryAddWord(defaultDbWord2.Word, defaultDbWord2.SynsetId).Should().BeTrue();


            //act
            sut.TryGetWords(wordlist, out IEnumerable <DbWord> data2).Should().BeTrue();
            //assert
            var wordOut = data2.ToHashSet();

            wordOut.Contains(defaultDbWord).Should().BeTrue();
            wordOut.Contains(defaultDbWord2).Should().BeTrue();
            //restore
            sut.DeleteDatabase();
        }
Ejemplo n.º 4
0
        public void TestWordCount(int count)
        {
            //arrange
            LocalWordDB sut = new LocalWordDB();

            sut.CreateDatabase();
            List <DbWord> wordlist = new List <DbWord>();

            for (int i = 0; i < count; i++)
            {
                wordlist.Add(new DbWord
                {
                    Word         = Guid.NewGuid().ToString(),
                    SynsetId     = Guid.NewGuid().ToString(),
                    CreationDate = DateTime.Today
                });
            }
            //act-assert
            sut.TryAddWords(wordlist).Should().Be(count);

            sut.GetWordCount().Should().Be(wordlist.Count);

            //restore
            sut.DeleteDatabase();
        }
Ejemplo n.º 5
0
        public void TestUpdateWordsRelationStatus()
        {
            //arrange
            LocalWordDB sut = new LocalWordDB();

            sut.CreateDatabase();

            List <DbWord> wordlist = new List <DbWord>
            {
                new DbWord {
                    Word = "test", SynsetId = "b:fzf4687", CreationDate = DateTime.Today, WordId = 1
                },
                new DbWord {
                    Word = "test2", SynsetId = "b:vdqvqdv45", CreationDate = DateTime.Today, WordId = 2
                }
            };

            sut.TryAddWord(defaultDbWord.Word, defaultDbWord.SynsetId).Should().BeTrue();
            sut.TryAddWord(defaultDbWord2.Word, defaultDbWord2.SynsetId).Should().BeTrue();

            //act
            sut.UpdateWordRelationStatus(wordlist, true).Should().Be(2);

            //assert

            sut.TryGetWords(wordlist, out IEnumerable <DbWord> outDbWords).Should().BeTrue();

            outDbWords.Count().Should().Be(wordlist.Count);

            outDbWords.Any(x => x.RelationsRequested == true).Should().BeTrue();


            //restore
            sut.DeleteDatabase();
        }
Ejemplo n.º 6
0
        public void TestMultipleWordInsertion(int count)
        {
            //arrange
            LocalWordDB sut = new LocalWordDB();

            sut.CreateDatabase();
            List <DbWord> wordlist = new List <DbWord>();

            for (int i = 0; i < count; i++)
            {
                wordlist.Add(new DbWord {
                    Word         = Guid.NewGuid().ToString(),
                    SynsetId     = Guid.NewGuid().ToString(),
                    CreationDate = DateTime.Today
                });
            }

            //act-assert
            sut.TryAddWords(wordlist).Should().Be(count);

            int countCheck = 0;

            foreach (DbWord word in wordlist)
            {
                sut.TryGetWord(word.Word, out DbWord wordOut).Should().BeTrue();
                countCheck++;
            }

            countCheck.Should().Be(wordlist.Count);

            //restore
            sut.DeleteDatabase();
        }
Ejemplo n.º 7
0
        public void TestAddWordFromWord()
        {
            //arrange
            LocalWordDB sut = new LocalWordDB();

            sut.CreateDatabase();
            //act-assert
            sut.TryAddWord(defaultDbWord.Word, defaultDbWord.SynsetId).Should().BeTrue();
            //restore
            sut.DeleteDatabase();
        }
Ejemplo n.º 8
0
        public void TestAddLog()
        {
            //arrange
            LocalWordDB sut = new LocalWordDB();

            sut.CreateDatabase();

            sut.TryAddLog("b:576847", "{'hdjkh':'result'}").Should().BeTrue();
            //act-assert
            //restore
            sut.DeleteDatabase();
        }
Ejemplo n.º 9
0
        public void TestDatabaseCreation()
        {
            //arrange
            LocalWordDB sut = new LocalWordDB();

            //act
            sut.CreateDatabase();
            //assert
            File.Exists(LocalWordDB.DbFile).Should().BeTrue();
            //restore
            sut.DeleteDatabase();
            File.Exists(LocalWordDB.DbFile).Should().BeFalse();
        }
Ejemplo n.º 10
0
        public void TestAddRelationFromWordInfo()
        {
            //arrange
            LocalWordDB sut = new LocalWordDB();

            sut.CreateDatabase();

            sut.TryAddWord(defaultDbWord.Word, defaultDbWord.SynsetId).Should().BeTrue();
            sut.TryAddWord(defaultDbWord2.Word, defaultDbWord2.SynsetId).Should().BeTrue();
            //act-assert
            sut.TryAddRelation(defaultDbWord2.Word, defaultDbWord2.SynsetId, "Hyperonym").Should().BeTrue();
            //restore
            sut.DeleteDatabase();
        }
Ejemplo n.º 11
0
        public void TestNotTodayCountLog(int year, int month, int day)
        {
            //arrange
            var         date = new DateTime(year, month, day);
            LocalWordDB sut  = new LocalWordDB();

            sut.CreateDatabase();

            sut.TryAddLog("b:576847", "{'hdjkh':'result'}").Should().BeTrue();
            //act-assert
            sut.GetBabelRequestsCount(date).Should().Be(0);
            //restore
            sut.DeleteDatabase();
        }
Ejemplo n.º 12
0
        public void TestTodayCountLog()
        {
            //arrange
            var         date = DateTime.Now;
            LocalWordDB sut  = new LocalWordDB();

            sut.CreateDatabase();

            sut.TryAddLog("b:576847", "{'hdjkh':'result'}").Should().BeTrue();
            //act-assert
            sut.GetBabelRequestsCount(date).Should().Be(1);
            sut.GetTodayBabelRequestsCount().Should().Be(1);
            //restore
            sut.DeleteDatabase();
        }
Ejemplo n.º 13
0
        public void TestAddRelationToEmpty()
        {
            //arrange
            LocalWordDB sut = new LocalWordDB();

            sut.CreateDatabase();

            sut.TryAddWord(defaultDbWord.Word, defaultDbWord.SynsetId).Should().BeTrue();
            sut.TryAddWord(defaultDbWord2.Word, defaultDbWord2.SynsetId).Should().BeTrue();
            //act-assert
            sut.TryAddRelation(defaultDbWord2.Word, "b:578764644", "Hyperonym").Should().BeTrue();
            sut.SynsetIdToSearch.Count.Should().Be(1);
            //restore
            sut.DeleteDatabase();
        }
Ejemplo n.º 14
0
        public void TestTodayMultipleCountLog(int count)
        {
            //arrange
            LocalWordDB sut = new LocalWordDB();

            sut.CreateDatabase();
            for (int i = 0; i < count; i++)
            {
                sut.TryAddLog(Guid.NewGuid().ToString(), Guid.NewGuid().ToString()).Should().BeTrue();
            }

            //act-assert
            sut.GetTodayBabelRequestsCount().Should().Be(count);

            //restore
            sut.DeleteDatabase();
        }
Ejemplo n.º 15
0
        public void TestSelectWordFromWord()
        {
            //arrange
            LocalWordDB sut = new LocalWordDB();

            sut.CreateDatabase();
            //act-assert
            sut.TryGetWord(defaultDbWord.Word, out DbWord data).Should().BeFalse();

            sut.TryAddWord(defaultDbWord.Word, defaultDbWord.SynsetId).Should().BeTrue();

            sut.TryGetWord(defaultDbWord.Word, out DbWord data2).Should().BeTrue();

            data2.Should().Be(defaultDbWord);


            //restore
            sut.DeleteDatabase();
        }
Ejemplo n.º 16
0
        public void TestUpdateManyWords()
        {
            //arrange
            LocalWordDB sut = new LocalWordDB();

            sut.CreateDatabase();

            List <DbWord> wordlist = new List <DbWord>
            {
                defaultDbWord,
                defaultDbWord2
            };

            sut.TryAddWord(defaultDbWord.Word, defaultDbWord.SynsetId).Should().BeTrue();
            sut.TryAddWord(defaultDbWord2.Word, defaultDbWord2.SynsetId).Should().BeTrue();

            var updatedSynset = "b:04704254";

            List <DbWord> wordlist2 = new List <DbWord>
            {
                new DbWord {
                    Word = "test", SynsetId = updatedSynset, CreationDate = DateTime.Today
                }
            };

            //act
            sut.TryUpdateDbWords(wordlist2).Should().Be(1);

            //assert

            sut.TryGetWords(wordlist, out IEnumerable <DbWord> outDbWords).Should().BeTrue();

            outDbWords.Count().Should().Be(wordlist.Count);

            outDbWords.ToList().Where(x => x.Word == "test").First().SynsetId.Should().Be(updatedSynset);


            //restore
            sut.DeleteDatabase();
        }
Ejemplo n.º 17
0
        public void TestNoRelationsOfWord()
        {
            //arrange
            LocalWordDB sut = new LocalWordDB();

            sut.CreateDatabase();

            sut.TryAddWord(defaultDbWord.Word, defaultDbWord.SynsetId).Should().BeTrue();

            //act-assert
            var wordreturned = sut.TryGetRelationsSum(defaultDbWord);

            wordreturned.Word.Should().Be(defaultDbWord.Word);
            wordreturned.HyperonymCount.Should().Be(0);
            wordreturned.HyponymCount.Should().Be(0);
            wordreturned.OtherCount.Should().Be(0);

            //no hyponym !!!

            //restore
            sut.DeleteDatabase();
        }
Ejemplo n.º 18
0
        public void TestMultipleSimilarWordInsertion()
        {
            //arrange
            LocalWordDB sut = new LocalWordDB();

            sut.CreateDatabase();
            List <DbWord> wordlist  = new List <DbWord>();
            List <DbWord> wordlist2 = new List <DbWord>();

            wordlist.Add(defaultDbWord);
            wordlist.Add(defaultDbWord2);


            //act-assert
            sut.TryAddWords(wordlist).Should().Be(wordlist.Count);


            wordlist2.Add(defaultDbWord);
            sut.TryAddWords(wordlist2).Should().Be(0, "the wordlist 2 should'nt be inserted");

            //restore
            sut.DeleteDatabase();
        }
Ejemplo n.º 19
0
        public void TestWordCompletedCount(int count)
        {
            //arrange
            LocalWordDB sut = new LocalWordDB();

            sut.CreateDatabase();
            List <DbWord> wordlist = new List <DbWord>();

            int    nullSynsetCount = 0;
            string synset          = null;

            for (int i = 0; i < count; i++)
            {
                if (i % 2 == 0)//only even
                {
                    synset = Guid.NewGuid().ToString();
                    nullSynsetCount++;
                }

                wordlist.Add(new DbWord
                {
                    Word         = Guid.NewGuid().ToString(),
                    SynsetId     = synset,
                    CreationDate = DateTime.Today
                });

                synset = null;
            }

            sut.TryAddWords(wordlist, true).Should().Be(count);

            //act-assert
            sut.GetWordsNotCompletedCount(count).Should().Be(nullSynsetCount);

            //restore
            sut.DeleteDatabase();
        }