public void ReturnsNullIfMissingKey()
            {
                // Given
                TestExecutionContext context  = new TestExecutionContext();
                TestDocument         document = new TestDocument();

                KeyValuePair <string, string>[] args = new KeyValuePair <string, string>[]
                {
                    new KeyValuePair <string, string>("Key", "Foo")
                };
                IfShortcode shortcode = new IfShortcode();

                // When
                ShortcodeResult result = shortcode.Execute(args, "Fizzbuzz", document, context);

                // Then
                result.ShouldBeNull();
            }
            public void ReturnsNullIfCanNotConvertToBool()
            {
                // Given
                TestExecutionContext context  = new TestExecutionContext();
                TestDocument         document = new TestDocument(new MetadataItems
                {
                    { "Foo", "abc" }
                });

                KeyValuePair <string, string>[] args = new KeyValuePair <string, string>[]
                {
                    new KeyValuePair <string, string>("Key", "Foo")
                };
                IfShortcode shortcode = new IfShortcode();

                // When
                ShortcodeResult result = shortcode.Execute(args, "Fizzbuzz", document, context);

                // Then
                result.ShouldBeNull();
            }
            public void ReturnsDocumentIfConvertedTrue()
            {
                // Given
                TestExecutionContext context  = new TestExecutionContext();
                TestDocument         document = new TestDocument(new MetadataItems
                {
                    { "Foo", "true" }
                });

                KeyValuePair <string, string>[] args = new KeyValuePair <string, string>[]
                {
                    new KeyValuePair <string, string>("Key", "Foo")
                };
                IfShortcode shortcode = new IfShortcode();

                // When
                ShortcodeResult result = shortcode.Execute(args, "Fizzbuzz", document, context);

                // Then
                result.ContentProvider.GetStream().ReadToEnd().ShouldBe("Fizzbuzz");
            }
Ejemplo n.º 4
0
            public async Task ReturnsNullIfConvertedFalse()
            {
                // Given
                TestExecutionContext context  = new TestExecutionContext();
                TestDocument         document = new TestDocument(new MetadataItems
                {
                    { "Foo", "false" }
                });

                KeyValuePair <string, string>[] args = new KeyValuePair <string, string>[]
                {
                    new KeyValuePair <string, string>("Key", "Foo")
                };
                IfShortcode shortcode = new IfShortcode();

                // When
                IDocument result = await shortcode.ExecuteAsync(args, "Fizzbuzz", document, context);

                // Then
                result.ShouldBeNull();
            }
Ejemplo n.º 5
0
            public async Task ReturnsDocumentIfTrue()
            {
                // Given
                TestExecutionContext context  = new TestExecutionContext();
                TestDocument         document = new TestDocument(new MetadataItems
                {
                    { "Foo", true }
                });

                KeyValuePair <string, string>[] args = new KeyValuePair <string, string>[]
                {
                    new KeyValuePair <string, string>("Key", "Foo")
                };
                IfShortcode shortcode = new IfShortcode();

                // When
                IDocument result = await shortcode.ExecuteAsync(args, "Fizzbuzz", document, context);

                // Then
                result.ShouldBeOfType <TestDocument>().Content.ShouldBe("Fizzbuzz");
            }
            public void ReturnsDocumentIfScriptEqual()
            {
                // Given
                TestExecutionContext context = new TestExecutionContext();

                context.ScriptHelper = new ScriptHelper(context);
                TestDocument document = new TestDocument()
                {
                    { "Foo", 122 }
                };

                KeyValuePair <string, string>[] args = new KeyValuePair <string, string>[]
                {
                    new KeyValuePair <string, string>("Key", "=> (int)Foo + 1"),
                    new KeyValuePair <string, string>("Value", "123")
                };
                IfShortcode shortcode = new IfShortcode();

                // When
                ShortcodeResult result = shortcode.Execute(args, "Fizzbuzz", document, context);

                // Then
                result.ContentProvider.GetStream().ReadToEnd().ShouldBe("Fizzbuzz");
            }
Ejemplo n.º 7
0
            public async Task ReturnsDocumentIfScriptEqual()
            {
                // Given
                TestExecutionContext context = new TestExecutionContext();

                context.ScriptHelper = new ScriptHelper(context);
                TestDocument document = new TestDocument()
                {
                    { "Foo", 122 }
                };

                KeyValuePair <string, string>[] args = new KeyValuePair <string, string>[]
                {
                    new KeyValuePair <string, string>("Key", "=> (int)Foo + 1"),
                    new KeyValuePair <string, string>("Value", "123")
                };
                IfShortcode shortcode = new IfShortcode();

                // When
                IDocument result = await shortcode.ExecuteAsync(args, "Fizzbuzz", document, context);

                // Then
                result.ShouldBeOfType <TestDocument>().Content.ShouldBe("Fizzbuzz");
            }