Ejemplo n.º 1
0
        public void RemovingAllWords_FromMaster_WillDeleteMasterAsWell(bool oneByOne)
        {
            var master = MasterWordsService.GetAll().First();
            var book   = master.Books.First();

            var before       = MasterWordsService.GetAll().Count();
            var beforeInBook = book.Words.Count();

            if (oneByOne)
            {
                foreach (var w in master.Words.ToArray())
                {
                    WordsService.Remove(w);
                }
            }
            else
            {
                WordsService.Remove(master.Words);
            }

            var secondMaster = MasterWordsService.GetAll().First();

            Assert.AreNotEqual(secondMaster, master);
            Assert.AreEqual(before - 1, MasterWordsService.GetAll().Count(), "Master count missmatch");
            Assert.AreEqual(beforeInBook - 1, book.Words.Count(), "Word in book count missmatch");
        }
Ejemplo n.º 2
0
        public ActionResult Index(int gridHeight = 3, int gridWidth = 3)
        {
            var model = new GridModel(gridHeight, gridWidth)
            {
                WordLengths = new List <int> {
                    3
                }
            };

            if (Request.HttpMethod == "POST")
            {
                model.WordLengths = new List <int> {
                    Convert.ToInt32(Request["wordLength1"])
                };
                for (var i = 0; i < gridHeight; i++)
                {
                    var currentRow = model.Rows[i];
                    for (var n = 0; n < gridWidth; n++)
                    {
                        currentRow[n] = new CellModel(model, i, n)
                        {
                            Value = Request.Form[$"col{i}_{n}"].ToLower()
                        };
                    }
                }
                var service = new WordsService();
                var combos  = service.GetAllCandidateWords(model, 0);
                model.ValidWords.Add(combos.Children.ToList());
            }
            return(View(model));
        }
        public void RemovingLink_BetweenTwoWords_FirstArgWillKeepTheMasterWithAllTranslations()
        {
            // Arrange
            var masterA        = new MasterWord();
            var wordInFirstArg = new Word(masterA, "Hi", new Language("English"));
            var translation    = new Word(masterA, "Hola", new Language("Spanish"));

            new Word(masterA, "some word", new Language("some lang"));

            MasterWordsService.Add(masterA);

            // Act
            WordsService.RemoveTranslation(wordInFirstArg, translation);

            // Assert
            var newMaster      = MasterWordsService.Get(masterA.ID);
            var newWord        = WordsService.Get(wordInFirstArg.ID);
            var newTranslation = WordsService.Get(translation.ID);

            Assert.AreEqual(2, newMaster.Words.Count, "Master should have two words left");
            Assert.AreEqual(newMaster, newWord.MasterWord, "Word in first argument should keep the master word");

            Assert.AreEqual(1, newTranslation.MasterWord.Words.Count, "Translation master should only have 1 translation");
            Assert.AreNotEqual(newTranslation.MasterWord, newWord.MasterWord, "Word in second argument should get new master created");
        }
Ejemplo n.º 4
0
        public void CreateDictionary()
        {
            // Arrange
            var fileReader = Substitute.For <IFileReader>();

            fileReader.ReadFile("fileName.txt").Returns(new Dictionary <string, int>()
            {
                { "блок", 50 },
                { "блоха", 20 },
                { "блокада", 10 },
                { "катерина", 30 },
                { "катер", 20 },
            });
            var wordsService = new WordsService(GlobalTransactionScopeTestSetUp.Context, fileReader);

            // Act
            wordsService.CreateDictionary("fileName.txt").GetAwaiter().GetResult();
            // Assert
            var addedWords = GlobalTransactionScopeTestSetUp.Context.Words.ToList();

            Assert.That(addedWords.Count == 5);
            Assert.That(addedWords.Any(w => w.Count == 50 && w.Value == "блок"));
            Assert.That(addedWords.Any(w => w.Count == 20 && w.Value == "блоха"));
            Assert.That(addedWords.Any(w => w.Count == 10 && w.Value == "блокада"));
            Assert.That(addedWords.Any(w => w.Count == 30 && w.Value == "катерина"));
            Assert.That(addedWords.Any(w => w.Count == 20 && w.Value == "катер"));
        }
Ejemplo n.º 5
0
        public async Task GetAllWordsAsync_ReturnsEmptySetIfNone()
        {
            var service = new WordsService(_context);
            var actual  = await service.GetAllWordsAsync <Adverb>("en");

            Assert.Empty(actual);
        }
Ejemplo n.º 6
0
        public Words_ViewModel(WordsModel model, WordType?wtype, int tt, IUnitOfWork uw)
        {
            _uow = uw;
            Contract.Requires(model != null);
            WordsInfo = model;
            word      = new WordsService(_uow);
            option    = new OptionService(_uow);
            language  = new LanguageServise(_uow);
            listitem  = new ListItems();

            chatmodel = new MSChartVM();
            //chatmodel.BarChart();
            charttest    = chatmodel.BarSeriesCollection;
            TT           = tt;
            AllLanguages = GetAllLanguages();
            allWordTypes = listitem.GetWordType();
            app          = option.GetAll();

            wt = wtype;

            RefreshProducts();

            ConfigureValidationRules();
            Validator.ResultChanged += OnValidationResultChanged;
        }
Ejemplo n.º 7
0
        public async Task GetRandomWordAsync_ReturnsNullIfNone()
        {
            var service = new WordsService(_context);
            var actual  = await service.GetRandomWordAsync <Adverb>("en");

            Assert.Null(actual);
        }
Ejemplo n.º 8
0
        public async Task GetWordByIdAsync_ReturnsNullIfNotFound()
        {
            var service = new WordsService(_context);
            var actual  = await service.GetWordByIdAsync <Adjective>(12);

            Assert.Null(actual);
        }
Ejemplo n.º 9
0
        public async Task UpdateWordsAsync_ReturnsPartialSetWhenSomeExist()
        {
            const int expectedCount = 3;
            var       expected      = (await FeedTestData(_context, expectedCount)).OfType <Adjective>().ToList();

            expected.ForEach(word =>
            {
                word.Value        = "Changed";
                word.IsDeleted    = !word.IsDeleted;
                word.IsVulgar     = !word.IsVulgar;
                word.LanguageCode = "pl";
            });
            var nonExistent = new List <Adjective>
            {
                GenerateWord <Adjective>(false, false),
                GenerateWord <Adjective>(false, false),
                GenerateWord <Adjective>(false, false)
            };

            var service = new WordsService(_context);
            var actual  = await service.UpdateWordsAsync(expected.Concat(nonExistent).ToList());

            Assert.Equal(expectedCount, actual.Count);
            actual.Select(w => w.Id).Should().Equal(expected.Select(w => w.Id));
            actual.Select(w => w.Value).Should().Equal(expected.Select(w => w.Value));
            actual.Select(w => w.IsDeleted).Should().Equal(expected.Select(w => w.IsDeleted));
            actual.Select(w => w.IsVulgar).Should().Equal(expected.Select(w => w.IsVulgar));
            actual.Select(w => w.LanguageCode).Should().Equal(expected.Select(w => w.LanguageCode));
        }
        public void RemovingLink_BetweenTwoWords_WillCreateNewMasterWordForIt(bool cleanCache)
        {
            // Arrange
            var masterA = new MasterWord();
            var wordA   = new Word(masterA, "Hi", new Language("English"));
            var wordB   = new Word(masterA, "Hola", new Language("Spanish"));

            MasterWordsService.Add(masterA);

            if (cleanCache)
            {
                RefreshServicesAndClearCache();
                wordA = WordsService.GetAll().First(w => w.ID == wordA.ID);
                wordB = WordsService.GetAll().First(w => w.ID == wordB.ID);
            }

            // Act
            WordsService.RemoveTranslation(wordA, wordB);

            // Assert
            var newA = WordsService.Get(wordA.ID);
            var newB = WordsService.Get(wordB.ID);

            masterA = MasterWordsService.Get(masterA.ID);

            Assert.AreNotEqual(newA.MasterWord, newB.MasterWord, "Master words should differ. New Ref");
            Assert.AreNotEqual(wordA.MasterWord, wordB.MasterWord, "Master words should differ. Old Ref");

            Assert.AreEqual(1, masterA.Words.Count(), "MasterWord word count should be 1");
        }
Ejemplo n.º 11
0
        public void GettingWords_ContainsALanguageAndListOfTranslation()
        {
            var word = WordsService.GetWordsWithData().First();

            Assert.IsNotNull(word.Language);
            Assert.IsNotNull(word.Translations);
            Assert.AreEqual(2, word.Translations.Count());
        }
Ejemplo n.º 12
0
 public void AddSingleBook_CheckIfDataCountIsCorrect()
 {
     Assert.AreEqual(1, BooksService.GetAllWithData().Count(), "Books");
     Assert.AreEqual(3, LanguagesService.GetAll().Count(), "Langs");
     Assert.AreEqual(9, WordsService.GetWordsWithData().Count(), "Words");
     Assert.AreEqual(3, MasterWordsService.GetAll().Count(), "MasterWords");
     Assert.AreEqual(1, AccountService.GetAll().Count(), "Accounts");
 }
Ejemplo n.º 13
0
        public async Task GetRandomWordAsync_WithVulgarFilter_ReturnsNullIfNone()
        {
            await FeedTestData(_context, 1);

            var service = new WordsService(_context);
            var actual  = await service.GetRandomWordAsync <Adverb>("en", useVulgar : true);

            Assert.Null(actual);
        }
Ejemplo n.º 14
0
        public async Task UpdateWordAsync_ReturnsNullWhenDoesNotExist()
        {
            var expected = GenerateWord <Noun>(false, false);

            var service = new WordsService(_context);
            var actual  = await service.UpdateWordAsync(expected);

            Assert.Null(actual);
        }
Ejemplo n.º 15
0
        public async Task GetRandomWordAsync_WithVulgarFilter_ReturnsNullWhenNoneInLanguage()
        {
            await FeedTestData(_context, 3);

            var service = new WordsService(_context);
            var actual  = await service.GetRandomWordAsync <Adjective>("pl", useVulgar : true);

            Assert.Null(actual);
        }
Ejemplo n.º 16
0
        public MainWindow()
        {
            InitializeComponent();

            _wordsService   = new WordsService();
            _yandexServices = new YandexServices();

            _textBox.PreviewMouseDoubleClick += TextBox_PreviewMouseDoubleClick;
        }
Ejemplo n.º 17
0
        public async Task GetRandomWordAsync_ReturnsWordIfAny()
        {
            await FeedTestData(_context, 3);

            var service = new WordsService(_context);
            var actual  = await service.GetRandomWordAsync <Noun>("en");

            Assert.NotNull(actual);
            Assert.IsType <Noun>(actual);
        }
Ejemplo n.º 18
0
        public void RemovingDefinition_FromWord_WillUpdateDB()
        {
            var word = WordsService.GetWordsWithData().First();

            word.Definition = null;
            WordsService.Update(word);
            var newWord = WordsService.GetWordsWithData().First();

            Assert.AreEqual(null, newWord.Definition, "Definition should be empty");
        }
Ejemplo n.º 19
0
        public async Task CreateWordAsync_AddsNewWord()
        {
            var expected = GenerateWord <Adverb>(false, false);

            var service = new WordsService(_context);
            var actual  = await service.CreateWordAsync(expected);

            Assert.Equal(expected.Id, actual);
            Assert.Equal(1, _context.Set <Adverb>().Count());
        }
        public void CanAdd_Word_ToDatabase()
        {
            var beforeWords = WordsService.GetAll().Count();

            WordsService.Add(new Word()
            {
                MasterWord = new MasterWord(), Text = "Something", Language = LanguagesService.GetAll().First()
            });
            Assert.AreEqual(beforeWords + 1, WordsService.GetWordsWithData().Count());
        }
Ejemplo n.º 21
0
        public async Task GetRandomWordAsync_WithVulgarFilter_ReturnsWordIfAny()
        {
            await FeedTestData(_context, 3);

            var service = new WordsService(_context);
            var actual  = await service.GetRandomWordAsync <Noun>("en", useVulgar : true);

            Assert.NotNull(actual);
            Assert.IsType <Noun>(actual);
            Assert.True(actual.IsVulgar);
        }
Ejemplo n.º 22
0
        public void RemovingWord_WithExplanationsAndDefinitions_UdpatesDB()
        {
            var before = WordsService.GetAll().Count();
            var word   = WordsService.GetWordsWithData().First();

            WordsService.Remove(word);

            var after = WordsService.GetAll().Count();

            Assert.AreEqual(before - 1, after, "Count missmatch");
        }
Ejemplo n.º 23
0
        public async Task DeleteWordAsync_ReturnsIdWhenExists()
        {
            const int count    = 3;
            var       expected = (await FeedTestData(_context, count)).OfType <Adverb>().First();

            var service = new WordsService(_context);
            var actual  = await service.DeleteWordAsync(expected);

            Assert.Equal(expected.Id, actual);
            Assert.Equal(count - 1, _context.Set <Adverb>().Count());
        }
Ejemplo n.º 24
0
        public void RemovingExplanation_FromWord_WillUpdateDB()
        {
            var word   = WordsService.GetWordsWithData().First();
            var before = word.Explanations.Count();

            word.Explanations = null;
            WordsService.Update(word);
            var newWord = WordsService.GetWordsWithData().First();

            Assert.IsTrue(newWord.Explanations == null || newWord.Explanations.Count == 0, "Explanations should be empty");
        }
Ejemplo n.º 25
0
        public async Task GetAllWordsAsync_ReturnsAllFromSet()
        {
            const int expectedCount = 3;
            var       ids           = (await FeedTestData(_context, expectedCount)).OfType <Noun>().Select(w => w.Id).ToList();

            var service = new WordsService(_context);
            var actual  = await service.GetAllWordsAsync <Noun>("en");

            Assert.Equal(expectedCount, actual.Count);
            actual.Select(w => w.Id).Should().Equal(ids);
        }
        //TODO: use nhibernate join
        private async void LoadWordsCollection(NHibernate.Criterion.ICriterion expression = null)
        {
            var allWords = new List <Word>();

            WordsCollection.Clear();
            var collection = await WordsService.GetDataAsync <Word>(expression);

            if (collection != null)
            {
                foreach (var item in collection)
                {
                    if (!allWords.Exists(x => x.Id == item.Id))
                    {
                        allWords.Add(item);
                    }
                }
            }
            foreach (var item in allWords)
            {
                WordsCollection.Add(new WordViewModel {
                    WordToDisplay = item
                });
            }
            var alreadyAdded = allWords.Count;

            //only in case of searching it does matter
            if (expression != null)
            {
                var collection2 = await WordsService.GetDataAsync <Translation>(expression);

                if (collection2 != null)
                {
                    foreach (var item in collection2)
                    {
                        foreach (var w in item.WordsStoredIn)
                        {
                            if (!allWords.Exists(x => x.Id == w.Id))
                            {
                                allWords.Add(w);
                            }
                        }
                    }
                }
            }

            foreach (var item in allWords.Skip(alreadyAdded))
            {
                WordsCollection.Add(new WordViewModel {
                    WordToDisplay = item
                });
            }
            allWords = null;
        }
        public void RemovingLink_BetweenTwoWords_WillRelinkWordsInBooks(
            [Values(true, false)] bool enBookLang,
            [Values(true, false)] bool invertRemoval)
        {
            // Arrange
            var langEn  = new Language("English");
            var langEsp = new Language("Spanish");

            var masterA = new MasterWord();
            var wordA   = new Word(masterA, "Hi", langEn);
            var wordB   = new Word(masterA, "Hola", langEsp);

            new Word(masterA, "some word", new Language("some lang"));

            var book = new Book("name", enBookLang ? langEn : langEsp);

            book.AddWord(masterA);

            MasterWordsService.Add(masterA);
            BooksService.Add(book);


            // Act
            RefreshServicesAndClearCache();
            wordA = WordsService.GetAll().First(w => w.ID == wordA.ID);
            wordB = WordsService.GetAll().First(w => w.ID == wordB.ID);

            if (invertRemoval)
            {
                WordsService.RemoveTranslation(wordA, wordB);
            }
            else
            {
                WordsService.RemoveTranslation(wordB, wordA);
            }

            // Assert
            book = BooksService.Get(book.ID);

            Assert.AreEqual(1, book.WordCount, "Book word count should be 1. Old Ref");
            Assert.AreEqual(1, book.WordCount, "Book word count should be 1. New Ref");

            Assert.IsNotNull(book.Words.First()[book.Language],
                             "After removing translation between two words, book should keep the master word which aligns with book language. New Ref");

            var wordInBook      = enBookLang ? wordA : wordB;
            var wordWithoutBook = enBookLang ? wordB : wordA;

            Assert.AreEqual(book, wordInBook.MasterWord.Books.First(), "word should be in a book");
            Assert.AreEqual(book.Language, wordInBook.Language, "book and word languages should be the same");
            Assert.AreEqual(book.Words.First(), wordInBook.MasterWord, "master word should be the same of word left of correct language");
            Assert.AreEqual(0, wordWithoutBook.MasterWord.Books.Count(), "other word should have no books");
        }
Ejemplo n.º 28
0
        public async Task GetWordByIdAsync_ReturnsWordIfFound()
        {
            var expected = (await FeedTestData(_context, 3)).OfType <Adverb>().First();

            var service = new WordsService(_context);
            var actual  = await service.GetWordByIdAsync <Adverb>(expected.Id);

            Assert.NotNull(actual);
            Assert.IsType <Adverb>(actual);
            Assert.Equal(expected.Id, actual.Id);
            Assert.Equal(expected.Value, actual.Value);
        }
Ejemplo n.º 29
0
        public async Task DeleteWordsAsync_ReturnsIdSetOfDeletedWhenExist()
        {
            const int count        = 5;
            const int deletedCount = 3;
            var       expected     = (await FeedTestData(_context, count)).OfType <Noun>().Skip(count - deletedCount).ToList();

            var service = new WordsService(_context);
            var actual  = await service.DeleteWordsAsync(expected);

            Assert.Equal(deletedCount, actual.Count);
            Assert.Equal(count - deletedCount, _context.Set <Noun>().Count());
            actual.Should().Equal(expected.Select(w => w.Id));
        }
Ejemplo n.º 30
0
        public async Task DeleteWordAsync_ReturnsZeroWhenDoesNotExist()
        {
            const int count       = 3;
            var       nonExistent = (await FeedTestData(_context, count)).OfType <Adjective>().First();

            nonExistent.Id = int.MaxValue;

            var service = new WordsService(_context);
            var actual  = await service.DeleteWordAsync(nonExistent);

            Assert.Equal(0, actual);
            Assert.Equal(count, _context.Set <Adjective>().Count());
        }