public void GetExecutorByWalkingTheStack_NotNamedInFinder_FindsDirectlyOnMethod() { var finder = new ConnectionExecutorFinder(null); var executor = finder.GetExecutorByWalkingTheStack(); Assert.IsTrue(executor is SqlServerProvider); Assert.AreEqual("K3", executor.ConnectionString); }
public void GetExecutorByWalkingTheStack_NonNamed_FindsTheClassConnection() { var finder = new ConnectionExecutorFinder(null); var executor = finder.GetExecutorByWalkingTheStack(); Assert.IsTrue(executor is OracleProvider); Assert.AreEqual("K1", executor.ConnectionString); }
public void GetExecutorByWalkingTheStack_NamedFromClass_IgnoresMethodAndGetsFromClass() { var finder = new ConnectionExecutorFinder("OnClass"); var executor = finder.GetExecutorByWalkingTheStack(); Assert.IsTrue(executor is OracleProvider); Assert.AreEqual("K1", executor.ConnectionString); }
/// <summary> /// Gets the SQL executor. If an appropriate executor /// is not in the cache, it will be found, and this is done be traversing the stack /// backwards until a method or class (in that order) that is decorated with a connection /// attribute /// </summary> /// <param name="name">The name.</param> /// <returns></returns> public static ISqlProvider GetSqlExecutor(string name) { if (name == null && executorMap.Count > 0) { return executorMap.Values.First(x => true); } var finder = new ConnectionExecutorFinder(name); var result = finder.GetExecutorByWalkingTheStack(); executorMap.Add(finder.Name, result); return result; }
/// <summary> /// Gets the SQL executor. If an appropriate executor /// is not in the cache, it will be found, and this is done be traversing the stack /// backwards until a method or class (in that order) that is decorated with a connection /// attribute /// </summary> /// <param name="name">The name.</param> /// <returns></returns> public static ISqlProvider GetSqlExecutor(string name) { if (name == null && executorMap.Count > 0) { return(executorMap.Values.First(x => true)); } var finder = new ConnectionExecutorFinder(name); var result = finder.GetExecutorByWalkingTheStack(); executorMap.Add(finder.Name, result); return(result); }
public void GetExecutorByWalkingTheStack_NonExistingName_ThrowsInvalidOperationException() { var finder = new ConnectionExecutorFinder("Non_Existing_Name"); var executor = finder.GetExecutorByWalkingTheStack(); Console.WriteLine(executor); }