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_WriteXml_Throws_Exception_When_Type_Is_Null() { using var memoryStream = new MemoryStream(); using var writer = XmlWriter.Create(memoryStream, new XmlWriterSettings { Indent = true }); var attributeDefinitionDate = new AttributeDefinitionDate() { Identifier = "identifier", LongName = "longname" }; Assert.That(() => attributeDefinitionDate.WriteXml(writer), Throws.Exception.TypeOf <SerializationException>() .With.Message.Contains("The Type property of AttributeDefinitionDate identifier:longname may not be null")); Assert.Throws <SerializationException>(() => attributeDefinitionDate.WriteXml(writer)); }
public void VerifyThatWriteXmlThrowsExceptionWhenTypeIsNull() { using (var fs = new FileStream("test.xml", FileMode.Create)) { using (var writer = XmlWriter.Create(fs, new XmlWriterSettings { Indent = true })) { var attributeDefinitionDate = new AttributeDefinitionDate(); Assert.Throws <SerializationException>(() => attributeDefinitionDate.WriteXml(writer)); } } }