public CoverageResult Cover(string command, int timeOut = 30) { Debug("Starting Code Coverage"); _database.TimeOut = timeOut; if (!Start()) { throw new SqlCoverException("Unable to start the trace - errors are recorded in the debug output"); } Debug("Starting Code Coverage...Done"); Debug("Executing Command: {0}", command); var sqlExceptions = new List <string>(); try { _database.Execute(command, timeOut); //todo read messages or rowcounts or something } catch (System.Data.SqlClient.SqlException e) { if (e.Number == -2) { throw; } sqlExceptions.Add(e.Message); } catch (Exception e) { Console.WriteLine("Exception running command: {0} - error: {1}", command, e.Message); } Debug("Executing Command: {0}...done", command); WaitForTraceMaxLatency(); Debug("Stopping Code Coverage"); try { var rawEvents = StopInternal(); Debug("Stopping Code Coverage...done"); Debug("Getting Code Coverage Result"); GenerateResults(_excludeFilter, rawEvents, sqlExceptions, $"SQLCover result of running '{command}'"); Debug("Getting Code Coverage Result..done"); } catch (Exception e) { throw new SqlCoverException("Exception gathering the results", e); } return(_result); }
protected void RunScript(string query, string error, int timeout = 30) { var script = GetScript(query); try { Gateway.Execute(script, timeout); } catch (Exception ex) { throw new InvalidOperationException(string.Format(error, ex.Message), ex); } }
public void Doesnt_Die_When_Finding_Encrypted_Stored_Procedures() { var databaseGateway = new DatabaseGateway(ConnectionStringReader.GetIntegration(), TestDatabaseName); databaseGateway.Execute(@"if not exists (select * from sys.procedures where name = 'enc') begin exec sp_executesql N'create procedure enc with encryption as select 100;' end", 15); var coverage = new CodeCoverage(ConnectionStringReader.GetIntegration(), TestDatabaseName, null, true, false); var results = coverage.Cover("exec enc"); //if we dont die we are good }
public void Shows_Warnings_When_Definition_Not_Available() { var databaseGateway = new DatabaseGateway(ConnectionStringReader.GetIntegration(), TestDatabaseName); databaseGateway.Execute(@"if not exists (select * from sys.procedures where name = 'enc') begin exec sp_executesql N'create procedure enc with encryption as select 100;' end", 15); var source = new DatabaseSourceGateway(databaseGateway); var warnings = source.GetWarnings(); Assert.IsTrue( warnings.Contains("enc") ); }
public void Doesnt_Die_When_Finding_Encrypted_Stored_Procedures() { var databaseGateway = new DatabaseGateway(TestServerConnectionString, TestDatabaseName, 15); databaseGateway.Execute(@"if not exists (select * from sys.procedures where name = 'enc') begin exec sp_executesql N'create procedure enc with encryption as select 100;' end"); var source = new DatabaseSourceGateway(databaseGateway); var batches = source.GetBatches(null); foreach (var batch in batches) { Console.WriteLine("batch: {0}", batch.Text); } Assert.AreEqual(5, batches.Count()); var coverage = new CodeCoverage(TestServerConnectionString, TestDatabaseName, null, true, false); Assert.DoesNotThrow(() => coverage.Cover("exec enc")); }
public CoverageResult Cover(string command, int timeOut = 30) { try { Debug("Starting Code Coverage"); Start(); Debug("Starting Code Coverage...Done"); Debug("Executing Command: {0}", command); try { _database.Execute(command, timeOut); //todo read messages or rowcounts or something } catch (Exception e) { Console.WriteLine("Exception running command: {0} - error: {1}", command, e.Message); } Debug("Executing Command: {0}...done", command); WaitForTraceMaxLatency(); Debug("Stopping Code Coverage"); var rawEvents = StopInternal(); Debug("Stopping Code Coverage...done"); Debug("Getting Code Coverage Result"); GenerateResults(_excludeFilter, rawEvents); Debug("Getting Code Coverage Result..done"); } catch (Exception e) { Debug("Exception running code coverage: {0}\r\n{1}", e.Message, e.StackTrace); } return(_result); }
public void Doesnt_Die_When_Finding_Encrypted_Stored_Procedures() { var databaseGateway = new DatabaseGateway(TestServerConnectionString, TestDatabaseName); databaseGateway.Execute(@"if not exists (select * from sys.procedures where name = 'enc') begin exec sp_executesql N'create procedure enc with encryption as select 100;' end", 15); var source = new DatabaseSourceGateway(databaseGateway); var batches = source.GetBatches(null); foreach (var batch in batches) { Console.WriteLine("batch: {0}", batch.Text); } Assert.AreEqual(4, batches.Count()); var proc = batches.FirstOrDefault(p => p.ObjectName == "[dbo].[a_large_procedure]"); Assert.AreEqual(2, proc.StatementCount); }