public void ProcessesShortcode()
            {
                // Given
                TestExecutionContext context = new TestExecutionContext();

                context.Shortcodes.Add <TestShortcode>("Bar");
                IDocument document = new TestDocument("123<?# Bar /?>456");

                Core.Modules.Contents.Shortcodes module = new Core.Modules.Contents.Shortcodes();

                // When
                List <IDocument> results = module.Execute(new[] { document }, context).ToList();

                // Then
                results.Single().Content.ShouldBe("123Foo456");
            }
            public void DisposesShortcode()
            {
                // Given
                TestExecutionContext context = new TestExecutionContext();

                context.Shortcodes.Add <DisposableShortcode>("Bar");
                IDocument document = new TestDocument("123<?# Bar /?>456");

                Core.Modules.Contents.Shortcodes module = new Core.Modules.Contents.Shortcodes();

                // When
                List <IDocument> results = module.Execute(new[] { document }, context).ToList();

                // Then
                DisposableShortcode.Disposed.ShouldBeTrue();
            }
            public void DoesNotProcessNestedRawShortcode()
            {
                // Given
                TestExecutionContext context = new TestExecutionContext();

                context.Shortcodes.Add <RawShortcode>("Raw");
                context.Shortcodes.Add <TestShortcode>("Bar");
                IDocument document = new TestDocument("123<?# Raw ?>ABC<?# Bar /?>XYZ<?#/ Raw ?>456");

                Core.Modules.Contents.Shortcodes module = new Core.Modules.Contents.Shortcodes();

                // When
                List <IDocument> results = module.Execute(new[] { document }, context).ToList();

                // Then
                results.Single().Content.ShouldBe("123ABC<?# Bar /?>XYZ456");
            }
            public void ShortcodesPersistState()
            {
                // Given
                TestExecutionContext context = new TestExecutionContext();

                context.Shortcodes.Add <IncrementingShortcode>("S");
                IDocument document = new TestDocument("123<?# S /?>456<?# S /?>789<?# S /?>");

                Core.Modules.Contents.Shortcodes module = new Core.Modules.Contents.Shortcodes();

                // When
                List <IDocument> results = module.Execute(new[] { document }, context).ToList();

                // Then
                results.Single().Content.ShouldBe("123456789");
                results.Single()["Foo"].ShouldBe(22);
            }
            public void ShortcodeSupportsNullResult()
            {
                // Given
                TestExecutionContext context = new TestExecutionContext();

                context.Shortcodes.Add <TestShortcode>("S1");
                context.Shortcodes.Add <NullResultShortcode>("S2");
                IDocument document = new TestDocument("123<?# S1 /?>456<?# S2 /?>789<?# S1 /?>");

                Core.Modules.Contents.Shortcodes module = new Core.Modules.Contents.Shortcodes();

                // When
                List <IDocument> results = module.Execute(new[] { document }, context).ToList();

                // Then
                results.Single().Content.ShouldBe("123Foo456789Foo");
            }
            public void ShortcodesCanAddMetadata()
            {
                // Given
                TestExecutionContext context = new TestExecutionContext();

                context.Shortcodes.Add <AddsMetadataShortcode>("S1");
                context.Shortcodes.Add <AddsMetadataShortcode2>("S2");
                IDocument document = new TestDocument("123<?# S1 /?>456<?# S2 /?>789");

                Core.Modules.Contents.Shortcodes module = new Core.Modules.Contents.Shortcodes();

                // When
                List <IDocument> results = module.Execute(new[] { document }, context).ToList();

                // Then
                results.Single().Content.ShouldBe("123456789");
                results.Single()["A"].ShouldBe("3");
                results.Single()["B"].ShouldBe("2");
                results.Single()["C"].ShouldBe("4");
            }
            public void ShortcodesCanReadMetadata()
            {
                // Given
                TestExecutionContext context = new TestExecutionContext();

                context.Shortcodes.Add <ReadsMetadataShortcode>("S1");
                context.Shortcodes.Add <ReadsMetadataShortcode>("S2");
                IDocument document = new TestDocument("123<?# S1 /?>456<?# S2 /?>789<?# S1 /?>", new MetadataItems
                {
                    { "Foo", 10 }
                });

                Core.Modules.Contents.Shortcodes module = new Core.Modules.Contents.Shortcodes();

                // When
                List <IDocument> results = module.Execute(new[] { document }, context).ToList();

                // Then
                results.Single().Content.ShouldBe("123456789");
                results.Single()["Foo"].ShouldBe(13);
            }