private void ExecuteNonQueryAssert(IDbCommand command, int times) { command.Received(times).ExecuteNonQuery(); command.DidNotReceive().ExecuteReader(); command.DidNotReceive().ExecuteReader(Arg.Any <CommandBehavior>()); command.DidNotReceive().ExecuteScalar(); }
public void ExecuteJob_NoOutputFormatSpecified_CommandExecutedWithoutWriter(string jobOutputFormat) { // setup string connString = Guid.NewGuid().ToString(); ConnectionSetting connSetting = new ConnectionSetting(Guid.NewGuid().ToString(), connString); ReportJob job = new ReportJob(); job.Command = Guid.NewGuid().ToString(); job.OutputFormat = jobOutputFormat; IDbConnection dbConn = Substitute.For <IDbConnection>(); _dbConnectionFactory.CreateConnection(connString, true).Returns(dbConn); IDbCommand cmd = Substitute.For <IDbCommand>(); dbConn.CreateCommand().Returns(cmd); // execute ReportJobResult result = _reportExecutor.ExecuteJob(connSetting, job); // assert cmd.Received(1).ExecuteNonQuery(); cmd.DidNotReceive().ExecuteReader(); Assert.AreEqual(0, result.RowCount); Assert.GreaterOrEqual(result.ExecutionTime.TotalMilliseconds, 0); }
public void ExecuteJob_NoDbParameters_CommandParametersNotSet() { // setup string connString = Guid.NewGuid().ToString(); ConnectionSetting connSetting = new ConnectionSetting(Guid.NewGuid().ToString(), connString); ReportJob job = new ReportJob(); job.Command = Guid.NewGuid().ToString(); job.Parameters = Guid.NewGuid().ToString(); IDbConnection dbConn = Substitute.For <IDbConnection>(); _dbConnectionFactory.CreateConnection(connString, true).Returns(dbConn); IDbCommand cmd = Substitute.For <IDbCommand>(); dbConn.CreateCommand().Returns(cmd); _dbParameterUtility.ConvertXmlToDbParameters(job.Parameters).Returns(new SqlParameter[] { }); // execute _reportExecutor.ExecuteJob(connSetting, job); // assert var temp = cmd.DidNotReceive().Parameters; }
public void ExecuteJob_OutputFormatSpecified_CommandExecutedWithWriter() { // setup string connString = Guid.NewGuid().ToString(); ConnectionSetting connSetting = new ConnectionSetting(Guid.NewGuid().ToString(), connString); ReportJob job = new ReportJob(); job.Command = Guid.NewGuid().ToString(); job.OutputFormat = Guid.NewGuid().ToString(); job.OutputFileName = Guid.NewGuid().ToString(); job.OutputFilePath = Environment.CurrentDirectory; job.Delimiter = Guid.NewGuid().ToString(); IDbConnection dbConn = Substitute.For <IDbConnection>(); _dbConnectionFactory.CreateConnection(connString, true).Returns(dbConn); IDbCommand cmd = Substitute.For <IDbCommand>(); dbConn.CreateCommand().Returns(cmd); IReportWriter reportWriter = Substitute.For <IReportWriter>(); _reportWriterFactory.GetReportWriter(job.OutputFormat).Returns(reportWriter); IDataReader reader = Substitute.For <IDataReader>(); reader.GetSchemaTable().Returns(new DataTable()); cmd.ExecuteReader().Returns(reader); // execute ReportJobResult result = _reportExecutor.ExecuteJob(connSetting, job); // assert cmd.DidNotReceive().ExecuteNonQuery(); cmd.Received(1).ExecuteReader(); reportWriter.Received(1).Initialise(Arg.Any <String>(), job.Delimiter); reportWriter.Received(1).WriteHeader(Arg.Any <IEnumerable <String> >()); }
public void ExecuteJob_JobCommandTypeNotStoredProcedure_CommandTypeNotSet(string jobCommandType) { // setup string connString = Guid.NewGuid().ToString(); ConnectionSetting connSetting = new ConnectionSetting(Guid.NewGuid().ToString(), connString); ReportJob job = new ReportJob(); job.Command = Guid.NewGuid().ToString(); job.CommandType = jobCommandType; IDbConnection dbConn = Substitute.For <IDbConnection>(); _dbConnectionFactory.CreateConnection(connString, true).Returns(dbConn); IDbCommand cmd = Substitute.For <IDbCommand>(); dbConn.CreateCommand().Returns(cmd); // execute _reportExecutor.ExecuteJob(connSetting, job); // assert cmd.DidNotReceive().CommandType = Arg.Any <System.Data.CommandType>(); }