public void ReadOnlyCollection_AttemptingToModifyCollection_Throws() { var nameValueCollection = new ReadOnlyNameValueCollection(); Assert.Throws<NotSupportedException>(() => nameValueCollection.Add("name", "value")); Assert.Throws<NotSupportedException>(() => nameValueCollection.Set("name", "value")); Assert.Throws<NotSupportedException>(() => nameValueCollection.Remove("name")); Assert.Throws<NotSupportedException>(() => nameValueCollection.Clear()); }
public void Configure(string configFilePath) { string keyAttriuteName = "key", valueAttributeName = "value"; Check.IsNotEmpty(configFilePath, "configFilePath"); configFilePath=Util.GetFullPath(configFilePath); if (!File.Exists(configFilePath)) { throw new FileNotFoundException(String.Format(AppCommon.File_Not_Found, configFilePath)); } ConfigXmlDocument document1 = new ConfigXmlDocument(); try { document1.Load(configFilePath); } catch (XmlException exception1) { throw new ConfigurationErrorsException(exception1.Message, exception1, configFilePath, exception1.LineNumber); } XmlNode section = document1.DocumentElement; _locker.EnterWriteLock(); try { _readonlyCollection = new ReadOnlyNameValueCollection(StringComparer.OrdinalIgnoreCase); HandlerBase.CheckForUnrecognizedAttributes(section); foreach (XmlNode node1 in section.ChildNodes) { if (!HandlerBase.IsIgnorableAlsoCheckForNonElement(node1)) { if (node1.Name == "add") { string text1 = HandlerBase.RemoveRequiredAttribute(node1, keyAttriuteName); string text2 = HandlerBase.RemoveRequiredAttribute(node1, valueAttributeName, true); HandlerBase.CheckForUnrecognizedAttributes(node1); _readonlyCollection[text1] = text2; } else { if (node1.Name == "remove") { string text3 = HandlerBase.RemoveRequiredAttribute(node1, keyAttriuteName); HandlerBase.CheckForUnrecognizedAttributes(node1); _readonlyCollection.Remove(text3); continue; } if (node1.Name.Equals("clear")) { HandlerBase.CheckForUnrecognizedAttributes(node1); _readonlyCollection.Clear(); continue; } HandlerBase.ThrowUnrecognizedElement(node1); } } } _readonlyCollection.SetReadOnly(); } finally { _locker.ExitWriteLock(); } FileWatchHandler fileWatchHandler = new FileWatchHandler(this, new FileInfo(configFilePath)); fileWatchHandler.StartWatching(); }