private static string GetLineInfo(XmlReader reader) { var lineInfo = reader as IXmlLineInfo; return(lineInfo == null ? string.Empty : Resources.FormatMsg_LineInfo(lineInfo.LineNumber, lineInfo.LinePosition)); }
public void CommitOperationThrowsExceptionWhenFindInvalidModificationAfterLoadOperation() { var xml = @"<?xml version=""1.0"" encoding=""UTF-8""?> <?xml-stylesheet type=""text/xsl"" href=""style1.xsl""?> <settings> <?xml-stylesheet type=""text/xsl"" href=""style2.xsl""?> <Data> <DefaultConnection> <ConnectionString>TestConnectionString</ConnectionString> <Provider>SqlClient</Provider> </DefaultConnection> <Inventory> <ConnectionString>AnotherTestConnectionString</ConnectionString> <Provider>MySql</Provider> </Inventory> </Data> </settings>"; var modifiedXml = @"<?xml version=""1.0"" encoding=""UTF-8""?> <?xml-stylesheet type=""text/xsl"" href=""style1.xsl""?> <settings xmlns:MyNameSpace=""http://microsoft.com/wwa/mynamespace""> <?xml-stylesheet type=""text/xsl"" href=""style2.xsl""?> <MyNameSpace:Data> <DefaultConnection> <ConnectionString>TestConnectionString</ConnectionString> <Provider>SqlClient</Provider> </DefaultConnection> <Inventory> <ConnectionString>AnotherTestConnectionString</ConnectionString> <Provider>MySql</Provider> </Inventory> </MyNameSpace:Data> </settings>"; var xmlConfigSrc = new XmlConfigurationSource(ArbitraryFilePath); var outputCacheStream = new MemoryStream(); xmlConfigSrc.Load(StringToStream(xml)); var exception = Assert.Throws <FormatException>( () => xmlConfigSrc.Commit(StringToStream(modifiedXml), outputCacheStream)); Assert.Equal(Resources.FormatError_NamespaceIsNotSupported(Resources.FormatMsg_LineInfo(3, 31)), exception.Message); }
public void ThrowExceptionWhenKeyIsDuplicated() { var xml = @"<settings> <Data> <DefaultConnection> <ConnectionString>TestConnectionString</ConnectionString> <Provider>SqlClient</Provider> </DefaultConnection> </Data> <Data Name='DefaultConnection' ConnectionString='NewConnectionString'> <Provider>NewProvider</Provider> </Data> </settings>"; var xmlConfigSrc = new XmlConfigurationSource(ArbitraryFilePath); var expectedMsg = Resources.FormatError_KeyIsDuplicated("Data:DefaultConnection:ConnectionString", Resources.FormatMsg_LineInfo(8, 52)); var exception = Assert.Throws <FormatException>(() => xmlConfigSrc.Load(StringToStream(xml))); Assert.Equal(expectedMsg, exception.Message); }
public void ThrowExceptionWhenFindNamespace() { var xml = @"<settings xmlns:MyNameSpace='http://microsoft.com/wwa/mynamespace'> <MyNameSpace:Data> <DefaultConnection> <ConnectionString>TestConnectionString</ConnectionString> <Provider>SqlClient</Provider> </DefaultConnection> <Inventory> <ConnectionString>AnotherTestConnectionString</ConnectionString> <Provider>MySql</Provider> </Inventory> </MyNameSpace:Data> </settings>"; var xmlConfigSrc = new XmlConfigurationSource(ArbitraryFilePath); var expectedMsg = Resources.FormatError_NamespaceIsNotSupported(Resources.FormatMsg_LineInfo(1, 11)); var exception = Assert.Throws <FormatException>(() => xmlConfigSrc.Load(StringToStream(xml))); Assert.Equal(expectedMsg, exception.Message); }