本文整理汇总了C#中Context.ReadConfigAsInt32方法的典型用法代码示例。如果您正苦于以下问题:C# Context.ReadConfigAsInt32方法的具体用法?C# Context.ReadConfigAsInt32怎么用?C# Context.ReadConfigAsInt32使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Context
的用法示例。
在下文中一共展示了Context.ReadConfigAsInt32方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Execute
/// <summary>
/// ITestStep.Execute() implementation
/// </summary>
/// <param name='testConfig'>The Xml fragment containing the configuration for this test step</param>
/// <param name='context'>The context for the test, this holds state that is passed beteen tests</param>
public void Execute(System.Xml.XmlNode testConfig, Context context)
{
// read test config...
string path = context.ReadConfigAsString( testConfig, "Path" );
string fileFilter = context.ReadConfigAsString( testConfig, "FileFilter" );
int timeOut = context.ReadConfigAsInt32( testConfig, "TimeOut" );
var watcher = new FileSystemWatcher
{
Path = path,
Filter = fileFilter,
NotifyFilter = NotifyFilters.LastWrite,
EnableRaisingEvents = true,
IncludeSubdirectories = false
};
watcher.Changed += OnCreated;
_mre = new ManualResetEvent(false);
if(!_mre.WaitOne(timeOut, false))
{
throw new Exception(string.Format("WaitOnFileStep timed out after {0} milisecs watching path:{1}, filter{2}", timeOut, path, fileFilter));
}
context.LogInfo(string.Format("WaitOnFileStep found the file: {0}", _newFilePath));
context.Add("waitedForFileName", _newFilePath);
}
示例2: Execute
/// <summary>
/// ITestStep.Execute() implementation
/// </summary>
/// <param name='testConfig'>The Xml fragment containing the configuration for this test step</param>
/// <param name='context'>The context for the test, this holds state that is passed beteen tests</param>
public void Execute(XmlNode testConfig, Context context)
{
int timeout = context.ReadConfigAsInt32(testConfig, "Timeout");
Thread.Sleep(timeout);
// Get the list of files in the directory
string directoryPath = context.ReadConfigAsString(testConfig, "DirectoryPath");
string pattern = context.ReadConfigAsString(testConfig, "SearchPattern");
string [] filelist = Directory.GetFiles( directoryPath, pattern ) ;
int expectedNoOfFiles = context.ReadConfigAsInt32(testConfig, "ExpectedNoOfFiles");
if ( filelist.Length != expectedNoOfFiles )
{
// Expecting more than one file
throw new ApplicationException( String.Format( "Directory does not contain the correct number of files!\n Found: {0} files matching the pattern {1}.", filelist.Length, pattern ) ) ;
}
context.LogInfo( "FilesExistStep found: \"{0}\" files", filelist.Length ) ;
}
示例3: Execute
/// <summary>
/// ITestStep.Execute() implementation
/// </summary>
/// <param name='testConfig'>The Xml fragment containing the configuration for this test step</param>
/// <param name='context'>The context for the test, this holds state that is passed beteen tests</param>
public void Execute(XmlNode testConfig, Context context)
{
string queueManager = context.ReadConfigAsString(testConfig, "QueueManager");
string queue = context.ReadConfigAsString(testConfig, "Queue");
int waitTimeout = context.ReadConfigAsInt32(testConfig, "WaitTimeout");
XmlNode validationConfig = testConfig.SelectSingleNode("ValidationStep");
string message = MQSeriesHelper.ReadMessage(queueManager, queue, waitTimeout, context);
context.LogData("MQSeries output message:", message);
context.ExecuteValidator(StreamHelper.LoadMemoryStream(message), validationConfig);
}
示例4: Execute
/// <summary>
/// ITestStep.Execute() implementation
/// </summary>
/// <param name='testConfig'>The Xml fragment containing the configuration for this test step</param>
/// <param name='context'>The context for the test, this holds state that is passed beteen tests</param>
public void Execute(XmlNode testConfig, Context context)
{
MemoryStream request = null;
MemoryStream response = null;
try
{
// read test config...
string sourcePath = context.ReadConfigAsString( testConfig, "SourcePath" );
string destinationUrl = context.ReadConfigAsString( testConfig, "DestinationUrl" );
int requestTimeout = context.ReadConfigAsInt32( testConfig, "RequestTimeout" );
XmlNode validationConfig = testConfig.SelectSingleNode("ValidationStep");
context.LogInfo("HttpRequestResponseStep about to post data from File: {0} to the Url: {1}", sourcePath, destinationUrl );
// Get the data to post...
request = StreamHelper.LoadFileToStream(sourcePath);
byte[] data = request.GetBuffer();
// Post the data...
response = HttpHelper.SendRequestData(destinationUrl, data, requestTimeout, context);
// Dump the respons to the console...
StreamHelper.WriteStreamToConsole("HttpRequestResponseStep response data", response, context);
// Validate the response...
try
{
response.Seek(0, SeekOrigin.Begin);
context.ExecuteValidator( response, validationConfig );
}
catch(Exception e)
{
throw new ApplicationException("HttpRequestResponseStep response stream was not correct!", e);
}
}
finally
{
if ( null != response )
{
response.Close();
}
if ( null != request )
{
request.Close();
}
}
}
示例5: Execute
/// <summary>
/// ITestStep.Execute() implementation
/// </summary>
/// <param name='testConfig'>The Xml fragment containing the configuration for this test step</param>
/// <param name='context'>The context for the test, this holds state that is passed beteen tests</param>
public void Execute(XmlNode testConfig, Context context)
{
var delayBeforeCheck = context.ReadConfigAsInt32( testConfig, "DelayBeforeExecution" );
var connectionString = context.ReadConfigAsString( testConfig, "ConnectionString" );
var datasetWriteXmlSchemaPath = context.ReadConfigAsString(testConfig, "DatasetWriteXmlSchemaPath");
var datasetWriteXmlPath = context.ReadConfigAsString(testConfig, "DatasetWriteXmlPath");
var tableNames = context.ReadConfigAsString(testConfig, "TableNames");
// Sleep for delay seconds...
System.Threading.Thread.Sleep(delayBeforeCheck);
var ds = GetDataSet(connectionString, tableNames);
ds.WriteXml(datasetWriteXmlPath);
ds.WriteXmlSchema(datasetWriteXmlSchemaPath);
}
示例6: Execute
/// <summary>
/// ITestStep.Execute() implementation
/// </summary>
/// <param name='testConfig'>The Xml fragment containing the configuration for this test step</param>
/// <param name='context'>The context for the test, this holds state that is passed beteen tests</param>
public void Execute(XmlNode testConfig, Context context)
{
string connectionString = context.ReadConfigAsString( testConfig, "ConnectionString" );
string table = context.ReadConfigAsString( testConfig, "Table" );
string condition = context.ReadConfigAsString( testConfig, "Condition" );
int expectedRows = context.ReadConfigAsInt32( testConfig, "ExpectedRows" );
// Build SQL statement
string sqlStatement = "select count(*) from " + table + " where " + condition ;
context.LogInfo( "DatabaseRowCountStep connecting to {0}, executing statement {1}", connectionString, sqlStatement ) ;
// Execute command against specified database
int rows = DatabaseHelper.ExecuteScalar( connectionString, sqlStatement ) ;
// Number of rows as expected?
if ( rows != expectedRows )
{
throw new ApplicationException( string.Format( "DatabaseRowCountStep failed, expected {0} rows but found {1} rows", expectedRows, rows ) ) ;
}
context.LogInfo( "DatabaseRowCountStep found \"{0}\" rows", rows ) ;
}
示例7: Execute
/// <summary>
/// ITestStep.Execute() implementation
/// </summary>
/// <param name='testConfig'>The Xml fragment containing the configuration for this test step</param>
/// <param name='context'>The context for the test, this holds state that is passed beteen tests</param>
public void Execute(XmlNode testConfig, Context context)
{
MemoryStream request = null;
MemoryStream response = null;
try
{
// read test config...
string sourcePath = context.ReadConfigAsString( testConfig, "SourcePath" );
string destinationUrl = context.ReadConfigAsString( testConfig, "DestinationUrl" );
int requestTimeout = context.ReadConfigAsInt32( testConfig, "RequestTimeout" );
context.LogInfo("HttpRequestResponseStep about to post data from File: {0} to the Url: {1}", sourcePath, destinationUrl );
// Get the data to post...
request = StreamHelper.LoadFileToStream(sourcePath);
byte[] data = request.GetBuffer();
// Post the data...
response = HttpHelper.SendRequestData(destinationUrl, data, requestTimeout, context);
// Dump the respons to the console...
StreamHelper.WriteStreamToConsole("HttpPostStep response data", response, context);
}
finally
{
if ( null != request )
{
request.Close();
}
if ( null != response )
{
response.Close();
}
}
}
示例8: Execute
/// <summary>
/// ITestStep.Execute() implementation
/// </summary>
/// <param name='testConfig'>The Xml fragment containing the configuration for this test step</param>
/// <param name='context'>The context for the test, this holds state that is passed beteen tests</param>
public void Execute(XmlNode testConfig, Context context)
{
// Read config...
string categoryName = context.ReadConfigAsString(testConfig, "CategoryName");
string counterName = context.ReadConfigAsString(testConfig, "CounterName");
string instanceName = context.ReadConfigAsString(testConfig, "InstanceName", true);
string server = context.ReadConfigAsString(testConfig, "Server");
float counterTargetValue = context.ReadConfigAsFloat(testConfig, "CounterTargetValue");
int sleepTime = context.ReadConfigAsInt32(testConfig, "SleepTime", true);
int timeOut = context.ReadConfigAsInt32(testConfig, "TimeOut", true);
context.LogInfo("About to start monitoring: {0}\\{1}\\{2}({3}) for the target value: {4}", server, categoryName, counterName, instanceName, counterTargetValue);
// Init perfmon counter...
var perfCounter = new PerformanceCounter
{
CategoryName = categoryName,
CounterName = counterName,
MachineName = server
};
if (null != instanceName)
{
perfCounter.InstanceName = instanceName;
}
// Set default value for sleepTime
if ( 0 == sleepTime)
{
sleepTime = 100;
}
DateTime now = DateTime.Now;
DateTime end = now;
if (0 != timeOut)
{
end = now.AddSeconds(timeOut);
}
bool targetHit = false;
do
{
if (perfCounter.NextValue() == counterTargetValue)
{
targetHit = true;
context.LogInfo("Target hit");
}
else if ((end > now) || (0 == timeOut))
{
System.Threading.Thread.Sleep(sleepTime);
}
} while ( (!targetHit) && ((end > now) || (0 == timeOut)));
if (!targetHit)
{
throw new ApplicationException("The target perfmon counter was not hit!");
}
}
示例9: Execute
/// <summary>
/// ITestStep.Execute() implementation
/// </summary>
/// <param name='testConfig'>The Xml fragment containing the configuration for this test step</param>
/// <param name='context'>The context for the test, this holds state that is passed beteen tests</param>
public void Execute(XmlNode testConfig, Context context)
{
_delayBeforeExecution = context.ReadConfigAsInt32(testConfig, "DelayBeforeExecution");
_connectionString = context.ReadConfigAsString( testConfig, "ConnectionString" );
_numberOfRowsAffected = testConfig.InnerXml.IndexOf("NumberOfRowsAffected", 0, testConfig.InnerXml.Length) != -1? context.ReadConfigAsInt32 (testConfig, "NumberOfRowsAffected") : -1;
XmlNode queryConfig = testConfig.SelectSingleNode("SQLQuery");
_sqlQuery = SqlQuery.BuildSQLQuery(queryConfig, context);
Execute(context);
}
示例10: Execute
/// <summary>
/// ITestStep.Execute() implementation
/// </summary>
/// <param name='testConfig'>The Xml fragment containing the configuration for this test step</param>
/// <param name='context'>The context for the test, this holds state that is passed beteen tests</param>
public void Execute(XmlNode testConfig, Context context)
{
MemoryStream msgStr = null;
try
{
// read test config...
string sourcePath = context.ReadConfigAsString(testConfig, "SourcePath");
string queuePath = context.ReadConfigAsString(testConfig, "QueuePath");
string messageLabel = context.ReadConfigAsString(testConfig, "MessageLabel");
string correlationId = context.ReadConfigAsString(testConfig, "CorrelationId", true);
int appSpecific = context.ReadConfigAsInt32(testConfig, "AppSpecific", true);
object objUseTransactions = context.ReadConfigAsObject(testConfig, "UseTransactions", true);
if (null != objUseTransactions)
{
if (!Convert.ToBoolean(objUseTransactions))
{
_transactionType = MessageQueueTransactionType.None;
}
}
context.LogInfo("MSMQWriteStep about to write data from File: {0} to the queue: {1}", sourcePath, queuePath );
var queue = new MessageQueue(queuePath);
var msg = new Message();
msgStr = StreamHelper.LoadFileToStream(sourcePath);
msg.BodyStream = msgStr;
msg.UseDeadLetterQueue = true;
if ( null != correlationId )
{
msg.CorrelationId = correlationId;
}
msg.AppSpecific = appSpecific;
queue.Send(msg, messageLabel, _transactionType);
}
finally
{
if ( null != msgStr )
{
msgStr.Close();
}
}
}
示例11: Execute
/// <summary>
/// ITestStep.Execute() implementation
/// </summary>
/// <param name='testConfig'>The Xml fragment containing the configuration for this test step</param>
/// <param name='context'>The context for the test, this holds state that is passed beteen tests</param>
public void Execute(XmlNode testConfig, Context context)
{
_timeOut = context.ReadConfigAsInt32( testConfig, "Delay" );
Execute(context);
}
示例12: Execute
/// <summary>
/// Execute() implementation
/// </summary>
/// <param name='testConfig'>The Xml fragment containing the configuration for this test step</param>
/// <param name='context'>The context for the test, this holds state that is passed beteen tests</param>
public void Execute(XmlNode testConfig, Context context)
{
int delayBeforeCheck = context.ReadConfigAsInt32(testConfig, "DelayBeforeCheck", true);
string server = context.ReadConfigAsString(testConfig, "Server");
string user = context.ReadConfigAsString(testConfig, "User");
string password = context.ReadConfigAsString(testConfig, "Password");
string from = null;
bool showBody = false;
string subject = null;
int attachments = -1;
bool found = false;
if (testConfig.SelectSingleNode("ShowBody") != null)
{
showBody = context.ReadConfigAsBool(testConfig, "ShowBody");
}
if (testConfig.SelectSingleNode("From") != null)
{
from = context.ReadConfigAsString(testConfig, "From");
}
if (testConfig.SelectSingleNode("Subject") != null)
{
subject = context.ReadConfigAsString(testConfig, "Subject");
}
if (testConfig.SelectSingleNode("Attachments") != null)
{
attachments = context.ReadConfigAsInt32(testConfig, "Attachments");
}
if ( delayBeforeCheck > 0 )
{
context.LogInfo("Waiting for {0} seconds before checking the mail.", delayBeforeCheck);
System.Threading.Thread.Sleep(delayBeforeCheck*1000);
}
var email = new Pop3Client(user, password, server);
email.OpenInbox();
try
{
while( email.NextEmail())
{
if (email.To == user && (email.From == from || from == null) && (email.Subject == subject || subject == null))
{
if (attachments > 0 && email.IsMultipart)
{
int a = 0;
IEnumerator enumerator = email.MultipartEnumerator;
while(enumerator.MoveNext())
{
var multipart = (Pop3Component)
enumerator.Current;
if( multipart.IsBody )
{
if (showBody)
{
context.LogData("Multipart body", multipart.Data);
}
}
else
{
context.LogData("Attachment name", multipart.Name);
a++;
}
}
if (attachments == a)
{
found = true;
break;
}
}
else
{
if (showBody)
{
context.LogData("Single body", email.Body);
}
found = true;
break;
}
}
}
if (!found)
{
throw new Exception("Failed to find email message");
}
else
{
email.DeleteEmail();
}
//.........这里部分代码省略.........
示例13: Execute
/// <summary>
/// ITestStep.Execute() implementation
/// </summary>
/// <param name='testConfig'>The Xml fragment containing the configuration for this test step</param>
/// <param name='context'>The context for the test, this holds state that is passed beteen tests</param>
public void Execute(XmlNode testConfig, Context context)
{
int timeout = context.ReadConfigAsInt32(testConfig, "Timeout");
Thread.Sleep(timeout);
// Get the list of files in the directory
string directoryPath = context.ReadConfigAsString(testConfig, "DirectoryPath");
string pattern = context.ReadConfigAsString(testConfig, "SearchPattern");
string [] filelist = Directory.GetFiles( directoryPath, pattern ) ;
if ( filelist.Length == 0)
{
// Expecting more than one file
throw new ApplicationException( String.Format( "Directory contains no files matching the pattern!" ) );
}
if ( filelist.Length == 1 )
{
// Expecting more than one file
throw new ApplicationException( String.Format( "Directory only contains one file matching the pattern!" ) );
}
// Get the validate steps
XmlNodeList validationConfigs = testConfig.SelectNodes( "ValidationStep");
bool nullException = false ;
int foundSteps = 0 ;
// For each file in the file list
foreach ( string filePath in filelist )
{
context.LogInfo("FileXmlValidateStep validating file: {0}", filePath );
MemoryStream xmlData = StreamHelper.LoadFileToStream(filePath, timeout);
StreamHelper.WriteStreamToConsole( "File data to be validated", xmlData, context );
// Check it against the validate steps to see if it matches one of them
for ( int i = 0 ; i < validationConfigs.Count ; i++, nullException = false )
{
try
{
// Try the validation and catch the exception
xmlData.Seek(0, SeekOrigin.Begin);
context.ExecuteValidator( xmlData, validationConfigs.Item( i ) ) ;
}
catch ( NullReferenceException )
{
// Not found a node matching XPath, do nothing
nullException = true ;
}
catch ( ApplicationException )
{
// Not a matching comparision, do nothing
nullException = true ;
}
catch ( Exception )
{
// Not RegEx validation, do nothing
nullException = true ;
} // try
// Have we successfully run a validation?
if ( nullException == false )
{
// Yes, must be a match!
foundSteps++ ;
break ;
} // nullException
} // i
} // filePath
if ( foundSteps != filelist.Length )
{
throw new MultiUnknownException(string.Format( "FileMultiValidateStep failed, did not match all the files to those specifed in the validate steps." ) );
}
}
示例14: Execute
/// <summary>
/// ITestStep.Execute() implementation
/// </summary>
/// <param name='testConfig'>The Xml fragment containing the configuration for this test step</param>
/// <param name='context'>The context for the test, this holds state that is passed beteen tests</param>
public void Execute(XmlNode testConfig, Context context)
{
int delayBeforeCheck = context.ReadConfigAsInt32( testConfig, "DelayBeforeCheck" );
string connectionString = context.ReadConfigAsString( testConfig, "ConnectionString" );
string rootElement = context.ReadConfigAsString( testConfig, "RootElement" );
bool allowEmpty = context.ReadConfigAsBool ( testConfig, "AllowEmpty" );
XmlNode queryConfig = testConfig.SelectSingleNode( "SQLQuery" );
string sqlQuery = BuildSqlQuery( queryConfig, context );
XmlNode validationConfig = testConfig.SelectSingleNode("ValidationStep");
XmlNode contextConfig = testConfig.SelectSingleNode("ContextLoaderStep");
context.LogInfo("Using database connection string: {0}", connectionString);
context.LogInfo("Executing database query : {0}", sqlQuery );
// Sleep for delay seconds...
System.Threading.Thread.Sleep(delayBeforeCheck*1000);
string xml = GetXmlData(connectionString, sqlQuery);
context.LogInfo("Xml returned : {0}", xml );
if(xml != null && xml.Trim().Length > 0)
{
//prepare to execute context loader
byte [] buffer = System.Text.Encoding.ASCII.GetBytes("<" + rootElement +">" + xml + "</" + rootElement + ">");
MemoryStream data = null;
try
{
data = new MemoryStream(buffer);
data.Seek(0, SeekOrigin.Begin);
context.ExecuteContextLoader( data, contextConfig );
data.Seek(0, SeekOrigin.Begin);
context.ExecuteValidator( data, validationConfig );
}
finally
{
if ( null != data )
{
data.Close();
}
}
}
else if (!allowEmpty && (xml == null || xml.Trim().Length > 0))
{
throw new Exception("Response was expected.No Xml returned.");
}
else if (allowEmpty)
{
context.LogWarning("No Xml was returned from the DB Query. AllowEmpty has been set to true and hence no error has been raised");
}
}
示例15: Execute
/// <summary>
/// ITestStep.Execute() implementation
/// </summary>
/// <param name='testConfig'>The Xml fragment containing the configuration for this test step</param>
/// <param name='context'>The context for the test, this holds state that is passed beteen tests</param>
public void Execute(XmlNode testConfig, Context context)
{
LoadTypeHashTable();
int delayBeforeCheck = context.ReadConfigAsInt32( testConfig, "DelayBeforeExecution" );
string connectionString = context.ReadConfigAsString( testConfig, "ConnectionString" );
string datasetReadXmlSchemaPath = context.ReadConfigAsString(testConfig, "DatasetReadXmlSchemaPath");
string datasetReadXmlPath = context.ReadConfigAsString(testConfig, "DatasetReadXmlPath");
double delayBetweenRecordImport = testConfig.InnerXml.IndexOf("DelayBetweenRecordImports",0,testConfig.InnerXml.Length) != -1? context.ReadConfigAsInt32 (testConfig, "DelayBetweenRecordImports") : 0;
// Sleep for delay seconds...
System.Threading.Thread.Sleep(delayBeforeCheck*1000);
ImportDatasetDataIntoDBTable(connectionString,GetDataSet(datasetReadXmlSchemaPath,datasetReadXmlPath, delayBetweenRecordImport) );
}