Esempio n. 1
0
 internal ContextCarrier(IEnumerable <string> names)
 {
     foreach (string name in names)
     {
         _contexts[name] = LogicalThreadContext.GetData(name);
     }
 }
Esempio n. 2
0
 internal void RestoreContext()
 {
     if (Thread.CurrentThread != _creatorThread)
     {
         Thread.CurrentPrincipal = _principal;
         foreach (KeyValuePair <string, object> pair in _contexts)
         {
             LogicalThreadContext.SetData(pair.Key, pair.Value);
         }
     }
 }
        public void StorageIsUsedByFacadeMethods()
        {
            MockStorage storage = new MockStorage();

            LogicalThreadContext.SetStorage(storage);

            object value = new object();

            LogicalThreadContext.SetData("key", value);
            Assert.AreSame(value, storage.data["key"]);

            object data = LogicalThreadContext.GetData("key");

            Assert.AreSame(value, data);

            LogicalThreadContext.FreeNamedDataSlot("key");

            Assert.IsFalse(storage.data.ContainsKey("key"));
        }
 public void StorageMayBeSetMoreThanOnce()
 {
     LogicalThreadContext.SetStorage(new MockStorage());
     LogicalThreadContext.SetStorage(new MockStorage());
     LogicalThreadContext.SetStorage(new MockStorage());
 }
 public void StorageMustNotBeNull()
 {
     Assert.Throws <ArgumentNullException>(() => LogicalThreadContext.SetStorage(null));
 }
 public void StorageMustNotBeNull()
 {
     LogicalThreadContext.SetStorage(null);
 }