public override void SetUp() { base.SetUp(); SafeCallContext.Clear(); ClearFiles(); }
public override void TearDown() { base.TearDown(); SafeCallContext.Clear(); FileSystems.ResetShadowId(); ClearFiles(); }
public override void Initialize() { base.Initialize(); SafeCallContext.Clear(); ClearFiles(); }
static ScopeProvider() { SafeCallContext.Register( () => { var scope = GetCallContextObject <Scope>(ScopeItemKey); var context = GetCallContextObject <ScopeContext>(ContextItemKey); SetCallContextObject(ScopeItemKey, null); SetCallContextObject(ContextItemKey, null); return(Tuple.Create(scope, context)); }, o => { // cannot re-attached over leaked scope/context if (GetCallContextObject <Scope>(ScopeItemKey) != null) { throw new Exception("Found leaked scope when restoring call context."); } if (GetCallContextObject <ScopeContext>(ContextItemKey) != null) { throw new Exception("Found leaked context when restoring call context."); } var t = (Tuple <Scope, ScopeContext>)o; SetCallContextObject(ScopeItemKey, t.Item1); SetCallContextObject(ContextItemKey, t.Item2); }); }
private static void Reset() { // reset settings SettingsForTests.Reset(); // clear the logical call context SafeCallContext.Clear(); }
static CallContextTests() { SafeCallContext.Register(() => { CallContext.FreeNamedDataSlot("test1"); CallContext.FreeNamedDataSlot("test2"); return(null); }, o => {}); }
public void Setup() { // bah SafeCallContext.Clear(); _dbContext = new DatabaseContext( new ScopeProvider(new DefaultDatabaseFactory(Constants.System.UmbracoConnectionName, Mock.Of <ILogger>())), Mock.Of <ILogger>(), new SqlCeSyntaxProvider(), Constants.DatabaseProviders.SqlCe); //unfortunately we have to set this up because the PetaPocoExtensions require singleton access ApplicationContext.Current = new ApplicationContext( CacheHelper.CreateDisabledCacheHelper(), new ProfilingLogger(Mock.Of <ILogger>(), Mock.Of <IProfiler>())) { DatabaseContext = _dbContext, IsReady = true }; }
protected HybridAccessorBase(IHttpContextAccessor httpContextAccessor) { if (httpContextAccessor == null) { throw new ArgumentNullException(nameof(httpContextAccessor)); } _httpContextAccessor = httpContextAccessor; lock (Locker) { // register the itemKey once with SafeCallContext if (_registered) { return; } _registered = true; } // ReSharper disable once VirtualMemberCallInConstructor var itemKey = ItemKey; // virtual SafeCallContext.Register(() => { var value = CallContext.LogicalGetData(itemKey); CallContext.FreeNamedDataSlot(itemKey); return(value); }, o => { if (o == null) { return; } var value = o as T; if (value == null) { throw new ArgumentException($"Expected type {typeof(T).FullName}, got {o.GetType().FullName}", nameof(o)); } CallContext.LogicalSetData(itemKey, value); }); }
public override void Initialize() { InitializeFirstRunFlags(); var path = TestHelper.CurrentAssemblyDirectory; AppDomain.CurrentDomain.SetData("DataDirectory", path); // we probably don't need this here, as it's done in base.Initialize() already, // but these test classes are all weird, not going to change it now - v8 SafeCallContext.Clear(); _dbFactory = new DefaultDatabaseFactory( GetDbConnectionString(), GetDbProviderName(), Logger); // ensure we start tests in a clean state ie without any scope in context // anything that used a true 'Scope' would have removed it, but there could // be a rogue 'NoScope' there - and we want to make sure it is gone var scopeProvider = new ScopeProvider(null); if (scopeProvider.AmbientScope != null) { scopeProvider.AmbientScope.Dispose(); // removes scope from context } base.Initialize(); using (ProfilingLogger.TraceDuration <BaseDatabaseFactoryTest>("init")) { //TODO: Somehow make this faster - takes 5s + DatabaseContext.Initialize(_dbFactory.ProviderName, _dbFactory.ConnectionString); CreateSqlCeDatabase(); InitializeDatabase(); //ensure the configuration matches the current version for tests SettingsForTests.ConfigurationStatus = UmbracoVersion.GetSemanticVersion().ToSemanticString(); } }
static ScopeProvider() { SafeCallContext.Register( () => { var scope = GetCallContextObject <IScopeInternal>(ScopeItemKey); var context = GetCallContextObject <ScopeContext>(ContextItemKey); SetCallContextObject(ScopeItemKey, null); SetCallContextObject(ContextItemKey, null); return(Tuple.Create(scope, context)); }, o => { // cannot re-attached over leaked scope/context // except of course over NoScope (which leaks) var ambientScope = GetCallContextObject <IScope>(ScopeItemKey); if (ambientScope != null) { var ambientNoScope = ambientScope as NoScope; if (ambientNoScope == null) { throw new Exception("Found leaked scope when restoring call context."); } // this should rollback any pending transaction ambientNoScope.Dispose(); } if (GetCallContextObject <ScopeContext>(ContextItemKey) != null) { throw new Exception("Found leaked context when restoring call context."); } var t = (Tuple <IScopeInternal, ScopeContext>)o; SetCallContextObject(ScopeItemKey, t.Item1); SetCallContextObject(ContextItemKey, t.Item2); }); }
public void TearDown() { SafeCallContext.Clear(); ClearFiles(); FileSystems.ResetShadowId(); }
public void SetUp() { SafeCallContext.Clear(); ClearFiles(); ShadowFileSystems.ResetId(); }
public override void TearDown() { base.TearDown(); SafeCallContext.Clear(); ClearFiles(); }
public void Setup() { SafeCallContext.Clear(); }
public void TearDown() { SafeCallContext.Clear(); }