Ejemplo n.º 1
0
        public async Task TestExportAnkiDue()
        {
            sourceCollection.Crt -= 86400 * 10;
            sourceCollection.Sched.Reset();
            var c = sourceCollection.Sched.PopCard();

            sourceCollection.Sched.AnswerCard(c, Sched.AnswerEase.Hard);
            sourceCollection.Sched.AnswerCard(c, Sched.AnswerEase.Hard);

            //Should have ivl of 1, due on day 11
            Assert.AreEqual(1, c.Interval);
            Assert.AreEqual(11, c.Due);
            Assert.AreEqual(10, sourceCollection.Sched.Today);

            //Export
            var export = new AnkiExporter(sourceCollection);

            export.IncludeSched = true;
            await export.ExportInto(tempExport, "ankitest.anki2");

            //Importing into a new col, the due date should be equivalent
            var tempfolder2 = await Utils.localFolder.CreateFolderAsync("tempfolder2");

            using (Collection col2 = await Utils.GetEmptyCollection(tempfolder2))
            {
                var imp = new Anki2Importer(col2, tempExport, "ankitest.anki2");
                await imp.Run();

                c = col2.GetCard(c.Id);
                col2.Sched.Reset();
                Assert.AreEqual(1, c.Due - col2.Sched.Today);
            }
            await tempfolder2.DeleteAsync();
        }
Ejemplo n.º 2
0
        public async Task TestExportAnki()
        {
            long did    = (long)sourceCollection.Deck.AddOrResuedDeck("test");
            var  dobj   = sourceCollection.Deck.Get(did);
            var  confId = sourceCollection.Deck.CreateNewConfiguration("newConf");
            var  conf   = sourceCollection.Deck.GetConf(confId);

            conf.GetNamedObject("new")["perDay"] = JsonValue.CreateNumberValue(5);
            sourceCollection.Deck.Save(conf);
            sourceCollection.Deck.SetConf(dobj, confId);

            //Export
            AnkiExporter export = new AnkiExporter(sourceCollection);
            await export.ExportInto(tempExport, "ankitest.anki2");

            //Exporting should not have changed conf for original deck
            conf = sourceCollection.Deck.ConfForDeckId(did);
            Assert.AreEqual(1, JsonHelper.GetNameNumber(conf, "id"));

            //Connect to new deck
            var col2 = await Storage.OpenOrCreateCollection(tempExport, "ankitest.anki2");

            Assert.AreEqual(2, col2.CardCount());

            //As scheduling was reset, should also revert decks to default conf
            long?newDid = col2.Deck.AddOrResuedDeck("test", false);

            Assert.IsNotNull(newDid);
            var conf2 = col2.Deck.ConfForDeckId(did);

            Assert.AreEqual(20, JsonHelper.GetNameNumber(conf2.GetNamedObject("new"), "perDay"));

            //Conf should be 1
            dobj = col2.Deck.Get(did);
            Assert.AreEqual(1, JsonHelper.GetNameNumber(dobj, "conf"));


            //Try again, limited to a deck
            col2.Close();
            await tempExport.DeleteAsync();

            tempExport = await Utils.localFolder.CreateFolderAsync("tempExport");

            export = new AnkiExporter(sourceCollection, 1);
            await export.ExportInto(tempExport, "ankitest.anki2");

            col2 = await Storage.OpenOrCreateCollection(tempExport, "ankitest.anki2");

            Assert.AreEqual(1, col2.CardCount());

            col2.Close();
        }