Exemple #1
0
        public void RenameTag_ThrowsInvalidOperationException_WhenOldTagDoesNotExist()
        {
            var fileSystem = CreateVirtualJournal(2017, 2020);
            var ioFactory  = new JournalReaderWriterFactory(fileSystem, "J:\\Current");
            var writer     = ioFactory.CreateWriter();
            var reader     = ioFactory.CreateReader(fileSystem.AllFiles.First(x => x.EndsWith(".md")));

            Assert.Throws <InvalidOperationException>(() => writer.RenameTag(reader, "oldTag", "newTag"));
        }
Exemple #2
0
        public void RenameTag_ThrowsException_WhenNoTagsExist()
        {
            var          fileSystem = new MockFileSystem();
            const string entryPath  = @"J:\Current\2019\01 January\2019.01.01.md";

            fileSystem.AddFile(entryPath, new MockFileData(TestEntries.WithoutFrontMatter));
            var ioFactory = new JournalReaderWriterFactory(fileSystem, "J:\\Current");
            var writer    = ioFactory.CreateWriter();
            var reader    = ioFactory.CreateReader(entryPath);

            Assert.Throws <InvalidOperationException>(() => writer.RenameTag(reader, "oldTag", "newTag"));
        }
Exemple #3
0
        public void CreateCompiledEntry1_IncludesAllTags_WhenNoneAreSpecified()
        {
            var          fileSystem    = CreateVirtualJournal(2019, 2019);
            const string rootDirectory = "J:\\Current";
            var          ioFactory     = new JournalReaderWriterFactory(fileSystem, rootDirectory);
            var          systemProcess = A.Fake <ISystemProcess>();
            var          markdownFiles = new MarkdownFiles(fileSystem, rootDirectory);
            var          journal       = Journal.Open(ioFactory, markdownFiles, systemProcess);

            var dateRange = new DateRange("2019-2-12", "2019-3-1");
            var filePath  = ioFactory.CreateWriter().GetCompiledJournalEntryFilePath(dateRange);

            journal.CreateCompiledEntry(dateRange, tags: null, allTagsRequired: false, overwrite: false);

            var allTags = journal.CreateIndex <MetaJournalEntry>().Select(x => x.Tag);

            ioFactory.CreateReader(filePath).FrontMatter.Tags.Should().OnlyContain(t => allTags.Contains(t));
        }
Exemple #4
0
        public void CreateCompiledEntry1_FiltersByTag_WhenTagIsSpecifiedAndAllAreRequired(params string[] tags)
        {
            var          fileSystem    = CreateVirtualJournal(2019, 2019);
            const string rootDirectory = "J:\\Current";
            var          ioFactory     = new JournalReaderWriterFactory(fileSystem, rootDirectory);
            var          systemProcess = A.Fake <ISystemProcess>();
            var          markdownFiles = new MarkdownFiles(fileSystem, rootDirectory);
            var          journal       = Journal.Open(ioFactory, markdownFiles, systemProcess);

            var dateRange = new DateRange("2019-2-12", "2019-6-1");
            var filePath  = ioFactory.CreateWriter().GetCompiledJournalEntryFilePath(dateRange);

            journal.CreateCompiledEntry(dateRange, tags: tags, allTagsRequired: true, overwrite: false);

            var expectedTags = journal.CreateIndex <MetaJournalEntry>(range: null, requiredTags: tags)
                               .SelectMany(x => x.Entries)
                               .SelectMany(x => x.Tags)
                               .Distinct();

            ioFactory.CreateReader(filePath).FrontMatter.Tags.Should().OnlyContain(t => expectedTags.Contains(t));
        }