private void MakeTestRunComplete(TestableTrxLogger testableTrxLogger) { var pass = TrxLoggerTests.CreatePassTestResultEventArgsMock(); testableTrxLogger.TestResultHandler(new object(), pass.Object); var testRunCompleteEventArgs = TrxLoggerTests.CreateTestRunCompleteEventArgs(); testableTrxLogger.TestRunCompleteHandler(new object(), testRunCompleteEventArgs); }
public void Initialize() { this.events = new Mock <TestLoggerEvents>(); this.testableTrxLogger = new TestableTrxLogger(); this.parameters = new Dictionary <string, string>(2); this.parameters[DefaultLoggerParameterNames.TestRunDirectory] = TrxLoggerTests.DefaultTestRunDirectory; this.parameters[TrxLoggerConstants.LogFileNameKey] = TrxLoggerTests.DefaultLogFileNameParameterValue; this.testableTrxLogger.Initialize(this.events.Object, this.parameters); }
public void DefaultTrxFileNameVerification() { this.parameters.Remove(TrxLoggerConstants.LogFileNameKey); this.parameters[TrxLoggerConstants.LogFilePrefixKey] = DefaultLogFilePrefixParameterValue; var time = DateTime.Now; var trxFileHelper = new TrxFileHelper(() => time); testableTrxLogger = new TestableTrxLogger(new FileHelper(), trxFileHelper); testableTrxLogger.Initialize(this.events.Object, this.parameters); MakeTestRunComplete(); var fileName = Path.GetFileName(testableTrxLogger.trxFile); var expectedName = $"{DefaultLogFilePrefixParameterValue}{time:_yyyyMMddHHmmss}.trx"; Assert.AreEqual(expectedName, fileName, "Trx file name pattern has changed. It should be in the form of prefix_yyyyMMddHHmmss.trx, Azure Devops VSTest task depends on this naming."); }
private string[] TestMultipleTrxLoggers() { var files = new string[2]; try { var time = new DateTime(2020, 1, 1, 0, 0, 0); var trxFileHelper = new TrxFileHelper(() => time); var trxLogger1 = new TestableTrxLogger(new FileHelper(), trxFileHelper); var trxLogger2 = new TestableTrxLogger(new FileHelper(), trxFileHelper); trxLogger1.Initialize(this.events.Object, this.parameters); trxLogger2.Initialize(this.events.Object, this.parameters); MakeTestRunComplete(trxLogger1); files[0] = trxLogger1.trxFile; MakeTestRunComplete(trxLogger2); files[1] = trxLogger2.trxFile; } finally { files = files .Where(i => !string.IsNullOrWhiteSpace(i)) .Distinct() .ToArray(); foreach (var file in files) { if (!string.IsNullOrEmpty(file) && File.Exists(file)) { File.Delete(file); } } } return(files); }