本文整理汇总了C#中Context.ExecuteValidator方法的典型用法代码示例。如果您正苦于以下问题:C# Context.ExecuteValidator方法的具体用法?C# Context.ExecuteValidator怎么用?C# Context.ExecuteValidator使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Context
的用法示例。
在下文中一共展示了Context.ExecuteValidator方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Execute
/// <summary>
/// ITestStep.Execute() implementation
/// </summary>
/// <param name='context'>The context for the test, this holds state that is passed beteen tests</param>
public void Execute(Context context)
{
MemoryStream data = null;
try
{
context.LogInfo("Searching for files in: \"{0}{1}\"", _directory, _searchPattern);
DateTime endTime = DateTime.Now + TimeSpan.FromMilliseconds(_timeout);
FileInfo[] files;
do
{
var di = new DirectoryInfo(_directory);
files = di.GetFiles(_searchPattern);
Thread.Sleep(100);
} while ((files.Length == 0) && (endTime > DateTime.Now));
if (files.Length == 0)
{
throw new ApplicationException(string.Format("No files were found at: {0}{1}", _directory, _searchPattern));
}
context.LogInfo("{0} fies were found at : \"{1}{2}\"", files.Length, _directory, _searchPattern);
IOException ex = null;
do
{
try
{
using (var fs = new FileStream(files[0].FullName, FileMode.Open, FileAccess.Read))
{
data = StreamHelper.LoadMemoryStream(fs);
}
}
catch (IOException ioex)
{
context.LogWarning("IOException caught trying to load file, will re-try if within timeout");
ex = ioex;
Thread.Sleep(100);
}
} while ((null == data) && (endTime > DateTime.Now));
if (null != ex)
{
throw ex;
}
context.LogData(string.Format("Loaded FILE: {0}", files[0].FullName), data);
data.Seek(0, SeekOrigin.Begin);
if (null != _contextLoaderStep)
{
_contextLoaderStep.ExecuteContextLoader(data, context);
}
if (null != _contextConfig)
{
context.ExecuteContextLoader(data, _contextConfig);
}
data.Seek(0, SeekOrigin.Begin);
if (null != _validationStep)
{
context.ExecuteValidator(data, _validationStep);
}
if (null != _validationConfig)
{
context.ExecuteValidator(data, _validationConfig);
}
if (_deleteFile)
{
File.Delete(files[0].FullName);
}
}
finally
{
if (null != data)
{
data.Close();
}
}
}
示例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)
{
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);
}
示例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)
{
const string soapproxynamespace = "BizUnit.Proxy";
Stream request = null;
Stream response = null;
// Turn on shadow copying of asseblies for the current appdomain.
AppDomain.CurrentDomain.SetShadowCopyFiles();
try
{
string wsdlFile = context.ReadConfigAsString(testConfig, "WebServiceWSDLURL");
string soapMessagePath = context.ReadConfigAsString(testConfig, "MessagePayload", true);
string inputMessageTypeName = context.ReadConfigAsString(testConfig, "InputMessageTypeName", true);
string webMethod = context.ReadConfigAsString(testConfig, "WebMethod");
string serviceName = context.ReadConfigAsString(testConfig, "ServiceName");
Assembly proxyAssembly = GetProxyAssembly(wsdlFile, soapproxynamespace);
object objInputMessage = null;
if(null != inputMessageTypeName && null != soapMessagePath)
{
objInputMessage =
LoadMessage(proxyAssembly, soapproxynamespace + "." + inputMessageTypeName, soapMessagePath);
if (null != objInputMessage)
{
request = GetOutputStream(objInputMessage);
context.LogData("SOAPHTTPRequestResponseStep request data", request);
}
}
object proxy = Activator.CreateInstance(proxyAssembly.GetType(soapproxynamespace + "." + serviceName));
MethodInfo mi = proxy.GetType().GetMethod(webMethod);
context.LogInfo("SOAPHTTPRequestResponseStep about to post data from File: {0} to the Service: {1} defined in WSDL: {2}", soapMessagePath, serviceName, wsdlFile);
object outputMessage;
if (null != inputMessageTypeName && null != soapMessagePath)
{
outputMessage = mi.Invoke(proxy, new[] { objInputMessage });
}
else
{
outputMessage = mi.Invoke(proxy, null);
}
if (null != outputMessage)
{
response = GetOutputStream(outputMessage);
context.LogData("SOAPHTTPRequestResponseStep response data", response);
}
// Execute ctx loader step if present...
if (null != response)
{
context.ExecuteContextLoader(response, testConfig.SelectSingleNode("ContextLoaderStep"), true);
}
// Validate the response...
try
{
context.ExecuteValidator(response, testConfig.SelectSingleNode("ValidationStep"), true);
}
catch (Exception e)
{
throw new ApplicationException("SOAPHTTPRequestResponseStep response stream was not correct!", e);
}
}
catch(Exception ex)
{
context.LogError("SOAPHTTPRequestResponseStep Failed");
context.LogException(ex);
throw;
}
finally
{
if (null != response)
{
response.Close();
}
if (null != request)
{
request.Close();
}
}
}
示例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)
{
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." ) );
}
}
示例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)
{
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");
}
}
示例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 msgData = null;
try
{
// Read test config...
string queuePath = context.ReadConfigAsString( testConfig, "QueuePath" );
double timeout = context.ReadConfigAsDouble( testConfig, "Timeout" );
XmlNode validationConfig = testConfig.SelectSingleNode("ValidationStep");
XmlNodeList ctxProps = testConfig.SelectNodes("ContextProperties/*");
context.LogInfo("MSMQReadStep about to read data from queue: {0}", queuePath );
var queue = new MessageQueue(queuePath);
// Receive msg from queue...
Message msg = queue.Receive(TimeSpan.FromMilliseconds(timeout), MessageQueueTransactionType.Single);
// Dump msg content to console...
msgData = StreamHelper.LoadMemoryStream(msg.BodyStream );
StreamHelper.WriteStreamToConsole("MSMQ message data", msgData, context);
// Validate data...
try
{
msgData.Seek(0, SeekOrigin.Begin);
context.ExecuteValidator( msgData, validationConfig );
}
catch(Exception e)
{
throw new ApplicationException("MSMQReadStep message data was not correct!", e);
}
if ( null != ctxProps && ctxProps.Count > 0 )
{
ProcessContextProperties( context, ctxProps, msg );
}
}
finally
{
if ( null != msgData )
{
msgData.Close();
}
}
}