public void ShouldBuildInlines() { // Given dynamic inline1 = new DynamicWrapper(); inline1.Run = new DynamicWrapper(); inline1.Run.Text = "Inline1"; dynamic inline2 = new DynamicWrapper(); inline2.Run = new DynamicWrapper(); inline2.Run.Text = "Inline2"; dynamic elementMetadata = new DynamicWrapper(); elementMetadata.Inlines = new[] { inline1, inline2 }; // When PrintElementBold element = BuildTestHelper.BuildBold(elementMetadata); // Then Assert.IsNotNull(element); Assert.IsNotNull(element.Inlines); Assert.AreEqual(2, element.Inlines.Count); Assert.IsInstanceOf <PrintElementRun>(element.Inlines.First()); Assert.IsInstanceOf <PrintElementRun>(element.Inlines.Last()); Assert.AreEqual("Inline1", ((PrintElementRun)element.Inlines.First()).Text); Assert.AreEqual("Inline2", ((PrintElementRun)element.Inlines.Last()).Text); }
public object Create(PrintElementBuildContext buildContext, dynamic elementMetadata) { var element = new PrintElementBold(); BuildHelper.ApplyTextProperties(element, buildContext.ElementStyle); BuildHelper.ApplyTextProperties(element, elementMetadata); BuildHelper.ApplyInlineProperties(element, buildContext.ElementStyle); BuildHelper.ApplyInlineProperties(element, elementMetadata); // Генерация содержимого элемента var inlines = buildContext.ElementBuilder.BuildElements(buildContext, elementMetadata.Inlines); if (inlines != null) { foreach (var inline in inlines) { element.Inlines.Add(inline); } } BuildHelper.PostApplyTextProperties(element, buildContext.ElementStyle); BuildHelper.PostApplyTextProperties(element, elementMetadata); return(element); }
public void ShouldBuildBold() { //Given var context = HtmlBuilderTestHelper.CreateHtmlBuilderContext(); var element = new PrintElementBold(); var result = new TextWriterWrapper(); var run = new PrintElementRun { Text = "Bold Text." }; //When element.Inlines.Add(run); context.Build(element, result.Writer); //Then Assert.AreEqual(Resources.ResultTestShouldBuildBold, result.GetText()); }