public void AllowReplaceData()
        {
            IThreadStorage storage = CreateStorage();

            object value1 = new object();
            object value2 = new object();

            storage.SetData("key", value1);
            Assert.AreSame(value1, storage.GetData("key"));
            storage.SetData("key", value2);
            Assert.AreSame(value2, storage.GetData("key"));
            storage.SetData("key", null);
            Assert.AreSame(null, storage.GetData("key"));
        }
        public void IsCaseSensitive()
        {
            IThreadStorage storage = CreateStorage();

            object value1 = new object();
            object value2 = new object();
            object value3 = new object();

            storage.SetData("key", value1);
            storage.SetData("KEY", value2);
            storage.SetData("KeY", value3);

            Assert.AreSame(value1, storage.GetData("key"));
            Assert.AreSame(value2, storage.GetData("KEY"));
            Assert.AreSame(value3, storage.GetData("KeY"));
        }
        public void FreeNamedDataSlotRemovesData()
        {
            IThreadStorage storage = CreateStorage();

            object value1 = new object();

            storage.SetData("key", value1);
            Assert.AreSame(value1, storage.GetData("key"));
            storage.FreeNamedDataSlot("key");
            Assert.AreSame(null, storage.GetData("key"));
        }
        public void UsesDistinguishedStorageOnDifferentThreads()
        {
            IThreadStorage storage = CreateStorage();

            object value1 = new object();

            storage.SetData("key", value1);

            ThreadTestHelper helper = new ThreadTestHelper(this, storage);

            helper.Execute();

            Assert.AreNotSame(value1, helper.value);
            Assert.IsNull(helper.value);
        }
Exemplo n.º 5
0
 /// <summary>
 /// Stores a given object and associates it with the specified <paramref name="name"/>.
 /// </summary>
 /// <param name="name">The name with which to associate the new item.</param>
 /// <param name="value">The object to store in the current thread's context.</param>
 public void SetData(string name, object value)
 {
     if (primaryStorage.IsAvailable())
     {
         primaryStorage.SetData(name, value);
     }
     else if (secondaryStorage.IsAvailable())
     {
         secondaryStorage.SetData(name, value);
     }
     else
     {
         throw createNotSupportedException();
     }
 }
 /// <summary>
 /// Stores a given object and associates it with the specified name.
 /// </summary>
 /// <param name="name">The name with which to associate the new item.</param>
 /// <param name="value">The object to store in the current thread's context.</param>
 public static void SetData(string name, object value)
 {
     threadStorage.SetData(name, value);
 }