Пример #1
0
        public void WebConfigScopeStorage_WithDuplicatesInUnderlyingSettings_ResolveToTheFirst()
        {
            // Arrange
            // Start with a normal NameValueCollection
            var values = new NameValueCollection();

            values.Add("foo1", "bar1");

            // Now mess it up
            // We are simulating what might happen in rare cases (probably during app-start and high load) -
            // the AppSettings NameValueCollection gets messed up internally, however keep functioning normally.
            // The duplication in AllKeys cause the bug https://aspnetwebstack.codeplex.com/workitem/912,
            var entryType    = typeof(NameObjectCollectionBase).GetNestedType("NameObjectEntry", BindingFlags.NonPublic);
            var entry        = entryType.GetConstructors(BindingFlags.Instance | BindingFlags.NonPublic)[0].Invoke(new object[] { "foo1", "bar2" });
            var entriesArray = (ArrayList)typeof(NameObjectCollectionBase).GetField("_entriesArray", BindingFlags.Instance | BindingFlags.NonPublic).GetValue(values);

            entriesArray.Add(entry);
            Assert.Equal(2, values.AllKeys.Length);

            // Act - should not throw;
            var stateStorage = new WebConfigScopeDictionary(values);

            // Assert
            Assert.Equal("bar1", stateStorage["foo1"]);
        }
        public void WebConfigScopeStorage_WithDuplicatesInUnderlyingSettings_ResolveToTheFirst()
        {
            // Arrange
            // Start with a normal NameValueCollection
            var values = new NameValueCollection();
            values.Add("foo1", "bar1");

            // Now mess it up
            // We are simulating what might happen in rare cases (probably during app-start and high load) - 
            // the AppSettings NameValueCollection gets messed up internally, however keep functioning normally.
            // The duplication in AllKeys cause the bug https://aspnetwebstack.codeplex.com/workitem/912, 
            var entryType = typeof(NameObjectCollectionBase).GetNestedType("NameObjectEntry", BindingFlags.NonPublic);
            var entry = entryType.GetConstructors(BindingFlags.Instance | BindingFlags.NonPublic)[0].Invoke(new object[] { "foo1", "bar2" });
            var entriesArray = (ArrayList)typeof(NameObjectCollectionBase).GetField("_entriesArray", BindingFlags.Instance | BindingFlags.NonPublic).GetValue(values);
            entriesArray.Add(entry);
            Assert.Equal(2, values.AllKeys.Length);

            // Act - should not throw;
            var stateStorage = new WebConfigScopeDictionary(values);

            // Assert
            Assert.Equal("bar1", stateStorage["foo1"]);
        }
 public ApplicationScopeStorageDictionary(WebConfigScopeDictionary webConfigState)
     : base(baseScope: webConfigState, backingStore: _innerDictionary)
 {
 }