public async Task Verify_that_WriteXmlAsync_does_not_throw_exception() { var cancellationTokenSource = new CancellationTokenSource(); var datatypeDefinitionDate = new DatatypeDefinitionDate { Identifier = "datatypeDefinitionDate" }; var attributeValueDate = new AttributeValueDate(); attributeValueDate.Definition = new AttributeDefinitionDate { Identifier = "default-identifier" }; var attributeDefinitionDate = new AttributeDefinitionDate { Identifier = "attributeDefinitionDate", Type = datatypeDefinitionDate, DefaultValue = attributeValueDate }; 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); Assert.That(async() => await attributeDefinitionDate.WriteXmlAsync(writer, cancellationTokenSource.Token), Throws.Nothing); }
public void Verify_that_WriteXml_does_not_throw_exception() { var datatypeDefinitionDate = new DatatypeDefinitionDate { Identifier = "datatypeDefinitionDate" }; var attributeValueDate = new AttributeValueDate(); attributeValueDate.Definition = new AttributeDefinitionDate { Identifier = "default-identifier" }; var attributeDefinitionDate = new AttributeDefinitionDate { Identifier = "attributeDefinitionDate", Type = datatypeDefinitionDate, DefaultValue = attributeValueDate }; using var memoryStream = new MemoryStream(); using var writer = XmlWriter.Create(memoryStream, new XmlWriterSettings { Indent = true, ConformanceLevel = ConformanceLevel.Fragment }); writer.WriteStartElement("TEST"); Assert.That(() => attributeDefinitionDate.WriteXml(writer), Throws.Nothing); }
public void Verify_That_Exception_Is_Raised_When_Invalid_AttributeDefinition_Is_Set() { var attributeDefinitionString = new AttributeDefinitionString(); var attributeValueDate = new AttributeValueDate(); var attributeValue = (AttributeValue)attributeValueDate; Assert.Throws <ArgumentException>(() => attributeValue.AttributeDefinition = attributeDefinitionString); }
public void VerifytThatExceptionIsRaisedWhenInvalidAttributeDefinitionIsSet() { var attributeDefinitionString = new AttributeDefinitionString(); var attributeValueDate = new AttributeValueDate(); var attributeValue = (AttributeValue)attributeValueDate; Assert.Throws <ArgumentException>(() => attributeValue.AttributeDefinition = attributeDefinitionString); }
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 attributeValueDate = new AttributeValueDate(); Assert.That(() => attributeValueDate.WriteXml(writer), Throws.Exception.TypeOf <SerializationException>()); }
public void Verify_that_when_ObjectValue_is_not_Date_an_exception_is_thrown() { var attributeValue = new AttributeValueDate(); Assert.That( () => attributeValue.ObjectValue = "true", Throws.Exception.TypeOf <InvalidOperationException>() .With.Message.Contains("Cannot use true as value for this AttributeValueDate.")); }
public void VerifyConvenienceValueProperty() { var attributeValue = new AttributeValueDate(); var date = DateTime.Now; attributeValue.ObjectValue = date; Assert.AreEqual(attributeValue.TheValue, date); }
public void Verify_That_WriteXmlAsync_Without_Definition_Set_Throws_SerializationException() { var cancellationTokenSource = new CancellationTokenSource(); using var memoryStream = new MemoryStream(); using var writer = XmlWriter.Create(memoryStream, new XmlWriterSettings { Indent = true }); var attributeValueDate = new AttributeValueDate(); Assert.That(async() => await attributeValueDate.WriteXmlAsync(writer, cancellationTokenSource.Token), 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 attributeValueDate = new AttributeValueDate(); Assert.Throws <SerializationException>(() => attributeValueDate.WriteXml(writer)); } } }
public void Verify_Convenience_Value_Property() { var attributeValue = new AttributeValueDate(); var date = DateTime.Now; attributeValue.ObjectValue = date; Assert.That(attributeValue.TheValue, Is.EqualTo(date)); date = DateTime.Now; attributeValue.TheValue = date; Assert.That(attributeValue.ObjectValue, Is.EqualTo(date)); }
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_The_AttributeDefinition_Can_Be_Set_Or_Get() { var attributeDefinitionDate = new AttributeDefinitionDate(); var attributeValueDate = new AttributeValueDate(); attributeValueDate.Definition = attributeDefinitionDate; var attributeValue = (AttributeValue)attributeValueDate; Assert.AreEqual(attributeDefinitionDate, attributeValue.AttributeDefinition); attributeValue.AttributeDefinition = attributeDefinitionDate; Assert.AreEqual(attributeDefinitionDate, attributeValue.AttributeDefinition); }
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 attributeValueDate = new AttributeValueDate(); Assert.That(async() => await attributeValueDate.ReadXmlAsync(xmlReader, cts.Token), Throws.Exception.TypeOf <OperationCanceledException>()); }
public void VerifyThatTheAttributeDefinitionCanBeSetOrGet() { var attributeDefinitionDate = new AttributeDefinitionDate(); var attributeValueDate = new AttributeValueDate(); attributeValueDate.Definition = attributeDefinitionDate; var attributeValue = (AttributeValue)attributeValueDate; Assert.AreEqual(attributeDefinitionDate, attributeValue.AttributeDefinition); attributeValue.AttributeDefinition = attributeDefinitionDate; Assert.AreEqual(attributeDefinitionDate, 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 attributeValueDate = new AttributeValueDate { Definition = new AttributeDefinitionDate() }; var cts = new CancellationTokenSource(); cts.Cancel(); Assert.That( async() => await attributeValueDate.WriteXmlAsync(writer, cts.Token), Throws.Exception.TypeOf <OperationCanceledException>()); }