/// <summary> /// C'tor. /// </summary> /// <param name="connection">The connection information</param> /// <param name="settings">The mock settings</param> internal MockSqlCommand(DbConnection connection, MockSettings settings) { Assert.IsTrue(connection != null); Assert.IsTrue(settings != null); this.DbConnection = connection; this.parameterCollection = new MockSqlParameterCollection(); this.settings = settings; }
/// <summary> /// Gets all the settings for the mock session /// </summary> /// <returns></returns> public static MockSettings RetrieveSettings() { StackTrace stackTrace = new StackTrace(); StackFrame[] stackFrames = stackTrace.GetFrames(); var testMethodFrames = ( from StackFrame frame in stackFrames where (frame.GetMethod().GetCustomAttribute <TestMethodAttribute>() != null) || (frame.GetMethod().GetCustomAttribute <TestInitializeAttribute>() != null) || (frame.GetMethod().GetCustomAttribute <TestCleanupAttribute>() != null) || (frame.GetMethod().GetCustomAttribute <ClassInitializeAttribute>() != null) || (frame.GetMethod().GetCustomAttribute <ClassCleanupAttribute>() != null) select frame).ToArray(); StackFrame testMethodFrame = testMethodFrames.FirstOrDefault(); MockSettings settings = new MockSettings(); if (testMethodFrame != null) { settings.mockId = GetMockId(testMethodFrame); RecordMockDataResultsAttribute recordAttr = FindRecordMockDataResultsAttribute(testMethodFrame); if (recordAttr != null) { settings.recordingMode = true; settings.outputPath = recordAttr.OutputPath; settings.isolatedQueries = recordAttr.IsolatedQueries; } } else { // Leave the rest of settings as defaults (nulls and false) } return(settings); }
/// <summary> /// Constructor for the mock sql connection /// </summary> public MockSqlConnection() { this.settings = MockSettings.RetrieveSettings(); }
/// <summary> /// Gets all the settings for the mock session /// </summary> /// <returns></returns> public static MockSettings RetrieveSettings() { StackTrace stackTrace = new StackTrace(); StackFrame[] stackFrames = stackTrace.GetFrames(); var testMethodFrames = ( from StackFrame frame in stackFrames where (frame.GetMethod().GetCustomAttribute<TestMethodAttribute>() != null) || (frame.GetMethod().GetCustomAttribute<TestInitializeAttribute>() != null) || (frame.GetMethod().GetCustomAttribute<TestCleanupAttribute>() != null) || (frame.GetMethod().GetCustomAttribute<ClassInitializeAttribute>() != null) || (frame.GetMethod().GetCustomAttribute<ClassCleanupAttribute>() != null) select frame).ToArray(); StackFrame testMethodFrame = testMethodFrames.FirstOrDefault(); MockSettings settings = new MockSettings(); if (testMethodFrame != null) { settings.mockId = GetMockId(testMethodFrame); RecordMockDataResultsAttribute recordAttr = FindRecordMockDataResultsAttribute(testMethodFrame); if (recordAttr != null) { settings.recordingMode = true; settings.outputPath = recordAttr.OutputPath; settings.isolatedQueries = recordAttr.IsolatedQueries; } } else { // Leave the rest of settings as defaults (nulls and false) } return settings; }