1- // Copyright (C) 2003-2010 Xtensive LLC.
2- // All rights reserved .
3- // For conditions of distribution and use, see license .
1+ // Copyright (C) 2013-2022 Xtensive LLC.
2+ // This code is distributed under MIT license terms .
3+ // See the License.txt file in the project root for more information .
44// Created by: Alena Mikshina
55// Created: 2013.10.04
66
77using System ;
8- using System . Collections . Generic ;
98using System . Diagnostics ;
109using System . IO ;
1110using System . Xml ;
@@ -18,39 +17,41 @@ namespace Xtensive.Orm.Tests.Configuration
1817 [ TestFixture ]
1918 public class SchemaTest
2019 {
21- private const string originalConfigFileName = "Xtensive.Orm.Tests.dll.config" ;
22- private const string xsdFileName = "Xtensive.Orm.xsd" ;
23- private const string xsdInLowerCaseFileName = "Test.xsd" ;
24- private const string configFileName = "Test.config" ;
25- private const string originalRootElementName = "AppConfigTest" ;
26- private const string rootElementName = "Xtensive.Orm" ;
27- private const string configXmlNamespace = "http://dataobjects.net/schemas/appconfig/" ;
20+ private const string OriginalConfigFileName = "Xtensive.Orm.Tests.dll.config" ;
21+ private const string XsdFileName = "Xtensive.Orm.xsd" ;
22+ private const string XsdInLowerCaseFileName = "Test.xsd" ;
23+ private const string ConfigFileName = "Test.config" ;
24+ private const string OriginalRootElementName = "AppConfigTest" ;
25+ private const string RootElementName = "Xtensive.Orm" ;
26+ private const string ConfigXmlNamespace = "http://dataobjects.net/schemas/appconfig/" ;
2827 private bool hasErrors ;
2928
3029 [ Test ]
3130 public void TestSchema ( )
3231 {
3332 hasErrors = false ;
3433
35- XElement segmentConfig = XElement . Load ( originalConfigFileName ) . Element ( originalRootElementName ) ;
36- Debug . Assert ( segmentConfig != null , "segmentConfig != null" ) ;
37- segmentConfig . Name = rootElementName ;
34+ var segmentConfig = XElement . Load ( OriginalConfigFileName ) . Element ( OriginalRootElementName ) ;
35+ Debug . Assert ( segmentConfig != null , "segmentConfig != null" ) ;
36+ segmentConfig . Name = RootElementName ;
3837
39- foreach ( XElement element in segmentConfig . DescendantsAndSelf ( ) )
40- element . Name = ( XNamespace ) configXmlNamespace + element . Name . LocalName ;
38+ foreach ( var element in segmentConfig . DescendantsAndSelf ( ) ) {
39+ element . Name = ( XNamespace ) ConfigXmlNamespace + element . Name . LocalName ;
40+ }
4141
42- using ( StreamWriter segmentConfigWriter = File . CreateText ( configFileName ) )
42+ using ( var segmentConfigWriter = File . CreateText ( ConfigFileName ) ) {
4343 segmentConfigWriter . Write ( segmentConfig . ToString ( ) . ToLower ( ) ) ;
44+ }
4445
4546 ChangeXsdElementsToLowerCase ( ) ;
4647
4748 try {
48- XmlReaderSettings schemaSettings = new XmlReaderSettings ( ) ;
49- schemaSettings . Schemas . Add ( configXmlNamespace , xsdInLowerCaseFileName ) ;
49+ var schemaSettings = new XmlReaderSettings ( ) ;
50+ _ = schemaSettings . Schemas . Add ( ConfigXmlNamespace , XsdInLowerCaseFileName ) ;
5051 schemaSettings . ValidationType = ValidationType . Schema ;
5152 schemaSettings . ValidationEventHandler += new ValidationEventHandler ( ValidationHandler ) ;
5253
53- XmlReader configReader = XmlReader . Create ( configFileName , schemaSettings ) ;
54+ var configReader = XmlReader . Create ( ConfigFileName , schemaSettings ) ;
5455 while ( configReader . Read ( ) ) {
5556 }
5657 configReader . Close ( ) ;
@@ -61,12 +62,6 @@ public void TestSchema()
6162 Console . WriteLine ( "LineNumber = {0}" , exception . LineNumber ) ;
6263 Console . WriteLine ( "LinePosition = {0}" , exception . LinePosition ) ;
6364 }
64- catch ( XmlSchemaValidationException exception ) {
65- hasErrors = true ;
66- Console . WriteLine ( "{0}: {1}" , exception . GetType ( ) , exception . Message ) ;
67- Console . WriteLine ( "LineNumber = {0}" , exception . LineNumber ) ;
68- Console . WriteLine ( "LinePosition = {0}" , exception . LinePosition ) ;
69- }
7065 catch ( XmlSchemaException exception ) {
7166 hasErrors = true ;
7267 Console . WriteLine ( "{0}: {1}" , exception . GetType ( ) , exception . Message ) ;
@@ -86,33 +81,39 @@ public void TestSchema()
8681 Console . WriteLine ( "{0}: {1}" , exception . GetType ( ) , exception . Message ) ;
8782 }
8883 finally {
89- File . Delete ( configFileName ) ;
90- File . Delete ( xsdInLowerCaseFileName ) ;
84+ File . Delete ( ConfigFileName ) ;
85+ File . Delete ( XsdInLowerCaseFileName ) ;
9186 }
9287
9388 Assert . IsFalse ( hasErrors ) ;
9489 }
9590
96- public void ValidationHandler ( object sender , ValidationEventArgs exception )
91+ public void ValidationHandler ( object sender , ValidationEventArgs validationEventArgs )
9792 {
9893 hasErrors = true ;
99- Console . WriteLine ( "({0}) {1}: {2}" , exception . Severity , exception . GetType ( ) , exception . Message ) ;
94+ var exception = validationEventArgs . Exception ;
95+ Console . WriteLine ( $ "({ validationEventArgs . Severity } ) { exception . GetType ( ) } : { validationEventArgs . Message } ") ;
96+ Console . WriteLine ( $ "LineNumber = { exception . LineNumber } ") ;
97+ Console . WriteLine ( $ "LinePosition = { exception . LinePosition } ") ;
10098 }
10199
102100 private static void ChangeXsdElementsToLowerCase ( )
103101 {
104- var elementsUsedInXsd = new List < string > { "element" , "complexType" , "attribute" , "simpleType" , "restriction" , "enumeration" , "pattern" } ;
102+ var elementsUsedInXsd = new string [ ] { "element" , "complexType" , "attribute" , "simpleType" , "restriction" , "enumeration" , "pattern" } ;
105103
106- XNamespace namespaceXsd = XNamespace . Get ( "http://www.w3.org/2001/XMLSchema" ) ;
107- XElement xsdWithElementsToLowerCase = XElement . Load ( xsdFileName ) ;
104+ var namespaceXsd = XNamespace . Get ( "http://www.w3.org/2001/XMLSchema" ) ;
105+ var xsdWithElementsToLowerCase = XElement . Load ( XsdFileName ) ;
108106
109- foreach ( var element in elementsUsedInXsd )
110- foreach ( var attributes in xsdWithElementsToLowerCase . Descendants ( namespaceXsd + element ) )
111- foreach ( var attribute in attributes . Attributes ( ) )
107+ foreach ( var element in elementsUsedInXsd ) {
108+ foreach ( var attributes in xsdWithElementsToLowerCase . Descendants ( namespaceXsd + element ) ) {
109+ foreach ( var attribute in attributes . Attributes ( ) ) {
112110 attribute . Value = attribute . Value . ToLower ( ) ;
111+ }
112+ }
113+ }
113114
114- using ( StreamWriter xElementXsdWriter = File . CreateText ( xsdInLowerCaseFileName ) )
115- xElementXsdWriter . Write ( xsdWithElementsToLowerCase ) ;
115+ using var xElementXsdWriter = File . CreateText ( XsdInLowerCaseFileName ) ;
116+ xElementXsdWriter . Write ( xsdWithElementsToLowerCase ) ;
116117 }
117118 }
118119}
0 commit comments