Пример #1
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="log"></param>
 /// <param name="testId"></param>
 /// <param name="sourcePath"></param>
 /// <param name="outputPath"></param>
 /// <param name="errorCounter"></param>
 public static void FormatXml(ITestLog log, string testId,
                              string sourcePath, string outputPath,
                              Counter errorCounter)
 {
     log.LogInfo($"    FormatXml: sourcePath={sourcePath}", testId);
     log.LogInfo($"    FormatXml: outputPath={outputPath}", testId);
     try
     {
         var sampleDoc = new XmlDocument();
         using (var xr = new XmlTextReader(sourcePath))
         {
             sampleDoc.Load(xr);
         }
         var xws = new XmlWriterSettings {
             Indent = true, Encoding = Encoding.UTF8
         };
         using (XmlWriter xw = XmlWriter.Create(outputPath, xws))
         {
             sampleDoc.Save(xw);
         }
     }
     catch (Exception excp)
     {
         errorCounter.Inc();
         log.LogException(excp, testId, false);
     }
 }
Пример #2
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="log"></param>
 /// <param name="testId"></param>
 /// <param name="xmlDocPath"></param>
 /// <param name="schemaSet"></param>
 /// <param name="errorCounter"></param>
 /// <param name="warningCounter"></param>
 public static void ValidateXml(
     ITestLog log, string testId,
     string xmlDocPath, XmlSchemaSet schemaSet,
     Counter errorCounter, Counter warningCounter)
 {
     log.LogInfo($"    ValidateXml: xmlDocPath={xmlDocPath}", testId);
     //log.LogInfo(String.Format("    ValidateXml: outputPath={0}", outputPath ?? "(null)"), testId);
     using (var stream = new FileStream(xmlDocPath, FileMode.Open, FileAccess.Read))
     {
         var sampleDoc = new XmlDocument();
         sampleDoc.Schemas.Add(schemaSet);
         sampleDoc.Load(stream);
         sampleDoc.Validate((o, e) =>
         {
             if (e.Severity == XmlSeverityType.Error)
             {
                 errorCounter.Inc();
             }
             else
             {
                 warningCounter.Inc();
             }
             log.LogError($"Validation {e.Severity}: {e.Message}", testId, false);
             log.LogException(e.Exception, testId, false);
         });
     }
 }
Пример #3
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="log"></param>
 /// <param name="testId"></param>
 /// <param name="pathA"></param>
 /// <param name="pathB"></param>
 /// <param name="errorCounter"></param>
 public static void CompareXml(ITestLog log, string testId, string pathA, string pathB, Counter errorCounter)
 {
     log.LogInfo($"    CompareXml: pathA={pathA}", testId);
     log.LogInfo($"    CompareXml: pathB={pathB}", testId);
     try
     {
         // load original into xml doc
         var docA = new XmlDocument();
         using (var fs = new FileStream(pathA, FileMode.Open, FileAccess.Read))
             using (var sr = new StreamReader(fs, Encoding.UTF8))
             {
                 docA.Load(sr);
             }
         // load emitted stream into xml doc
         var docB = new XmlDocument();
         using (var stream = new FileStream(pathB, FileMode.Open, FileAccess.Read))
         {
             docB.Load(stream);
         }
         // compare
         XmlCompare.CompareXmlDocs(docA, docB);
     }
     catch (Exception excp)
     {
         errorCounter.Inc();
         log.LogException(excp, testId, false);
     }
 }
Пример #4
0
        protected override void WriteToOutput(LogLevel logLevel, string text)
        {
            ITestLog ltmLog = GetLtmLog();

            switch (logLevel)
            {
            case LogLevel.Warning:
                // UGH!!!!!
                ltmLog.Error(TestResult.Warning, TestLogFlags.Text, null, null, null, text, null, null, 0);
                break;

            case LogLevel.Error:
                // UGH!!!!!
                ltmLog.Error(TestResult.Exception, TestLogFlags.Text, null, null, null, text, null, null, 0);
                break;

            case LogLevel.Trace:
            case LogLevel.Verbose:
                ltmLog.WriteLine(TestLogFlags.Ignore, text);
                break;

            default:
            case LogLevel.Info:
                ltmLog.WriteLine(TestLogFlags.Text, text);
                break;
            }
        }
Пример #5
0
 private ITestLog GetLtmLog()
 {
     if (this.testLog == null)
     {
         this.testLog = (ITestLog) new LtmContext();
     }
     return(this.testLog);
 }
Пример #6
0
		static internal	void			Dispose()
		{
		    //Reset the info.  
		    _internal			= null;
            if(_asserthandler != null)
                Debug.Listeners.Remove(_asserthandler);
		    _asserthandler      = null;
		}
Пример #7
0
 static internal void                    Dispose()
 {
     //Reset the info.
     _internal = null;
     if (_asserthandler != null)
     {
         Debug.Listeners.Remove(_asserthandler);
     }
     _asserthandler = null;
 }
Пример #8
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="log"></param>
 /// <param name="testId"></param>
 /// <param name="transformer"></param>
 /// <param name="sourcePath"></param>
 /// <param name="targetPath"></param>
 /// <param name="errorCounter"></param>
 public static void TransformXml(ITestLog log, string testId, IXmlTransformer transformer, string sourcePath, string targetPath, Counter errorCounter)
 {
     log.LogInfo($"    TransformXml: sourcePath={sourcePath}", testId);
     log.LogInfo($"    TransformXml: targetPath={targetPath}", testId);
     try
     {
         transformer.Transform(sourcePath, targetPath);
     }
     catch (Exception excp)
     {
         errorCounter.Inc();
         log.LogException(excp, testId, false);
     }
 }
Пример #9
0
        public void Run(int n, ITestLog log)
        {
            var path = Path.GetFullPath(".\\test-" + Guid.NewGuid().ToString("n") + ".kiwidb");

            try
            {
                log.Start();
                n = Test(new Collection(path), n);
                log.Stop(n);
            }
            finally
            {
                File.Delete(path);
            }
        }
Пример #10
0
        internal void HandleException(Exception ex, TestResult result)
        {
            ITestLog ltmLog = GetLtmLog();

            while (ex != null)
            {
                DataComparisonException mex = ex as DataComparisonException;
                object expected             = null;
                object actual = null;
                if (mex != null)
                {
                    actual   = mex.ActualValue;
                    expected = mex.ExpectedValue;
                }

                ltmLog.Error(result, TestLogFlags.Text, ToStringConverter.ConvertObjectToString(actual), ToStringConverter.ConvertObjectToString(expected), ex.Source, ex.Message, ex.StackTrace, null, 0);
                ex = ex.InnerException;
            }
        }
Пример #11
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="log"></param>
 /// <param name="testId"></param>
 /// <param name="typeDetector"></param>
 /// <param name="sourcePath"></param>
 /// <param name="errorCounter"></param>
 /// <returns></returns>
 public static object DeserialiseXml(ITestLog log, string testId, Func <string, Type> typeDetector, string sourcePath, Counter errorCounter)
 {
     log.LogInfo($"    DeserialiseXml: sourcePath={sourcePath}", testId);
     try
     {
         Type autoDetectedType = typeDetector(sourcePath);
         var  xs = new XmlSerializer(autoDetectedType);
         using (var xr = new XmlTextReader(sourcePath))
         {
             return(xs.Deserialize(xr));
         }
     }
     catch (Exception excp)
     {
         errorCounter.Inc();
         log.LogException(excp, testId, false);
         return(null);
     }
 }
Пример #12
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="log"></param>
 /// <param name="testId"></param>
 /// <param name="fpml"></param>
 /// <param name="outputPath"></param>
 /// <param name="errorCounter"></param>
 public static void SerialiseXml(ITestLog log, string testId, object fpml, string outputPath, Counter errorCounter)
 {
     log.LogInfo($"    SerialiseXml: outputPath={outputPath}", testId);
     try
     {
         var xs  = new XmlSerializer(fpml.GetType());
         var xws = new XmlWriterSettings {
             Indent = true, Encoding = Encoding.UTF8
         };
         using (var xw = XmlWriter.Create(outputPath, xws))
         //using (var fs = new FileStream(outputPath, FileMode.Create, FileAccess.Write))
         //using (var xw = new XmlTextWriter(fs, Encoding.UTF8))
         {
             xs.Serialize(xw, fpml);
         }
     }
     catch (Exception excp)
     {
         errorCounter.Inc();
         log.LogException(excp, testId, false);
     }
 }
Пример #13
0
 internal void InitLogger()
 {
     this.Log = Utility.InitLog();
     Utility.SetLogPath(string.Empty);
     Log.Info("App Started");
 }
Пример #14
0
 internal static void Dispose()
 {
     //Reset the info.
     s_pinternal      = null;
     s_passerthandler = null;
 }
Пример #15
0
 internal static void Dispose()
 {
     //Reset the info.  
     s_pinternal = null;
     s_passerthandler = null;
 }
Пример #16
0
 private ITestLog GetLtmLog()
 {
     if (this.testLog == null)
         this.testLog = (ITestLog)new LtmContext();
     return this.testLog;
 }
 /// <summary>
 /// Constructs a test manager base, with given test site, maximal sizes for event and return queue.
 /// </summary>
 /// <param name="log">Test case log.</param>
 /// <param name="maxEventQueueSize">Maximal size for event queue. Not implemented yet.</param>
 /// <param name="maxReturnQueueSize">Maximal size for return queue. Not implemented yet.</param>
 public ProtocolTestsManager(ITestLog log, int maxEventQueueSize, int maxReturnQueueSize)
 {
     this.Log    = log;
     eventQueue  = new ObservationQueue <AvailableEvent>(maxEventQueueSize);
     returnQueue = new ObservationQueue <AvailableReturn>(maxReturnQueueSize);
 }
Пример #18
0
 public ValuesController(ILogger <ValuesController> logger, ITestLog testLog)
 {
     testLog.Log();
     _logger = logger;
 }