コード例 #1
0
        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);
        }
コード例 #2
0
        public void Verify_That_WriteXmlAsync_Throws_Exception_When_Type_Is_Null()
        {
            var cancellationTokenSource = new CancellationTokenSource();

            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(async() => await attributeDefinitionDate.WriteXmlAsync(writer, cancellationTokenSource.Token),
                        Throws.Exception.TypeOf <SerializationException>()
                        .With.Message.Contains("The Type property of AttributeDefinitionDate identifier:longname may not be null"));
        }