public void UpdateCheckRepairTest() { var elementAA = ElementFactory.CreateScalar("name1", null); var elementAB = ElementFactory.CreateScalar("name1", "Test1"); elementAA.Repair(elementAB); var elementSetA = ElementFactory.CreateSet(elementAA, elementAB); var elementBA = ElementFactory.CreateScalar("name1", "Test1"); var elementBB = ElementFactory.CreateScalar("name1", null); elementBA.Repair(elementBB); var elementSetB = ElementFactory.CreateSet(elementBA, elementBB); elementSetB.Add(elementBB); elementSetA.Add(elementAB); elementSetB.Update(elementSetA); elementSetA.Add((IDataElement[])null); elementSetB.Add((IDataElement[])null); elementSetB.Add(ElementFactory.Create("name1", null)); elementSetB.Add(ElementFactory.Create("name3", null)); elementSetB.Add(ElementFactory.Create("name4", null)); elementSetB.Add(ElementFactory.Create("name5", DataValueTypes.Text)); elementSetA.Add(ElementFactory.Create("name1", null)); elementSetA.Add(ElementFactory.Create("name2", null)); elementSetA.Add(ElementFactory.CreateScalar("name4", DataValueTypes.Text, null)); elementSetA.Add(ElementFactory.Create("name5", null)); elementSetB.Repair(elementSetA); elementSetB.Update(elementSetA); }
/// <summary> /// Gets the result of the serialization of the specified object. /// </summary> /// <param name="elementSet">The element set to consider.</param> /// <param name="object1">The object to serialize.</param> /// <typeparam name="T">The data element attribute to consider.</typeparam> /// <returns>The Xml string serializing the specified object.</returns> public static IBdoLog UpdateFromObject <T>( this IDataElementSet elementSet, object object1) where T : DataElementAttribute { var log = new BdoLog(); if (elementSet != null && object1 != null) { foreach (PropertyInfo propertyInfo in object1.GetType().GetProperties()) { if (propertyInfo.GetCustomAttribute(typeof(DetailPropertyAttribute)) is DetailPropertyAttribute attribute) { string name = attribute.Name; if (string.IsNullOrEmpty(name)) { name = propertyInfo.Name; } elementSet.Add( ElementFactory.Create( name, propertyInfo.PropertyType.GetValueType(), propertyInfo.GetValue(object1))); } } } return(log); }
private List <IArea> GetAreas(List <ObjectId> ids) { var areas = new List <IArea>(); using (var t = db.TransactionManager.StartTransaction()) { foreach (var idEnt in ids) { if (!idEnt.ObjectClass.IsDerivedFrom(RXClassCurve) && idEnt.ObjectClass != RXClassHatch) { continue; } var ent = idEnt.GetObject(OpenMode.ForRead) as Entity; var area = ElementFactory.Create <IArea>(ent); if (area != null) { areas.Add(area); } } t.Commit(); } return(areas); }
void ParseHtmlDocument(string htmlFragment) { using (Stream s = new MemoryStream(Encoding.UTF8.GetBytes(htmlFragment.ToCharArray()))) { var domdoc = ElementFactory.Create(s, Encoding.UTF8, CsQuery.HtmlParsingMode.Document, CsQuery.HtmlParsingOptions.Default, CsQuery.DocType.HTML5); foreach (var childNode in domdoc.ChildNodes) { var testInnerText = childNode.InnerText; } this.treeView1.Nodes.Clear(); var treeNode = new TreeNode("root"); treeView1.Nodes.Add(treeNode); if (domdoc.HasChildren) { foreach (var child in domdoc.ChildNodes) { DescribeDomNode(child, treeNode); } } this.treeView1.ExpandAll(); } }
public void ShouldCreateElement(Type type) { var created = ElementFactory.Create(type, _mockLocator); Expect(created, Is.Not.Null); Expect(created, Is.AssignableTo(type)); }
public void CopyAllChildrenFromTheOriginalIFrameElementToTheAmpElement_Always() { // Arrange const int ExpectedResult = 2; var htmlElement = ElementFactory.CreateIFrame(); var firstChild = ElementFactory.Create("input"); var secondChild = ElementFactory.Create("p"); htmlElement.Append(firstChild); htmlElement.Append(secondChild); ElementFactory.Document.Body.Append(htmlElement); var runContext = new RunContext(new RunConfiguration { RelativeUrlsHost = "http://test-domain.com" }); var iframeSanitizer = new IFrameSanitizer(); iframeSanitizer.Configure(runContext); // Act var actualResult = iframeSanitizer.Sanitize(ElementFactory.Document, htmlElement); // Assert Assert.AreEqual(ExpectedResult, actualResult.Children.Length); }
private static ElementMetadata AssembleElementMetatata( ElementMetadata parentMetadata, ElementFactory elementChild, HashSet <Type> visitedTypes, ICollection <ElementMetadata> elementMetadataCollection, IDictionary <OpenXmlQualifiedName, FieldInfo> fieldInfos) { OpenXmlElement element = elementChild.Create(); var elementMetadata = element.Metadata; elementMetadataCollection.Add(elementMetadata); if (!fieldInfos.TryGetValue(elementMetadata.QName, out FieldInfo? fieldInfo)) { fieldInfo = new FieldInfo(elementMetadata.QName); fieldInfos[elementMetadata.QName] = fieldInfo; } fieldInfo.AddParentElementMetadata(parentMetadata); fieldInfo.AddElementMetadata(elementMetadata); if (visitedTypes.Add(element.GetType())) { foreach (var child in elementMetadata.Children.Elements) { fieldInfo.AddChildElementMetadata( AssembleElementMetatata(elementMetadata, child, visitedTypes, elementMetadataCollection, fieldInfos)); } } return(elementMetadata); }
public IEnumerable <Element> GenerateElements(int divisions, SpawnRate spawnRate, ElementFactory elementFactory) { var random = new Random(); return(ElementsToSpawn(divisions, spawnRate) .ConvertAll(scaleBox => elementFactory.Create(scaleBox))); }
public void ThowArgumentNullException_WhenElementArgumentIsNull() { // Arrange var ampElement = ElementFactory.Create("amp-iframe"); // Assert Ensure.ArgumentExceptionIsThrown(() => new MediaSanitizerAccessor().SetMediaElementLayout(null, ampElement), "element"); }
/// <summary> /// Returns a data element representing this instance. /// </summary> /// <param name="name">The name of the element to create.</param> /// <param name="log">The log of the operation.</param> /// <returns>Retuns the data element that represents this instace.</returns> public override IDataElement AsElement(string name = null) { var element = ElementFactory.Create(name); element.ItemScript = ToString(); return(element); }
/// <summary> /// Creates a new DomDocument (or derived) object. /// </summary> /// /// <param name="html"> /// The HTML source for the document. /// </param> /// <param name="encoding"> /// (optional) the character set encoding. /// </param> /// <param name="parsingMode"> /// (optional) the HTML parsing mode. /// </param> /// <param name="parsingOptions"> /// (optional) options for controlling the parsing. /// </param> /// <param name="docType"> /// The DocType for this document. /// </param> /// /// <returns> /// A new IDomDocument object. /// </returns> public static IDomDocument Create(Stream html, Encoding encoding = null, HtmlParsingMode parsingMode = HtmlParsingMode.Content, HtmlParsingOptions parsingOptions = HtmlParsingOptions.Default, DocType docType = DocType.Default) { return(ElementFactory.Create(html, encoding, parsingMode, parsingOptions, docType)); }
public void CreatePartDefinition2_NullAsType_ShouldThrowArgumentNull() { var origin = ElementFactory.Create(); Assert.Throws <ArgumentNullException>("type", () => { AttributedModelServices.CreatePartDefinition((Type)null, origin, false); }); }
public static List <BlockSectionGP> Parse(List <ObjectId> ids, out List <IArea> classes, Editor ed) { var classService = new ClassTypeService(); classes = new List <IArea>(); var sections = new List <BlockSectionGP>(); var filteredBlocks = new List <string>(); foreach (var idEnt in ids) { var ent = idEnt.GetObject(OpenMode.ForRead) as Entity; if (ent is BlockReference) { var section = ElementFactory.Create <BlockSectionGP>(ent); if (section != null) { if (section.Error == null) { sections.Add(section); } else { Inspector.AddError(section.Error); } } else { filteredBlocks.Add(((BlockReference)ent).GetEffectiveName()); } } else if (ent is Curve || ent is Hatch) { var area = ElementFactory.Create <IArea>(ent, classService); if (area != null) { classes.Add(area); } } } if (filteredBlocks.Count > 0) { ed.WriteMessage("\nОтфильтрованные блоки:"); var groupsFilteredBlock = filteredBlocks.GroupBy(g => g); foreach (var item in groupsFilteredBlock) { ed.WriteMessage($"\n{item.Key} - {item.Count()} шт."); } } ed.WriteMessage($"\nОпределено блоков блок-секций ГП - {sections.Count}"); return(sections); }
public void FormICompositionElement_ValueWithNullOriginAsElementArgument_ShouldSetOriginPropertyToNull() { var element = ElementFactory.Create((ICompositionElement)null); Assert.IsNull(element.Origin); var result = SerializableCompositionElement.FromICompositionElement(element); Assert.IsNull(element.Origin); }
public void Constructor5_ValueAsIdArgument_ShouldSetICompositionErrorIdProperty() { var expectations = Expectations.GetEnumValues <CompositionErrorId>(); Assert.All(expectations, e => { var error = new CompositionError(e, "Description", ElementFactory.Create(), new Exception()); Assert.Equal(e, error.Id); }); }
public void Constructor4_ValueAsExceptionArgument_ShouldSetInnerExceptionProperty() { var expectations = Expectations.GetInnerExceptions(); Assert.All(expectations, e => { var error = new CompositionError("Description", ElementFactory.Create(), e); Assert.Same(e, error.InnerException); }); }
public void Constructor4_ValueAsMessageArgument_ShouldSetMessageProperty() { var expectations = Expectations.GetExceptionMessages(); Assert.All(expectations, e => { var exception = new CompositionError(e, ElementFactory.Create(), new Exception()); Assert.Equal(e, exception.Description); }); }
public void FromICompositionElement_ValueWithNullDisplayNameAsElementArgument_ShouldSetDisplayNamePropertyToEmptyString() { var element = ElementFactory.Create((string)null); Assert.IsNull(element.DisplayName); var result = SerializableCompositionElement.FromICompositionElement(element); Assert.AreEqual(string.Empty, result.DisplayName); }
public IEnumerator <THtmlElement> GetEnumerator() { InitCollection(); for (var i = 0; i < _nativeElements.Length; i++) { var htmlElement = ElementFactory.Create <THtmlElement>(this, Locator, i); htmlElement.SetNativeElement(_nativeElements[i]); yield return(htmlElement); } }
public void Constructor3_ValueAsMessageArgument_ShouldSetMessageProperty() { var expectations = Expectations.GetExceptionMessages(); foreach (var e in expectations) { var exception = new ComposablePartException(e, ElementFactory.Create()); Assert.Equal(e, exception.Message); } }
public void Constructor9_ValueAsInnerExceptionArgument_ShouldSetInnerExceptionProperty() { var expectations = Expectations.GetInnerExceptions(); foreach (var e in expectations) { var exception = new ComposablePartException("Message", ElementFactory.Create(), e); Assert.Same(e, exception.InnerException); } }
public void Constructor4_ValueAsExceptionArgument_ShouldSetInnerExceptionProperty() { var expectations = Expectations.GetInnerExceptions(); foreach (var e in expectations) { var error = new CompositionError("Description", ElementFactory.Create(), e); Assert.AreSame(e, ((ICompositionError)error).InnerException); } }
public void Constructor5_ValueAsIdArgument_ShouldSetICompositionErrorIdProperty() { var expectations = Expectations.GetEnumValues <CompositionErrorId>(); foreach (var e in expectations) { var error = new CompositionError(e, "Description", ElementFactory.Create(), new Exception()); Assert.AreEqual(e, ((ICompositionError)error).Id); } }
public void ReturnFalse_WhenElementHasNotStyleAttribute() { // Arange var element = ElementFactory.Create("div"); // Act var actualResult = new StyleAttributeSanitizer().CanSanitize(element); // Assert Assert.IsFalse(actualResult); }
public void Constructor2_ValueAsMessageArgument_ShouldSetMessageProperty() { var expectations = Expectations.GetExceptionMessages(); foreach (var e in expectations) { var exception = new CompositionError(e, ElementFactory.Create()); Assert.AreEqual(e, exception.Description); } }
public void ReturnFalse_WhenElementArgumentIsNotIFrameElement() { // Arrange var htmlElement = ElementFactory.Create("div"); // Act var actualResult = new IFrameSanitizer().CanSanitize(htmlElement); // Assert Assert.IsFalse(actualResult); }
/// <summary> /// Creates a new DomDocument (or derived) object /// </summary> /// /// <param name="html"> /// The HTML source for the document /// </param> /// <param name="parsingMode"> /// (optional) the parsing mode. /// </param> /// <param name="parsingOptions"> /// (optional) options for controlling the parsing. /// </param> /// <param name="docType"> /// The DocType for this document. /// </param> /// /// <returns> /// A new IDomDocument object /// </returns> public static IDomDocument Create(string html, HtmlParsingMode parsingMode = HtmlParsingMode.Auto, HtmlParsingOptions parsingOptions = HtmlParsingOptions.Default, DocType docType = DocType.Default) { var encoding = Encoding.UTF8; using (var stream = new MemoryStream(encoding.GetBytes(html))) { return(ElementFactory.Create(stream, encoding, parsingMode, parsingOptions, docType)); } }
public Element GetActiveElement(int rowId, string columnId) { foreach (var xpath in XpathProvider.ActiveInCell) { var elements = Driver.FindElements(By.XPath(xpath(Prefix, rowId, Header[columnId]))); if (elements.One()) { return(ElementFactory.Create(Driver, elements.First())); } } throw new Exception("no active element found in cell"); }
public void ReturnTrue_WhenElementHasStyleAttribute() { // Arange var element = ElementFactory.Create("div"); element.SetAttribute("style", "color: red;"); // Act var actualResult = new StyleAttributeSanitizer().CanSanitize(element); // Assert Assert.IsTrue(actualResult); }
public void RemoveStyleAttribute() { // Arange var element = ElementFactory.Create("div"); element.SetAttribute("style", "color: red;"); // Act var actualResult = new StyleAttributeSanitizer().Sanitize(ElementFactory.Document, element); // Assert Assert.IsFalse(actualResult.HasAttribute("style")); }