public void SetFormattedText_ValidXmlWithSupportedChildNode_ConvertToInlines()
        {
            // Setup
            const string xmlToConvert = "<text>test <bold>bold text</bold></text>";
            var          textBlock    = new TextBlock();

            // Precondition
            CollectionAssert.IsEmpty(textBlock.Inlines);

            // Call
            TextBlockExtensions.SetFormattedText(textBlock, xmlToConvert);

            // Assert
            Assert.AreEqual(1, textBlock.Inlines.Count);
            var span = (Span)textBlock.Inlines.First();

            Inline[] spanInlines = span.Inlines.ToArray();

            Assert.AreEqual(2, spanInlines.Length);
            var run = (Run)spanInlines[0];

            Assert.AreEqual("test ", run.Text);

            var bold     = (Bold)spanInlines[1];
            var boldSpan = (Span)bold.Inlines.First();

            Assert.AreEqual("bold text", ((Run)boldSpan.Inlines.First()).Text);
        }
        public void GetFormattedText_TextSet_ReturnText()
        {
            // Setup
            const string xmlToConvert = "<text>test <bold>bold text</bold></text>";
            var          textBlock    = new TextBlock();

            TextBlockExtensions.SetFormattedText(textBlock, xmlToConvert);

            // Call
            string formattedText = TextBlockExtensions.GetFormattedText(textBlock);

            // Assert
            Assert.AreEqual(xmlToConvert, formattedText);
        }
        public void SetFormattedText_ValidXmlWithoutChildNodes_ConvertToInlines()
        {
            // Setup
            const string xmlToConvert = "<text>test</text>";
            var          textBlock    = new TextBlock();

            // Precondition
            CollectionAssert.IsEmpty(textBlock.Inlines);

            // Call
            TextBlockExtensions.SetFormattedText(textBlock, xmlToConvert);

            // Assert
            Assert.AreEqual(1, textBlock.Inlines.Count);
            var span = (Span)textBlock.Inlines.First();

            Assert.AreEqual(1, span.Inlines.Count);
            var run = (Run)span.Inlines.First();

            Assert.AreEqual("test", run.Text);
        }
        public void GivenTextBlockWithXml_WhenNewTextXmlNull_ThenInlinesCleared()
        {
            // Given
            const string xmlToConvert = "<text>test</text>";
            var          textBlock    = new TextBlock();

            TextBlockExtensions.SetFormattedText(textBlock, xmlToConvert);

            // Precondition
            Assert.AreEqual(1, textBlock.Inlines.Count);
            var span = (Span)textBlock.Inlines.First();

            Assert.AreEqual(1, span.Inlines.Count);
            var run = (Run)span.Inlines.First();

            Assert.AreEqual("test", run.Text);

            // When
            TextBlockExtensions.SetFormattedText(textBlock, null);

            // Then
            CollectionAssert.IsEmpty(textBlock.Inlines);
        }