Exemplo n.º 1
0
        public void AddOrAppendToCustomHeader_AppendsHeader_WhenExists()
        {
            var rawBody = TestBodies.MultipleHeadersIncludingDefaultH1;

            var body          = new JournalEntryBody(rawBody);
            var originalCount = body.Count();

            const string customHeader  = "## The standard Lorem Ipsum passage, used since the 1500s";
            var          originalIndex = body.ToList().FindIndex(x => x.header == customHeader);
            const string appended      = "- Today I did the thing\r\n- Then I did another thing.";

            body.AddOrAppendToCustomHeader(customHeader, new[] { appended });

            var currentIndex = body.ToList().FindIndex(x => x.header == customHeader);

            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
        }
Exemplo n.º 2
0
        public void AddOrAppendToCustomHeader_ThrowsException_WhenHeaderFormattedIncorrectly()
        {
            var rawBody = TestBodies.NoHeadersOnlyText;
            var body    = new JournalEntryBody(rawBody);

            Assert.Throws <ArgumentException>(() => body.AddOrAppendToCustomHeader("Header Name", new[] { "Here is some additional text I would like to add." }));
        }
Exemplo n.º 3
0
        public void AddOrAppendToCustomHeader_AddsHeader_WhenNotExists()
        {
            var rawBody = TestBodies.NoHeadersOnlyText;

            var body = new JournalEntryBody(rawBody);

            body.Count().Should().Be(1);

            const string appended = "- Today I did the thing\r\n- Then I did another thing.";
            const string header   = "## My Header";

            body.AddOrAppendToCustomHeader(header, new[] { appended });
            body.ToList().FindIndex(x => x.header == header).Should().Be(1);

            body.Count().Should().Be(2);

            var output = body.ToString();

            output.Length.Should().Be(rawBody.Trim().Length + appended.Length + header.Length + 8); // 4 line breaks X 2 chars each
        }