public void TestReversedEventOrder()
        {
            WordList wordList = new WordList();
            Word word = wordList.Add("test", "test", "");
            wordList.ResetHistory();

            DateTime utcNow = DateTime.UtcNow;
            word.Events.Add(new WordEvent(utcNow.AddDays(-1), WordEventType.Remembered));
            word.Events.Add(new WordEvent(utcNow.AddDays(-2), WordEventType.Forgotten));
            word.Events.Add(new WordEvent(utcNow.AddDays(-2), WordEventType.Added));

            var wordListXml = WordListXmlConverter.ConvertToXml(wordList);
            WordList wordList2 = WordListXmlConverter.ConvertToObject(wordListXml);

            List<WordInfo> words2 = wordList2.GetAllWords().ToList();
            Assert.That(words2.Count, Is.EqualTo(1));

            Word word2 = words2[0].Word;

            Assert.That(word2.Events.Count, Is.EqualTo(3));
            Assert.That(word2.Events[0].EventType, Is.EqualTo(WordEventType.Added));
            Assert.That(word2.Events[1].EventType, Is.EqualTo(WordEventType.Forgotten));
            Assert.That(word2.Events[2].EventType, Is.EqualTo(WordEventType.Remembered));
            Assert.That(word2.Events[0].EventDate, Is.EqualTo(utcNow.AddDays(-2)));
            Assert.That(word2.Events[1].EventDate, Is.EqualTo(utcNow.AddDays(-2)));
            Assert.That(word2.Events[2].EventDate, Is.EqualTo(utcNow.AddDays(-1)));
        }
Ejemplo n.º 2
0
        public void Test()
        {
            WordList wordList = new WordList();

            wordList.Add("apple", "a round fruit", null);
            wordList.Add("oRRange", "a round citrus fruit", "fruit");

            Assert.That(wordList.GetAllWords().Select(w => w.Word.Name), Is.EquivalentTo(new[] { "apple", "oRRange" }));
            Assert.That(wordList.GetAllTags(), Is.EquivalentTo(new[] { "fruit" }));
            Assert.That(wordList.GetWordsWithTag("fruit").Select(w => w.Word.Name), Is.EquivalentTo(new[] { "oRRange" }));

            wordList.Update("apple", "apple", "a round fruit", "fruit");
            wordList.Update("oRRange", "orange", "a round citrus fruit", "fruit");

            Assert.That(wordList.GetAllWords().Select(w => w.Word.Name), Is.EquivalentTo(new[] {"apple", "orange"}));
            Assert.That(wordList.GetAllTags(), Is.EquivalentTo(new[] {"fruit"}));
            Assert.That(wordList.GetWordsWithTag("fruit").Select(w => w.Word.Name), Is.EquivalentTo(new[] { "apple", "orange" }));

            wordList.MarkTranslation("a round fruit", WordEventType.Remembered);
            WordEvent translationRemenberedEvent = wordList.GetAllTranslations().Single(t => t.Translation == "a round fruit").Events.First().WordEvent;
            Assert.That(translationRemenberedEvent.EventType, Is.EqualTo(WordEventType.Remembered));
            Assert.That(translationRemenberedEvent.Translation, Is.EqualTo("a round fruit"));

            MemoryStream mem = new MemoryStream();
            WordListFileParser fileParser = new WordListFileParser();
            fileParser.GenerateZip(wordList, mem);

            WordList wordList2 = fileParser.ParseZip(mem);
            Assert.That(wordList2.GetAllWords().Select(w => w.Word.Name), Is.EquivalentTo(new[] { "apple", "orange" }));
            Assert.That(wordList2.GetAllTags(), Is.EquivalentTo(new[] { "fruit" }));
            Assert.That(wordList2.GetWordsWithTag("fruit").Select(w => w.Word.Name), Is.EquivalentTo(new[] { "apple", "orange" }));

            translationRemenberedEvent = wordList2.GetAllTranslations().Single(t => t.Translation == "a round fruit").Events.First().WordEvent;
            Assert.That(translationRemenberedEvent.EventType, Is.EqualTo(WordEventType.Remembered));
            Assert.That(translationRemenberedEvent.Translation, Is.EqualTo("a round fruit"));
        }