public void VerifytThatExceptionIsRaisedWhenInvalidAttributeDefinitionIsSet() { var attributeDefinitionString = new AttributeDefinitionReal(); var attributeValueXhtml = new AttributeValueXHTML(); var attributeValue = (AttributeValue)attributeValueXhtml; Assert.Throws <ArgumentException>(() => attributeValue.AttributeDefinition = attributeDefinitionString); }
public void Verify_That_Exception_Is_Raised_When_Invalid_AttributeDefinition_Is_Set() { var attributeDefinitionString = new AttributeDefinitionReal(); var attributeValueXhtml = new AttributeValueXHTML(); var attributeValue = (AttributeValue)attributeValueXhtml; Assert.Throws <ArgumentException>(() => attributeValue.AttributeDefinition = attributeDefinitionString); }
public void VerifyConvenienceValueProperty() { var attributeValue = new AttributeValueXHTML(); var val = "testetestes"; attributeValue.ObjectValue = val; Assert.AreEqual(attributeValue.TheValue, val); }
public void Verify_That_WriteXml_Without_Definition_Set_Throws_SerializationException() { using var memoryStream = new MemoryStream(); using var writer = XmlWriter.Create(memoryStream, new XmlWriterSettings { Indent = true }); var attributeValueXhtml = new AttributeValueXHTML(); Assert.That(() => attributeValueXhtml.WriteXml(writer), Throws.Exception.TypeOf <SerializationException>()); }
public void VerifyThatWriteXmlWithoutDefinitionSetThrowsSerializationException() { using (var fs = new FileStream("test.xml", FileMode.Create)) { using (var writer = XmlWriter.Create(fs, new XmlWriterSettings { Indent = true })) { var attributeValueXhtml = new AttributeValueXHTML(); Assert.Throws <SerializationException>(() => attributeValueXhtml.WriteXml(writer)); } } }
private void AddAttributeButton_Click(object sender, RoutedEventArgs e) { var dataGridRowIndex = ((sender as Button).BindingGroup.Owner as DataGridRow).GetIndex(); AttributeDefinition selectedAttribute = _attributes[dataGridRowIndex].AttributeDefinition; AttributeValue attributeValue = null; if (selectedAttribute.GetType() == typeof(AttributeDefinitionBoolean)) { attributeValue = new AttributeValueBoolean(); attributeValue.ObjectValue = false; } else if (selectedAttribute.GetType() == typeof(AttributeDefinitionDate)) { attributeValue = new AttributeValueDate(); attributeValue.ObjectValue = DateTime.Now; } else if (selectedAttribute.GetType() == typeof(AttributeDefinitionEnumeration)) { attributeValue = new AttributeValueEnumeration(); List <EnumValue> enumValues = new List <EnumValue>(); enumValues.Add(((DatatypeDefinitionEnumeration)selectedAttribute.DatatypeDefinition).SpecifiedValues.First()); attributeValue.ObjectValue = enumValues; } else if (selectedAttribute.GetType() == typeof(AttributeDefinitionInteger)) { attributeValue = new AttributeValueInteger(); attributeValue.ObjectValue = ""; } else if (selectedAttribute.GetType() == typeof(AttributeDefinitionReal)) { attributeValue = new AttributeValueReal(); attributeValue.ObjectValue = ""; } else if (selectedAttribute.GetType() == typeof(AttributeDefinitionString)) { attributeValue = new AttributeValueString(); attributeValue.ObjectValue = ""; } else if (selectedAttribute.GetType() == typeof(AttributeDefinitionXHTML)) { attributeValue = new AttributeValueXHTML(); attributeValue.ObjectValue = "<div></div>"; } attributeValue.AttributeDefinition = selectedAttribute; attributeValue.SpecElAt = (Application.Current.MainWindow as MainWindow).content.SpecObjects.SingleOrDefault(x => x.Identifier == _specObject.Identifier); _attributes[dataGridRowIndex].AttributeValue = attributeValue; _attributes[dataGridRowIndex].added = true; }
public void VerifyThatTheAttributeDefinitionCanBeSetOrGet() { var attributeDefinitionXhtml = new AttributeDefinitionXHTML(); var attributeValueXhtml = new AttributeValueXHTML(); attributeValueXhtml.Definition = attributeDefinitionXhtml; var attributeValue = (AttributeValue)attributeValueXhtml; Assert.AreEqual(attributeDefinitionXhtml, attributeValue.AttributeDefinition); attributeValue.AttributeDefinition = attributeDefinitionXhtml; Assert.AreEqual(attributeDefinitionXhtml, attributeValue.AttributeDefinition); }
public void Verify_That_The_AttributeDefinition_Can_Be_Set_Or_Get() { var attributeDefinitionXhtml = new AttributeDefinitionXHTML(); var attributeValueXhtml = new AttributeValueXHTML(); attributeValueXhtml.Definition = attributeDefinitionXhtml; var attributeValue = (AttributeValue)attributeValueXhtml; Assert.AreEqual(attributeDefinitionXhtml, attributeValue.AttributeDefinition); attributeValue.AttributeDefinition = attributeDefinitionXhtml; Assert.AreEqual(attributeDefinitionXhtml, attributeValue.AttributeDefinition); }
/// <summary> /// Create <see cref="AttributeValue"/> For <see cref="SpecElementWithAttributes"/> /// </summary> /// <param name="specElementWithAttributes"> /// The <see cref="SpecElementWithAttributes"/> to which <see cref="AttributeValue"/>s need to be added. /// </param> /// <param name="specType"> /// The <see cref="SpecType"/> of the <see cref="specElementWithAttributes"/> /// </param> private void CreateValuesForSpecElementWithAttributes(SpecElementWithAttributes specElementWithAttributes, SpecType specType) { var attributeValueBoolean = new AttributeValueBoolean(); attributeValueBoolean.Definition = (AttributeDefinitionBoolean)specType.SpecAttributes.SingleOrDefault(x => x.GetType() == typeof(AttributeDefinitionBoolean)); attributeValueBoolean.TheValue = true; specElementWithAttributes.Values.Add(attributeValueBoolean); var attributeValueDate = new AttributeValueDate(); attributeValueDate.Definition = (AttributeDefinitionDate)specType.SpecAttributes.SingleOrDefault(x => x.GetType() == typeof(AttributeDefinitionDate)); attributeValueDate.TheValue = XmlConvert.ToDateTime("2015-12-01", XmlDateTimeSerializationMode.Utc); specElementWithAttributes.Values.Add(attributeValueDate); var attributeValueEnumeration = new AttributeValueEnumeration(); attributeValueEnumeration.Definition = (AttributeDefinitionEnumeration)specType.SpecAttributes.SingleOrDefault(x => x.GetType() == typeof(AttributeDefinitionEnumeration)); var enumValue = attributeValueEnumeration.Definition.Type.SpecifiedValues.FirstOrDefault(); attributeValueEnumeration.Values.Add(enumValue); specElementWithAttributes.Values.Add(attributeValueEnumeration); var attributeValueInteger = new AttributeValueInteger(); attributeValueInteger.Definition = (AttributeDefinitionInteger)specType.SpecAttributes.SingleOrDefault(x => x.GetType() == typeof(AttributeDefinitionInteger)); attributeValueInteger.TheValue = 1; specElementWithAttributes.Values.Add(attributeValueInteger); var attributeValueReal = new AttributeValueReal(); attributeValueReal.Definition = (AttributeDefinitionReal)specType.SpecAttributes.SingleOrDefault(x => x.GetType() == typeof(AttributeDefinitionReal)); attributeValueReal.TheValue = 100; specElementWithAttributes.Values.Add(attributeValueReal); var attributeValueString = new AttributeValueString(); attributeValueString.Definition = (AttributeDefinitionString)specType.SpecAttributes.SingleOrDefault(x => x.GetType() == typeof(AttributeDefinitionString)); attributeValueString.TheValue = "a string value"; specElementWithAttributes.Values.Add(attributeValueString); var attributeValueXhtml = new AttributeValueXHTML(); attributeValueXhtml.Definition = (AttributeDefinitionXHTML)specType.SpecAttributes.SingleOrDefault(x => x.GetType() == typeof(AttributeDefinitionXHTML)); attributeValueXhtml.TheValue = this.xhtmlcontent; specElementWithAttributes.Values.Add(attributeValueXhtml); }
public void Verify_That_WriteXmlAsync_Throws_Exception_when_cancelled() { using var memoryStream = new MemoryStream(); using var writer = XmlWriter.Create(memoryStream, new XmlWriterSettings { Indent = true }); var attributeValueXhtml = new AttributeValueXHTML { Definition = new AttributeDefinitionXHTML() }; var cts = new CancellationTokenSource(); cts.Cancel(); Assert.That( async() => await attributeValueXhtml.WriteXmlAsync(writer, cts.Token), Throws.Exception.TypeOf <OperationCanceledException>()); }
public void Verify_that_raw_text_can_be_extracted_from_xtml_value() { var attributeValue = new AttributeValueXHTML(); attributeValue.TheValue = null; Assert.That(attributeValue.ExtractUnformattedTextFromValue(), Is.Empty); attributeValue.TheValue = ""; Assert.That(attributeValue.ExtractUnformattedTextFromValue(), Is.Empty); var val = "<xhtml:div>Description of the SpecObject that includes formatted tables and/or style:<xhtml:ul class=\"noindent\"><xhtml:li>Element 1</xhtml:li><xhtml:li>Element 2</xhtml:li></xhtml:ul></xhtml:div>"; attributeValue.ObjectValue = val; var unformattedText = attributeValue.ExtractUnformattedTextFromValue(); Assert.That(unformattedText, Is.EqualTo("Description of the SpecObject that includes formatted tables and/or style: Element 1 Element 2")); }
/// <summary> /// Change ReqIF value of the specObject and the attribute value. The Attribute must be part of the ReqIF file. /// </summary> /// <param name="specObject"></param> /// <param name="name"></param> /// <param name="eaValue"></param> /// <param name="caseSensitive"></param> /// <returns></returns> private bool RoundtripChangeValueReqIf(SpecObject specObject, string name, string eaValue, bool caseSensitive = false) { try { AttributeValue attrValueObject = caseSensitive ? specObject.Values.SingleOrDefault(x => x.AttributeDefinition.LongName == name) : specObject.Values.SingleOrDefault(x => x.AttributeDefinition.LongName.ToLower() == name.ToLower()); // Attribute not part of ReqIF, skip if (attrValueObject == null) { // Create AttributValue and assign them to values. AttributeDefinition attributeType = _moduleAttributeDefinitions.SingleOrDefault(x => x.LongName.ToLower() == name.ToLower()); switch (attributeType) { case AttributeDefinitionString _: attrValueObject = new AttributeValueString { AttributeDefinition = attributeType }; break; case AttributeDefinitionXHTML _: attrValueObject = new AttributeValueXHTML { AttributeDefinition = attributeType }; break; case AttributeDefinitionEnumeration moduleAttributDefinitionEnumeration: attrValueObject = new AttributeValueEnumeration { AttributeDefinition = attributeType }; break; } if (attrValueObject == null) { return(true); // not supported datatype } specObject.Values.Add(attrValueObject); } var attrType = attrValueObject.AttributeDefinition; //specObj.Values[0].AttributeDefinition.LongName; switch (attrType) { case AttributeDefinitionXHTML _: // make xhtml and handle new line var xhtmlcontent = MakeXhtmlFromString(eaValue); attrValueObject.ObjectValue = xhtmlcontent; break; case AttributeDefinitionString _: attrValueObject.ObjectValue = eaValue; break; case AttributeDefinitionEnumeration _: try { // take all the valid enums if (!SetReqIfEnumValue((AttributeValueEnumeration)attrValueObject, eaValue)) { return(false); } } catch (Exception e) { MessageBox.Show($@"Name: '{name}' Value: '{eaValue}' {e}", $@"Error enumeration value TV '{name}'."); } break; } return(true); } catch (Exception e) { MessageBox.Show($@"Name: '{name}' Value: '{eaValue}' {e}", $@"Error value TV '{name}'."); return(false); } }