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(); }
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)); }
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")); }
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); }
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()); }
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)); }
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); }
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)); }
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")); }
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(); }
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); }
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()); }
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"); }
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(); }
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"); }
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)); }
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(); }
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)); }
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); }
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); }
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)); }
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); }
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); }
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); }
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) ); }
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:"); }
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); }
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); }
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(); }