Ejemplo n.º 1
0
        public void CreateCompiledEntry2_CreatesEntry_WithProvidedEntries(ICollection <JournalEntryFile> entries)
        {
            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          expectedTags   = entries.SelectMany(x => x.Tags).Distinct();
            var          expectedBodies = entries.Select(x => x.Body).Distinct();

            journal.CreateCompiledEntry(entries.Cast <IJournalEntry>().ToList(), false);

            var compiledDirectory = fileSystem.Path.Combine(rootDirectory, "Compiled");
            var file     = fileSystem.Directory.GetFiles(compiledDirectory).Single();
            var fileText = fileSystem.File.ReadAllText(file);

            foreach (var body in expectedBodies)
            {
                fileText.Should().Contain(body);
            }

            JournalFrontMatter.FromFilePath(fileSystem, file).Tags.Should().OnlyContain(t => expectedTags.Contains(t));

            A.CallTo(() => systemProcess.Start(A <string> ._)).MustHaveHappened();
        }
Ejemplo n.º 2
0
        private protected Journal OpenJournal()
        {
            var fileSystem    = new FileSystem();
            var ioFactory     = new JournalReaderWriterFactory(fileSystem, Location);
            var markdownFiles = new MarkdownFiles(fileSystem, Location);

            return(Journal.Open(ioFactory, markdownFiles, SystemProcess));
        }
Ejemplo n.º 3
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"));
        }
Ejemplo n.º 4
0
        public PipedEntries()
        {
            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);

            _journal = Journal.Open(ioFactory, markdownFiles, systemProcess);
        }
Ejemplo n.º 5
0
        public void OpenRandomEntry_ThrowsException_WhenNoEntriesAreFound()
        {
            var          fileSystem    = CreateEmptyJournal();
            const string rootDirectory = "J:\\Current";
            var          ioFactory     = new JournalReaderWriterFactory(fileSystem, rootDirectory);
            var          markdownFiles = new MarkdownFiles(fileSystem, rootDirectory);
            var          systemProcess = A.Fake <ISystemProcess>();
            var          journal       = Journal.Open(ioFactory, markdownFiles, systemProcess);

            Assert.Throws <InvalidOperationException>(() => journal.OpenRandomEntry());
        }
Ejemplo n.º 6
0
        public void CreateNewEntry_ThrowsException_IfEntryAlreadyExists()
        {
            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);

            Assert.Throws <JournalEntryAlreadyExistsException>(() => journal.CreateNewEntry(new LocalDate(2019, 1, 1), null, null));
        }
Ejemplo n.º 7
0
        public void RenameTagDryRun_ThrowsException_WhenTagDoesExist()
        {
            var          fileSystem    = CreateVirtualJournal(2017, 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);

            Assert.Throws <InvalidOperationException>(() => journal.RenameTagDryRun("superman"));
        }
        protected override void RunJournalCommand()
        {
            var fileSystem          = new FileSystem();
            var readerWriterFactory = new JournalReaderWriterFactory(fileSystem, Location);
            var markdownFiles       = new MarkdownFiles(fileSystem, Location);
            var journal             = Journal.Open(readerWriterFactory, markdownFiles, SystemProcess);

            var entries = journal.GetRecentEntries(Limit);

            WriteObject(entries, true);
        }
Ejemplo n.º 9
0
        public void CreateCompiledEntry2_ThrowsException_WhenEntryExistsAndOverwriteIsFalse(ICollection <JournalEntryFile> entries)
        {
            var          fileSystem    = CreateVirtualJournal(2019, 2019);
            const string rootDirectory = "J:\\Current";
            var          ioFactory     = new JournalReaderWriterFactory(fileSystem, rootDirectory, BodyWrapWidth);
            var          systemProcess = A.Fake <ISystemProcess>();
            var          markdownFiles = new MarkdownFiles(fileSystem, rootDirectory);
            var          journal       = Journal.Open(ioFactory, markdownFiles, systemProcess);

            journal.CreateCompiledEntry(entries.Cast <IJournalEntry>().ToList(), false);
            Assert.Throws <JournalEntryAlreadyExistsException>(() => journal.CreateCompiledEntry(entries.Cast <IJournalEntry>().ToList(), false));
        }
Ejemplo n.º 10
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"));
        }
Ejemplo n.º 11
0
        public void OpenRandomEntry_OpensTaggedEntry_WhenTagIsProvided()
        {
            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);

            journal.OpenRandomEntry(new[] { "cat" }, null);
            A.CallTo(() => systemProcess.Start(A <string> ._)).MustHaveHappened();
        }
Ejemplo n.º 12
0
        public void CreateCompiledEntry2_OverwritesEntry_WhenEntryExistsAndOverwriteIsTrue(ICollection <JournalEntryFile> entries)
        {
            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);

            journal.CreateCompiledEntry(entries.Cast <IJournalEntry>().ToList(), false);
            journal.CreateCompiledEntry(entries.Cast <IJournalEntry>().ToList(), true);
        }
Ejemplo n.º 13
0
        public void GetRecentEntries_ReturnsAllEntries_WhenLimitIsLessThanOne(int limit)
        {
            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 entries = journal.GetRecentEntries(limit);

            entries.Count().Should().Be(fileSystem.AllFiles.Count());
        }
Ejemplo n.º 14
0
        public void CreateNewEntry_CreatesFileName_ThatMatchEntryDate()
        {
            var          fileSystem    = new MockFileSystem();
            const string rootDirectory = "J:\\Current";
            var          ioFactory     = new JournalReaderWriterFactory(fileSystem, rootDirectory);
            var          systemProcess = A.Fake <ISystemProcess>();
            var          markdownFiles = A.Fake <IMarkdownFiles>();
            var          journal       = Journal.Open(ioFactory, markdownFiles, systemProcess);

            journal.CreateNewEntry(new LocalDate(2019, 7, 19), null, "");

            fileSystem.AllFiles.Should().OnlyContain(x => x == "J:\\Current\\2019\\07 July\\2019.07.19.md");
        }
Ejemplo n.º 15
0
        public void OpenRandomEntry_SearchesEntireJournal_WhenNoTagsOrDateRangeUsed()
        {
            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);

            journal.OpenRandomEntry(new string[] { }, null);

            A.CallTo(() => systemProcess.Start(A <string> ._)).MustHaveHappened();
        }
Ejemplo n.º 16
0
        public void CreateNewEntry_AddsEmptyFrontMatter_WhenNoTagsOrReadmeAreProvided(string[] tags, string readme)
        {
            var          fileSystem    = new MockFileSystem();
            const string rootDirectory = "J:\\Current";
            var          ioFactory     = new JournalReaderWriterFactory(fileSystem, rootDirectory);
            var          systemProcess = A.Fake <ISystemProcess>();
            var          markdownFiles = A.Fake <IMarkdownFiles>();
            var          journal       = Journal.Open(ioFactory, markdownFiles, systemProcess);

            journal.CreateNewEntry(new LocalDate(2019, 7, 19), tags, readme);

            fileSystem.GetFile("J:\\Current\\2019\\07 July\\2019.07.19.md").TextContents.Should().Be("---\r\ntags:\r\n  - (untagged)\r\n---\r\n# Friday, July 19, 2019\r\n");
        }
Ejemplo n.º 17
0
        public void OpenRandomEntry_ThrowsException_WhenNoTaggedEntriesFound()
        {
            var          fileSystem    = CreateVirtualJournal(2020, 2023);
            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);

            Assert.Throws <InvalidOperationException>(() => journal.OpenRandomEntry(new List <string> {
                "fake"
            }, null));
        }
Ejemplo n.º 18
0
        public void OpenRandomEntry_SearchesEntireJournal_WhenNoTagsOrDateRangeUsed()
        {
            var          fileSystem    = CreateVirtualJournal(2019, 2019);
            const string rootDirectory = "J:\\Current";
            var          ioFactory     = new JournalReaderWriterFactory(fileSystem, rootDirectory, BodyWrapWidth);
            var          systemProcess = A.Fake <ISystemProcess>();
            var          markdownFiles = new MarkdownFiles(fileSystem, rootDirectory);
            var          journal       = Journal.Open(ioFactory, markdownFiles, systemProcess);

            var entry = journal.GetRandomEntry(new string[] { }, TagOperator.Any, null);

            entry.Should().NotBeNull();
        }
Ejemplo n.º 19
0
        public void OpenRandomEntry_ThrowsException_WhenNoEntriesFound()
        {
            var          fileSystem    = new MockFileSystem();
            const string rootDirectory = "J:\\Current";

            fileSystem.AddDirectory(rootDirectory);
            var ioFactory     = new JournalReaderWriterFactory(fileSystem, rootDirectory, BodyWrapWidth);
            var systemProcess = A.Fake <ISystemProcess>();
            var markdownFiles = new MarkdownFiles(fileSystem, rootDirectory);
            var journal       = Journal.Open(ioFactory, markdownFiles, systemProcess);

            Assert.Throws <InvalidOperationException>(() => journal.GetRandomEntry(new[] { "fake" }, TagOperator.Any, null));
        }
Ejemplo n.º 20
0
        public void RenameTagDryRun_ReturnsListOfEffectedFiles_Always()
        {
            var          fileSystem    = CreateVirtualJournal(2017, 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          index         = journal.CreateIndex <MetaJournalEntry>();

            var blahCount = index["blah"].Count;

            journal.RenameTagDryRun("blah").Should().HaveCount(blahCount);
        }
Ejemplo n.º 21
0
        public void CreateCompiledEntry1_OverwritesEntry_WhenEntryExistsAndOverwriteIsTrue()
        {
            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");

            journal.CreateCompiledEntry(dateRange, tags: null, allTagsRequired: false, overwrite: false);
            journal.CreateCompiledEntry(dateRange, tags: null, allTagsRequired: false, overwrite: true);
        }
Ejemplo n.º 22
0
        public void CreateCompiledEntry1_ThrowsException_WhenEntryExistsAndOverwriteIsFalse()
        {
            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");

            journal.CreateCompiledEntry(dateRange, null, false, false);
            Assert.Throws <JournalEntryAlreadyExistsException>(() => journal.CreateCompiledEntry(dateRange, null, false, false));
        }
Ejemplo n.º 23
0
        public void GetReadmeEntries_FiltersOutEntriesOlderThanEarliestDate()
        {
            var          earliestDate  = new LocalDate(2009, 4, 25);
            var          fileSystem    = CreateVirtualJournal(2005, 2010);
            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          readmes       = journal.GetReadmeEntries(earliestDate, false);

            var count = readmes.Count(r => r.ReadmeDate <= earliestDate);

            count.Should().Be(0);
        }
Ejemplo n.º 24
0
        public void OpenRandomEntry_OpensEntryWithinDateRange_WhenRangeIsProvided()
        {
            var          fileSystem    = CreateVirtualJournal(2019, 2019);
            const string rootDirectory = "J:\\Current";
            var          ioFactory     = new JournalReaderWriterFactory(fileSystem, rootDirectory, BodyWrapWidth);
            var          systemProcess = A.Fake <ISystemProcess>();
            var          markdownFiles = new MarkdownFiles(fileSystem, rootDirectory);
            var          journal       = Journal.Open(ioFactory, markdownFiles, systemProcess);
            var          entry         = journal.GetRandomEntry(null, TagOperator.Any, new DateRange(new LocalDate(2019, 6, 1), new LocalDate(2019, 6, 15)));

            var nameElements = entry.EntryName.Split(new[] { '.' });
            var intElements  = nameElements.Select(int.Parse).ToArray();

            Assert.True(intElements[0] == 2019 && intElements[1] == 6 && intElements[2] >= 1 && intElements[2] <= 15);
        }
Ejemplo n.º 25
0
        public void GetReadmeEntries_ExcludesFutureEntries_WhenSpecified()
        {
            var          earliestDate  = new LocalDate();
            var          fileSystem    = CreateVirtualJournal(2030, 2030);
            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          readmes       = journal.GetReadmeEntries(earliestDate, false);

            // Because the journal only includes entries from 2030, and all readmes have relative dates specified (5 years),
            // all readme entries should have a future expiration. Note that in 2035, this test will need to be updated. ;)
            readmes.Count.Should().Be(0);
        }
Ejemplo n.º 26
0
        public void CreateCompiledEntry1_ThrowsException_WhenNoEntriesFoundInDateRange()
        {
            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("2018-2-12", "2018-6-1");

            Assert.Throws <InvalidOperationException>(() =>
                                                      journal.CreateCompiledEntry(dateRange, tags: null, allTagsRequired: true, overwrite: false)
                                                      );
        }
Ejemplo n.º 27
0
        public void CreateNewEntry_OnlyIncludesReadmeInFrontMatter_WhenOnlyReadmeIsProvided()
        {
            var          fileSystem    = new MockFileSystem();
            const string rootDirectory = "J:\\Current";
            var          ioFactory     = new JournalReaderWriterFactory(fileSystem, rootDirectory);
            var          systemProcess = A.Fake <ISystemProcess>();
            var          markdownFiles = A.Fake <IMarkdownFiles>();
            var          journal       = Journal.Open(ioFactory, markdownFiles, systemProcess);

            journal.CreateNewEntry(new LocalDate(2019, 7, 19), null, "2 years");

            var entryText = fileSystem.GetFile("J:\\Current\\2019\\07 July\\2019.07.19.md").TextContents;

            entryText.Should().Contain("readme: 2 years");
            entryText.Should().NotContain("tags:");
        }
Ejemplo n.º 28
0
        public void GetReadmeEntries_IncludesFutureEntries_WhenSpecified()
        {
            var          earliestDate  = new LocalDate();
            var          fileSystem    = CreateVirtualJournal(2030, 2031);
            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          readmes       = journal.GetReadmeEntries(earliestDate, true);

            // Since the earliest entries in this journal are dated 2030, and the min expiration date is 5 years,
            // none of them will have expired before 2035. Therefore, all readmes in this collection should be included.
            // This test will also have to be updated in 2035. F**k, I'll be 57 years old!
            readmes.Count.Should().Be(fileSystem.TotalReadmeEntries);
        }
Ejemplo n.º 29
0
        public void GetReadmeEntries_ReturnsAllEntries_WhenMaxDateIsDefaultValue()
        {
            var          earliestDate  = new LocalDate();
            var          fileSystem    = CreateVirtualJournal(2005, 2010);
            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          readmes       = journal.GetReadmeEntries(earliestDate, false);

            // Since this journal only has entries up to 2010, and the max expiration date is 5 years,
            // by "now" (e.g. the current date) they should have all expired. Therefore, the "include future" option
            // is effectively irrelevant in this scenario.
            readmes.Count.Should().Be(fileSystem.TotalReadmeEntries);
        }
Ejemplo n.º 30
0
        public void CreateIndex_SkipsEntries_OutsideDateRange()
        {
            var          fileSystem    = CreateVirtualJournal(2017, 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 from      = new LocalDate(2019, 1, 1);
            var to        = new LocalDate(2019, 1, 10);
            var dateRange = new DateRange(from, to);
            var index     = journal.CreateIndex <JournalEntryFile>(dateRange);

            index.SelectMany(x => x.Entries).All(x => x.EntryDate >= from && x.EntryDate <= to).Should().BeTrue();
        }