public void AddOrAppendToDefaultHeader_AppendsHeader_WhenExists() { var rawBody = TestBodies.MultipleHeadersIncludingDefaultH1; var body = new JournalEntryBody(rawBody); var originalCount = body.Count(); body.Count(x => DateTime.TryParse(x.header.Replace("#", "").Trim(), out _)).Should().Be(1); var defaultHeader = body.First().header; var originalIndex = body.ToList().FindIndex(x => x.header == defaultHeader); const string appended = "- Today I did the thing\r\n- Then I did another thing."; body.AddOrAppendToDefaultHeader(Today.Date(), new[] { appended }); var currentIndex = body.ToList().FindIndex(x => x.header == defaultHeader); currentIndex.Should().Be(originalIndex); var currentCount = body.Count(); currentCount.Should().Be(originalCount); var output = body.ToString(); output.Length.Should().Be(rawBody.Trim().Length + appended.Length + 4); // 2 line breaks X 2 chars each }
private void OpenToCurrent() { var fileSystem = new FileSystem(); string path; var year = Journal.YearDirectoryPattern.Format(Today.Date()); var month = Journal.MonthDirectoryPattern.Format(Today.Date()); switch (To) { case "CurrentMonth": path = fileSystem.Path.Combine(Location, year, month); break; case "CurrentYear": path = fileSystem.Path.Combine(Location, year); break; default: path = fileSystem.Path.Combine(Location); break; } if (!fileSystem.Directory.Exists(path)) { throw new PSInvalidOperationException("No directory currently exists for the selected period."); } SystemProcess.Start(path); }
public void AddOrAppendToCustomHeader_ThrowsException_WhenLinesAreNullOrEmpty(ICollection <string> lines) { var rawBody = TestBodies.AllTextHasExactlyOneHeader; var body = new JournalEntryBody(rawBody); Assert.Throws <ArgumentException>(() => body.AddOrAppendToDefaultHeader(Today.Date(), lines)); }
public void This_DoesNotThrowExceptions_WhenYamlIsNullOrEmptyButDateIsValid(string yaml) { var frontMatter = new JournalFrontMatter(yaml, Today.Date()); frontMatter.Tags.Should().BeNull(); frontMatter.Readme.Should().BeNull(); frontMatter.ReadmeDate.Should().BeNull(); frontMatter.IsEmpty().Should().BeTrue(); }
public void ToString_ShouldInsertDefaultTags_IfNoneArePresent() { var frontMatter = new JournalFrontMatter(string.Empty, Today.Date()); var yaml = frontMatter.ToString(true); yaml.Should().Contain("- (untagged)"); var text = frontMatter.ToString(); text.Should().Contain("- (untagged)"); }
public void Add(IJournalReader reader) { if (string.IsNullOrEmpty(reader.FrontMatter.Readme)) { return; } if (_includeFuture && reader.FrontMatter.ReadmeDate > Today.Date() || // Include readme's which expire after today, if requested. reader.FrontMatter.ReadmeDate <= Today.Date() && reader.FrontMatter.ReadmeDate >= _earliestDate) // Include readme's between earliestDate and today. { var readme = new ReadmeJournalEntry(reader); _readMeEntries.Add(readme); } }