public void AppendTags_AddsTags_WhenNoCurrentTagsExist() { var frontMatter = new JournalFrontMatter(string.Empty, null); frontMatter.AppendTags(new[] { "test" }); frontMatter.Tags.Should().Contain("test"); }
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(); }
public void RenameTag(IJournalReader journalReader, string oldTag, string newTag) { if (string.IsNullOrWhiteSpace(oldTag) || string.IsNullOrWhiteSpace(newTag)) { throw new ArgumentNullException($"'{nameof(oldTag)}' cannot be null, empty, or whitespace.", nameof(oldTag)); } if (string.IsNullOrWhiteSpace(newTag)) { throw new ArgumentNullException($"'{nameof(newTag)}' cannot be null, empty, or whitespace.", nameof(newTag)); } if (!journalReader.FrontMatter.HasTags()) { throw new InvalidOperationException("No tags exist in this journal."); } var currentTags = journalReader.FrontMatter.Tags.ToList(); var oldItemIndex = currentTags.IndexOf(oldTag); if (oldItemIndex < 0) { throw new InvalidOperationException($"The tag '{oldTag}' does not exist."); } currentTags[oldItemIndex] = newTag; var readmeExpression = new ReadmeParser(journalReader.FrontMatter.Readme).ToExpression(journalReader.EntryDate); var frontMatter = new JournalFrontMatter(currentTags, readmeExpression); var newEntry = frontMatter.ToString(asFrontMatter: true) + journalReader.RawBody; _fileSystem.File.WriteAllText(journalReader.FilePath, newEntry); }
public void ToString_ReturnsValidFrontMatter_Always(string input, string expectedResult) { var journalDate = new LocalDate(2019, 9, 8); var frontMatter = new JournalFrontMatter(input, journalDate); var text = frontMatter.ToString(true); text.Should().Be(expectedResult); }
public void This_RemovesDuplicateTags_WhenPresent(string duplicateTags, string expectedYaml, int expectedCount) { var journalDate = new LocalDate(2019, 9, 8); var frontMatter = new JournalFrontMatter(duplicateTags, journalDate); frontMatter.Tags.Count.Should().Be(expectedCount); frontMatter.ToString().Should().Be(expectedYaml); }
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 This_DoesNotThrowExceptions_WhenYamlStringIsNullOrEmpty(string yaml) { var frontMatter = new JournalFrontMatter(yaml, null); frontMatter.Tags.Should().BeNull(); frontMatter.Readme.Should().BeNull(); frontMatter.ReadmeDate.Should().BeNull(); frontMatter.IsEmpty().Should().BeTrue(); }
public void Constructor_CanAcceptYamlBlockIndicators(string input, string toString, string expectedReadmeString, IEnumerable <string> expectedTags) { var journalDate = new LocalDate(2019, 9, 8); var frontMatter = new JournalFrontMatter(input, journalDate); frontMatter.ToString().Should().Be(toString); frontMatter.Readme.Should().Be(expectedReadmeString); frontMatter.Tags.Should().BeEquivalentTo(expectedTags); }
public void ToString_IgnoresNullValues_Always() { const string yaml = "Tags:\r\n - one\r\n - two"; var journalDate = new LocalDate(2019, 9, 8); var frontMatter = new JournalFrontMatter(yaml, journalDate); var text = frontMatter.ToString(); // Should include nothing but the originally supplied tags. text.Should().Be(yaml.ToLowerInvariant()); }
public void This_DoesNotThrowExceptions_WhenTagsAndReadmeParserAreNull() { IEnumerable <string> tags = null; ReadmeExpression readmeExpression = null; var frontMatter = new JournalFrontMatter(tags, readmeExpression); 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 This_ParsesLegacyReadmeValues_WhenPresent(string yaml, string entryDate, string readmeDate) { var journalDate = entryDate.ToLocalDate(); var frontMatter = new JournalFrontMatter(yaml, journalDate); frontMatter.Tags.Should().Contain(new List <string> { "one", "two" }); frontMatter.Readme.Should().Be(readmeDate); frontMatter.ReadmeDate.Should().Be(readmeDate.ToLocalDate()); frontMatter.IsEmpty().Should().BeFalse(); }
public void This_DoesNotThrowExceptions_WhenEntryFileHasNoYaml() { var fileSystem = new MockFileSystem(); var filePath = @"D:\TempJournal\2020\02 February\2020.02.12.md"; fileSystem.AddFile(filePath, new MockFileData("Here is some text without front matter")); var fm4 = JournalFrontMatter.FromFilePath(fileSystem, filePath); fm4.Tags.Should().BeNull(); fm4.Readme.Should().BeNull(); fm4.ReadmeDate.Should().BeNull(); fm4.IsEmpty().Should().BeTrue(); }