Beispiel #1
0
        public void NullArguments()
        {
            var type        = GetType();
            var assembly    = type.GetAssembly();
            var stream      = Stream.Null;
            var dataContext = new object();
            var document    = new Document();
            var target      = new TextRenderTarget();
            var buffer      = new ConsoleBuffer(80);
            var renderRect  = Rect.Empty;

          #if XAML
            var resourceName = "";

            new Action(() => ConsoleRenderer.ReadElementFromStream <Br>(null, dataContext))
            .Should().Throw <ArgumentNullException>().Which.ParamName.Should().Be(nameof(stream));
            new Action(() => ConsoleRenderer.ReadElementFromResource <Br>((Assembly)null, resourceName, dataContext))
            .Should().Throw <ArgumentNullException>().Which.ParamName.Should().Be(nameof(assembly));
            new Action(() => ConsoleRenderer.ReadElementFromResource <Br>(assembly, null, dataContext))
            .Should().Throw <ArgumentNullException>().Which.ParamName.Should().Be(nameof(resourceName));
            new Action(() => ConsoleRenderer.ReadElementFromResource <Br>((Type)null, resourceName, dataContext))
            .Should().Throw <ArgumentNullException>().Which.ParamName.Should().Be(nameof(type));
            new Action(() => ConsoleRenderer.ReadElementFromResource <Br>(type, null, dataContext))
            .Should().Throw <ArgumentNullException>().Which.ParamName.Should().Be(nameof(resourceName));
            new Action(() => ConsoleRenderer.ReadDocumentFromStream(null, dataContext))
            .Should().Throw <ArgumentNullException>().Which.ParamName.Should().Be(nameof(stream));
            new Action(() => ConsoleRenderer.ReadDocumentFromResource((Assembly)null, resourceName, dataContext))
            .Should().Throw <ArgumentNullException>().Which.ParamName.Should().Be(nameof(assembly));
            new Action(() => ConsoleRenderer.ReadDocumentFromResource(assembly, null, dataContext))
            .Should().Throw <ArgumentNullException>().Which.ParamName.Should().Be(nameof(resourceName));
            new Action(() => ConsoleRenderer.ReadDocumentFromResource((Type)null, resourceName, dataContext))
            .Should().Throw <ArgumentNullException>().Which.ParamName.Should().Be(nameof(type));
            new Action(() => ConsoleRenderer.ReadDocumentFromResource(type, null, dataContext))
            .Should().Throw <ArgumentNullException>().Which.ParamName.Should().Be(nameof(resourceName));
          #endif
            new Action(() => ConsoleRenderer.RenderDocument(null))
            .Should().Throw <ArgumentNullException>().Which.ParamName.Should().Be(nameof(document));
            new Action(() => ConsoleRenderer.RenderDocumentToBuffer(null, buffer, renderRect))
            .Should().Throw <ArgumentNullException>().Which.ParamName.Should().Be(nameof(document));
            new Action(() => ConsoleRenderer.RenderDocumentToBuffer(document, null, renderRect))
            .Should().Throw <ArgumentNullException>().Which.ParamName.Should().Be(nameof(buffer));
            new Action(() => ConsoleRenderer.RenderDocumentToText(null, target))
            .Should().Throw <ArgumentNullException>().Which.ParamName.Should().Be(nameof(document));
            new Action(() => ConsoleRenderer.RenderDocumentToText(document, null))
            .Should().Throw <ArgumentNullException>().Which.ParamName.Should().Be(nameof(target));
        }
Beispiel #2
0
        /// <summary>
        ///     Creates this instance.
        /// </summary>
        /// <returns>Document.</returns>
        public virtual Document Create()
        {
            var vm = CreateViewModel(Context);

            using (var resourceStream = Assembly.GetExecutingAssembly()
                                        .GetManifestResourceStream("ArgParser.Styles.Extensions.ParserHelp.xaml"))
            {
                return(ConsoleRenderer.ReadDocumentFromStream(resourceStream, vm, new XamlElementReaderSettings
                {
                    ReferenceAssemblies =
                    {
                        typeof(FigletDiv).Assembly,
                        typeof(ParserHelpTemplate).Assembly,
                        typeof(Parser).Assembly
                    }
                }));
            }
        }
        public void ReadDocumentFromStreamWithContext()
        {
            Document doc = ConsoleRenderer.ReadDocumentFromStream(StringToStream($"<Document {XamlNS}><Span Text='{{Get Length}}'/></Document>"), "abc");

            doc.Children.Should().ContainSingle().Which.Should().BeOfType <Span>().Which.Text.Should().Be("3");
        }
        public void ReadDocumentFromStream()
        {
            Document doc = ConsoleRenderer.ReadDocumentFromStream(StringToStream($"<Document {XamlNS}><Span Text='Foo'/></Document>"), null);

            doc.Children.Should().ContainSingle().Which.Should().BeOfType <Span>().Which.Text.Should().Be("Foo");
        }