/// <summary> /// Returns the <see cref="Specification"/> representation of a <see cref="RequirementsSpecification"/> /// </summary> /// <param name="requirementsSpecification">The <see cref="RequirementsSpecification"/></param> /// <param name="specificationType">The associated <see cref="SpecificationType"/></param> /// <returns>The <see cref="Specification"/></returns> public Specification ToReqIfSpecification(RequirementsSpecification requirementsSpecification, SpecificationType specificationType) { if (requirementsSpecification == null) { throw new ArgumentNullException("requirementsSpecification"); } var specification = new Specification(); this.SetIdentifiableProperties(specification, requirementsSpecification); specification.Type = specificationType; this.SetCommonAttributeValues(specification, requirementsSpecification); foreach (var parameterValue in requirementsSpecification.ParameterValue) { var attributeDef = specificationType.SpecAttributes.Single(x => x.DatatypeDefinition.Identifier == parameterValue.ParameterType.Iid.ToString()); var value = this.ToReqIfAttributeValue(parameterValue.ParameterType, attributeDef, parameterValue.Value, parameterValue.Scale); specification.Values.Add(value); } // Add extra AttributeValue corresponding to the isDeprecated property var isDeprecatedType = (AttributeDefinitionBoolean)specificationType.SpecAttributes.Single(def => def.DatatypeDefinition == this.BooleanDatatypeDefinition && def.LongName == IsDeprecatedAttributeDefName); var isDeprecated = new AttributeValueBoolean { TheValue = requirementsSpecification.IsDeprecated, Definition = isDeprecatedType }; specification.Values.Add(isDeprecated); return(specification); }
public void Verify_that_WriteXml_does_not_throw_exception() { var datatypeDefinitionBoolean = new DatatypeDefinitionBoolean { Identifier = "datatypeDefinitionBoolean" }; var attributeValueBoolean = new AttributeValueBoolean(); attributeValueBoolean.Definition = new AttributeDefinitionBoolean { Identifier = "default-identifier" }; var attributeDefinitionBoolean = new AttributeDefinitionBoolean { Identifier = "attributeDefinitionBoolean", Type = datatypeDefinitionBoolean, DefaultValue = attributeValueBoolean }; using var memoryStream = new MemoryStream(); using var writer = XmlWriter.Create(memoryStream, new XmlWriterSettings { Indent = true, ConformanceLevel = ConformanceLevel.Fragment }); writer.WriteStartElement("TEST"); Assert.That(() => attributeDefinitionBoolean.WriteXml(writer), Throws.Nothing); }
public async Task Verify_that_WriteXmlAsync_does_not_throw_exception() { var datatypeDefinitionBoolean = new DatatypeDefinitionBoolean { Identifier = "datatypeDefinitionBoolean" }; var attributeValueBoolean = new AttributeValueBoolean(); attributeValueBoolean.Definition = new AttributeDefinitionBoolean { Identifier = "default-identifier" }; var attributeDefinitionBoolean = new AttributeDefinitionBoolean { Identifier = "attributeDefinitionBoolean", Type = datatypeDefinitionBoolean, DefaultValue = attributeValueBoolean }; await using var memoryStream = new MemoryStream(); await using var writer = XmlWriter.Create(memoryStream, new XmlWriterSettings { Indent = true, ConformanceLevel = ConformanceLevel.Fragment, Async = true }); await writer.WriteStartElementAsync(null, "TEST", null); var cancellationTokenSource = new CancellationTokenSource(); Assert.That(async() => await attributeDefinitionBoolean.WriteXmlAsync(writer, cancellationTokenSource.Token), Throws.Nothing); }
public void Verify_That_Exception_Is_Raised_When_Invalid_AttributeDefinition_Is_Set() { var attributeDefinitionString = new AttributeDefinitionString(); var attributeValueBoolean = new AttributeValueBoolean(); var attributeValue = (AttributeValue)attributeValueBoolean; Assert.Throws <ArgumentException>(() => attributeValue.AttributeDefinition = attributeDefinitionString); }
public void VerifyConvenienceValueProperty() { var attributeValueBoolean = new AttributeValueBoolean(); attributeValueBoolean.ObjectValue = true; Assert.IsTrue(attributeValueBoolean.TheValue); }
public void VerifytThatExceptionIsRaisedWhenInvalidAttributeDefinitionIsSet() { var attributeDefinitionString = new AttributeDefinitionString(); var attributeValueBoolean = new AttributeValueBoolean(); var attributeValue = (AttributeValue)attributeValueBoolean; Assert.Throws <ArgumentException>(() => attributeValue.AttributeDefinition = attributeDefinitionString); }
public void Verify_that_when_ObjectValue_is_not_boolean_an_exception_is_thrown() { var attributeValueBoolean = new AttributeValueBoolean(); Assert.That( () => attributeValueBoolean.ObjectValue = "true", Throws.Exception.TypeOf <InvalidOperationException>() .With.Message.Contains("Cannot use true as value for this AttributeValueBoolean.")); }
public void Verify_Convenience_Value_Property() { var attributeValueBoolean = new AttributeValueBoolean(); attributeValueBoolean.ObjectValue = true; Assert.That(attributeValueBoolean.TheValue, Is.True); Assert.That(attributeValueBoolean.ObjectValue, Is.True); }
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 attributeValueReal = new AttributeValueBoolean(); Assert.That( () => attributeValueReal.WriteXml(writer), Throws.Exception.TypeOf <SerializationException>() .With.Message.Contains("The Definition property of an AttributeValueBoolean may not be null")); }
public void VerifyThatWriteXmlWithoutDefinitionSetThrowsSerializationException() { using (var fs = new FileStream("test.xml", FileMode.Create)) { using (var writer = XmlWriter.Create(fs, new XmlWriterSettings { Indent = true })) { var attributeValueReal = new AttributeValueBoolean(); Assert.Throws <SerializationException>(() => attributeValueReal.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 Verify_that_ReadXmlAsync_throws_exception_when_cancelled() { var reqifPath = Path.Combine(TestContext.CurrentContext.TestDirectory, "TestData", "Datatype-Demo.reqif"); var cts = new CancellationTokenSource(); cts.Cancel(); using var fileStream = File.OpenRead(reqifPath); using var xmlReader = XmlReader.Create(fileStream, new XmlReaderSettings { Async = true }); var attributeValueBoolean = new AttributeValueBoolean(); Assert.That(async() => await attributeValueBoolean.ReadXmlAsync(xmlReader, cts.Token), Throws.Exception.TypeOf <OperationCanceledException>()); }
public void Verify_That_The_AttributeDefinition_Can_Be_Set_Or_Get() { var atrAttributeDefinitionBoolean = new AttributeDefinitionBoolean(); var attributeValueBoolean = new AttributeValueBoolean(); attributeValueBoolean.Definition = atrAttributeDefinitionBoolean; var attributeValue = (AttributeValue)attributeValueBoolean; Assert.AreEqual(atrAttributeDefinitionBoolean, attributeValue.AttributeDefinition); attributeValue.AttributeDefinition = atrAttributeDefinitionBoolean; Assert.AreEqual(atrAttributeDefinitionBoolean, attributeValue.AttributeDefinition); }
public void VerifyThatTheAttributeDefinitionCanBeSetOrGet() { var atrAttributeDefinitionBoolean = new AttributeDefinitionBoolean(); var attributeValueBoolean = new AttributeValueBoolean(); attributeValueBoolean.Definition = atrAttributeDefinitionBoolean; var attributeValue = (AttributeValue)attributeValueBoolean; Assert.AreEqual(atrAttributeDefinitionBoolean, attributeValue.AttributeDefinition); attributeValue.AttributeDefinition = atrAttributeDefinitionBoolean; Assert.AreEqual(atrAttributeDefinitionBoolean, attributeValue.AttributeDefinition); }
/// <summary> /// Returns the <see cref="SpecObject"/> representation of a <see cref="Requirement"/> /// </summary> /// <param name="requirement">The <see cref="Requirement"/></param> /// <param name="specObjectType">The associated <see cref="SpecObjectType"/></param> /// <returns>The associated <see cref="SpecObject"/></returns> public SpecObject ToReqIfSpecObject(Requirement requirement, SpecObjectType specObjectType) { if (requirement == null) { throw new ArgumentNullException("requirement"); } var specObject = new SpecObject(); this.SetIdentifiableProperties(specObject, requirement); specObject.Type = specObjectType; this.SetCommonAttributeValues(specObject, requirement); foreach (var parameterValue in requirement.ParameterValue) { var attributeDef = specObjectType.SpecAttributes.Single(x => x.DatatypeDefinition.Identifier == parameterValue.ParameterType.Iid.ToString()); var value = this.ToReqIfAttributeValue(parameterValue.ParameterType, attributeDef, parameterValue.Value, parameterValue.Scale); specObject.Values.Add(value); } // Add extra AttributeValue corresponding to the requirement text if (requirement.Definition.Any()) { var definition = requirement.Definition.First(); var attributeDefinition = (AttributeDefinitionString)specObjectType.SpecAttributes.Single(def => def.DatatypeDefinition == this.TextDatatypeDefinition && def.LongName == RequirementTextAttributeDefName); var requirementValue = new AttributeValueString { TheValue = definition.Content, Definition = attributeDefinition }; specObject.Values.Add(requirementValue); } // Add extra AttributeValue corresponding to the isDeprecated property var isDeprecatedType = (AttributeDefinitionBoolean)specObjectType.SpecAttributes.Single(def => def.DatatypeDefinition == this.BooleanDatatypeDefinition && def.LongName == IsDeprecatedAttributeDefName); var isDeprecated = new AttributeValueBoolean { TheValue = requirement.IsDeprecated, Definition = isDeprecatedType }; specObject.Values.Add(isDeprecated); return(specObject); }
/// <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 attributeValueReal = new AttributeValueBoolean { Definition = new AttributeDefinitionBoolean() }; var cts = new CancellationTokenSource(); cts.Cancel(); Assert.That( async() => await attributeValueReal.WriteXmlAsync(writer, cts.Token), Throws.Exception.TypeOf <OperationCanceledException>()); }
public void VerifyThatGetSchemaReturnsNull() { var attributeValueBoolean = new AttributeValueBoolean(); Assert.IsNull(attributeValueBoolean.GetSchema()); }