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 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 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")); }
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()); }
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 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 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 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 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 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)); }
private void FromAll() { var fileSystem = new FileSystem(); var markdownFiles = new MarkdownFiles(fileSystem, Location); var sorted = SortDirection == "Descending" ? markdownFiles.FindAll().OrderByDescending(FileNameToDate) : markdownFiles.FindAll().OrderBy(FileNameToDate); var filtered = Limit > 0 ? sorted.Take(Limit).Select(PathToPSObject) : sorted.Select(PathToPSObject); WriteObject(filtered, 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 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 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 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 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 Invalidate() { var fileSystem = new FileSystem(); var store = new FileStore <UserSettings>(fileSystem); var settings = store.Load(); var readerWriterFactory = new JournalReaderWriterFactory(fileSystem, settings.DefaultJournalRoot, 120); var markDownFiles = new MarkdownFiles(fileSystem, settings.DefaultJournalRoot); var systemProcess = SystemProcessFactory.Create(); var journal = Journal.Open(readerWriterFactory, markDownFiles, systemProcess); var uniqueTags = journal.GetUniqueTags(); MemoryCache.Default.Set(nameof(JournalTagCache), uniqueTags, _policy); _tags = uniqueTags; }
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 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 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 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 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 RenameTagDryRun_DoesNotInvokeJournalWriter_Ever() { var fileSystem = CreateVirtualJournal(2017, 2019); const string rootDirectory = "J:\\Current"; var ioFactory = A.Fake <IJournalReaderWriterFactory>(); var writer = A.Fake <IJournalWriter>(); A.CallTo(() => ioFactory.CreateWriter()).Returns(writer); A.CallTo(() => ioFactory.CreateReader(A <string> .Ignored)).ReturnsLazily((string file) => new JournalReader(fileSystem, file)); var systemProcess = A.Fake <ISystemProcess>(); var markdownFiles = new MarkdownFiles(fileSystem, rootDirectory); var journal = Journal.Open(ioFactory, markdownFiles, systemProcess); journal.RenameTagDryRun("blah"); A.CallTo(() => writer.RenameTag(A <IJournalReader> ._, A <string> ._, A <string> ._)).MustNotHaveHappened(); }
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(); }
public void CreateCompiledEntry1_IncludesAllDates_WhenNoFiltersAreSpecified() { var fileSystem = CreateVirtualJournal(2016, 2019, onlyValidEntries: true); 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("2016-1-1", "2019-12-28"); // Virtual journal assumes 28 days in a month. var filePath = ioFactory.CreateWriter().GetCompiledJournalEntryFilePath(dateRange); journal.CreateCompiledEntry(range: null, tags: null, allTagsRequired: false, overwrite: false); fileSystem.FileExists(fileSystem.Path.Combine(rootDirectory, "Compiled", filePath)).Should().BeTrue(); }
public void CreateCompiledEntry2_ThrowsException_WhenNoEntriesProvided(ICollection <IJournalEntry> 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); Assert.Throws <ArgumentException>(() => journal.CreateCompiledEntry(entries, false) ); Assert.Throws <ArgumentException>(() => journal.CreateCompiledEntry(null, false) ); }