예제 #1
0
            public async Task IteratesScript()
            {
                // Given
                TestExecutionContext context = new TestExecutionContext();

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

                KeyValuePair <string, string>[] args = new KeyValuePair <string, string>[]
                {
                    new KeyValuePair <string, string>("Key", "=> new int[] { 1, 2, (int)Foo + 1 }"),
                    new KeyValuePair <string, string>("ValueKey", "Bar")
                };
                ForEachShortcode shortcode = new ForEachShortcode();

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

                // Then
                result.Cast <TestDocument>().ShouldAllBe(x => x.Content == "Fizzbuzz");
                result.Select(x => x.Get("Bar")).ShouldBe(new object[] { 1, 2, 6 });
            }
예제 #2
0
            public void IteratesScript()
            {
                // Given
                TestExecutionContext context = new TestExecutionContext();

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

                KeyValuePair <string, string>[] args = new KeyValuePair <string, string>[]
                {
                    new KeyValuePair <string, string>("Key", "=> new int[] { 1, 2, (int)Foo + 1 }"),
                    new KeyValuePair <string, string>("ValueKey", "Bar")
                };
                ForEachShortcode shortcode = new ForEachShortcode();

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

                // Then
                result.ShouldAllBe(x => x.ContentProvider.GetStream().ReadToEnd() == "Fizzbuzz");
                result.Select(x => x.NestedMetadata["Bar"]).ShouldBe(new object[] { 1, 2, 6 });
            }
예제 #3
0
            public async Task ThrowsForInvalidValueKey()
            {
                // Given
                TestExecutionContext context  = new TestExecutionContext();
                TestDocument         document = new TestDocument();

                KeyValuePair <string, string>[] args = new KeyValuePair <string, string>[]
                {
                    new KeyValuePair <string, string>("Key", "Foo"),
                    new KeyValuePair <string, string>("ValueKey", string.Empty)
                };
                ForEachShortcode shortcode = new ForEachShortcode();

                // When, Then
                await Should.ThrowAsync <ShortcodeArgumentException>(async() => await shortcode.ExecuteAsync(args, string.Empty, document, context));
            }
예제 #4
0
            public async Task MissingKey()
            {
                // Given
                TestExecutionContext context  = new TestExecutionContext();
                TestDocument         document = new TestDocument();

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

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

                // Then
                result.ShouldBeNull();
            }