public void Should_SetValue_in_CallContext() { var key = "testKey"; var expected = "Some Text"; var contextStorage = new CallContextStorage(); contextStorage.SetValue(key, expected); var actual = contextStorage.GetValue <string>(key); actual.ShouldBe(expected); }
/// <summary> /// Transfers necessary context from <see cref="HttpContext"/> to the injected underlying context provider (e.g. <see cref="CallContext"/>, for running background worker threads in ASP.NET applications). /// </summary> public void TransferContext() { // Iterate through all context storage keys providers foreach (var keys in _httpContextStorageTransferKeys) { // Add each key/value pair to the call context foreach (string key in keys.GetKeys()) { _callContextStorage.SetValue(key, _httpContextStorage.GetValue <object>(key)); } } }
public void Should_Get_Generic_Value_in_CallContext() { var key = "testKey"; var expected = "Some Text"; var contextStorage = new CallContextStorage(); var testObject = new TestObject { Text = expected }; contextStorage.SetValue(key, testObject); var actual = contextStorage.GetValue <TestObject>(key); actual.Text.ShouldBe(expected); }