public Listener(TestRunnerEventDispatcher eventDispatcher, TappedLogger tappedLogger, LockBox <Report> reportBox) { this.eventDispatcher = eventDispatcher; this.tappedLogger = tappedLogger; this.reportBox = reportBox; states = new Dictionary <string, TestStepState>(); rootTestStepIds = new List <string>(); rootTestStepStopwatch = Stopwatch.StartNew(); rootTestStepResult = new TestResult() { Outcome = TestOutcome.Passed }; consumer = new MessageConsumer() .Handle <TestDiscoveredMessage>(HandleTestDiscoveredMessage) .Handle <AnnotationDiscoveredMessage>(HandleAnnotationDiscoveredMessage) .Handle <TestStepStartedMessage>(HandleTestStepStartedMessage) .Handle <TestStepLifecyclePhaseChangedMessage>(HandleTestStepLifecyclePhaseChangedMessage) .Handle <TestStepMetadataAddedMessage>(HandleTestStepMetadataAddedMessage) .Handle <TestStepFinishedMessage>(HandleTestStepFinishedMessage) .Handle <TestStepLogAttachMessage>(HandleTestStepLogAttachMessage) .Handle <TestStepLogStreamWriteMessage>(HandleTestStepLogStreamWriteMessage) .Handle <TestStepLogStreamEmbedMessage>(HandleTestStepLogStreamEmbedMessage) .Handle <TestStepLogStreamBeginSectionBlockMessage>(HandleTestStepLogStreamBeginSectionBlockMessage) .Handle <TestStepLogStreamBeginMarkerBlockMessage>(HandleTestStepLogStreamBeginMarkerBlockMessage) .Handle <TestStepLogStreamEndBlockMessage>(HandleTestStepLogStreamEndBlockMessage) .Handle <LogEntrySubmittedMessage>(HandleLogEntrySubmittedMessage); tappedLogger.SetListener(this); }
public void Read_WithFunc_ProvidesContents() { LockBox<int> box = new LockBox<int>(11); int actualValue = box.Read(value => value); Assert.AreEqual(11, actualValue); }
public void Write_WithAction_ProvidesContents() { LockBox<int> box = new LockBox<int>(11); int actualValue = 0; box.Write(value => actualValue = value); Assert.AreEqual(11, actualValue); }
public void UnlockingEmptiesBox() { var db = _setup(); var box = new LockBox(db, "Tbl", _criteria); Assert.True(box.Any(), "The box should not have been empty"); box.Unlock(); Assert.False(box.Any(), "The box should have been empty after unlocking it"); }
///<summary> /// Ctor. ///</summary> ///<param name="taskQueue">The task queue to use.</param> ///<param name="eventAggregator">An event aggregator.</param> ///<param name="unhandledExceptionPolicy">An exception policy.</param> public TaskRunner(ITaskQueue taskQueue, IEventAggregator eventAggregator, IUnhandledExceptionPolicy unhandledExceptionPolicy) { this.taskQueue = taskQueue; this.eventAggregator = eventAggregator; this.unhandledExceptionPolicy = unhandledExceptionPolicy; currentWorkerTasks = new LockBox <IDictionary <string, ThreadTask> >(new Dictionary <string, ThreadTask>()); }
public void Write_WithFunc_ProvidesContents() { LockBox <int> box = new LockBox <int>(11); int actualValue = box.Write(value => value); Assert.AreEqual(11, actualValue); }
///<summary> /// Ctor. ///</summary> ///<param name="taskQueue">The task queue to use.</param> ///<param name="eventAggregator">An event aggregator.</param> ///<param name="unhandledExceptionPolicy">An exception policy.</param> public TaskRunner(ITaskQueue taskQueue, IEventAggregator eventAggregator, IUnhandledExceptionPolicy unhandledExceptionPolicy) { this.taskQueue = taskQueue; this.eventAggregator = eventAggregator; this.unhandledExceptionPolicy = unhandledExceptionPolicy; currentWorkerTasks = new LockBox<IDictionary<string, ThreadTask>>(new Dictionary<string, ThreadTask>()); }
public void Read_WithAction_ProvidesContents() { LockBox <int> box = new LockBox <int>(11); int actualValue = 0; box.Read(value => actualValue = value); Assert.AreEqual(11, actualValue); }
/// <summary> /// Creates an empty registry. /// </summary> public Registry() { plugins = new Plugins(this); components = new Components(this); services = new Services(this); serviceLocator = new RegistryServiceLocator(this); resourceLocator = new RegistryResourceLocator(this); dataBox = new LockBox <RegistryData>(new RegistryData()); }
/// <summary> /// Creates an empty registry. /// </summary> public Registry() { plugins = new Plugins(this); components = new Components(this); services = new Services(this); serviceLocator = new RegistryServiceLocator(this); resourceLocator = new RegistryResourceLocator(this); dataBox = new LockBox<RegistryData>(new RegistryData()); }
public void SetsLockDate() { var db = _setup(); var rows = new LockBox(db, "Tbl", _criteria); Assert.NotNull(rows.Single()["LockDate"]); var fromDb = db.Read("Tbl", _criteria); Assert.NotNull(fromDb.Single()["LockDate"]); }
/// <summary> /// Creates a file preference set. /// </summary> /// <param name="preferenceSetFile">The preference set file.</param> /// <exception cref="ArgumentNullException">Thrown if <paramref name="preferenceSetFile"/> is null.</exception> public FilePreferenceSet(FileInfo preferenceSetFile) { if (preferenceSetFile == null) { throw new ArgumentNullException("preferenceSetFile"); } this.preferenceSetFile = preferenceSetFile; dataLockBox = new LockBox <PreferenceSetData>(new PreferenceSetData(preferenceSetFile)); }
public void CachesContents() { var db = new UnreliableDb(); _setup(db); var box = new LockBox(db, "Tbl", _criteria); Assert.True(box.Any(), "The box should not have been empty"); // Now, we'll make the database blow up if it gets accessed again db.FailOnNextOp = true; // When we access the box again, it shouldn't make the db explode Assert.True(box.Any(), "This should not blow up the box"); }
/// <summary> /// Initializes the event arguments. /// </summary> /// <param name="testPackage">The test package configuration.</param> /// <param name="testExplorationOptions">The test exploration options.</param> /// <param name="reportLockBox">The report lock-box which may be used to access the report asynchronously during execution.</param> /// <exception cref="ArgumentNullException">Thrown if <paramref name="testPackage"/> /// or <paramref name="testExplorationOptions"/> is null.</exception> public ExploreStartedEventArgs(TestPackage testPackage, TestExplorationOptions testExplorationOptions, LockBox<Report> reportLockBox) { if (testPackage == null) throw new ArgumentNullException("testPackage"); if (testExplorationOptions == null) throw new ArgumentNullException("testExplorationOptions"); this.testPackage = testPackage; this.testExplorationOptions = testExplorationOptions; this.reportLockBox = reportLockBox; }
private void WireUpTestRunnerEvents(ITestRunner testRunner) { WireUpTestStepFinished(testRunner); testRunner.Events.RunStarted += (s, e) => { reportLockBox = e.ReportLockBox; testTreeModel.UpdateTestCount(); }; testRunner.Events.ExploreStarted += (s, e) => reportLockBox = e.ReportLockBox; testRunner.Events.ExploreFinished += (s, e) => testTreeModel.UpdateTestCount(); }
public TestController(ITestTreeModel testTreeModel, IOptionsController optionsController, ITaskManager taskManager, IEventAggregator eventAggregator, IFilterService filterService) { this.testTreeModel = testTreeModel; this.optionsController = optionsController; this.taskManager = taskManager; this.eventAggregator = eventAggregator; this.filterService = filterService; testPackage = new TestPackage(); reportLockBox = new LockBox <Report>(new Report()); }
public void LocksRows() { var db = _setup(); var rows = new LockBox(db, "Tbl", _criteria); var rowLocks = rows.Select(r => r["LockId"].ToString()); foreach (var rowLock in rowLocks) Assert.AreEqual(rows.LockId, rowLock, "Expected each row to have the lockId set"); var fromDb = db.Read("Tbl", _criteria); var dbLocks = fromDb.Select(r => r["LockId"].ToString()); foreach (var dbLock in dbLocks) Assert.AreEqual(rows.LockId, dbLock, "Expected each database row to have the lockId set"); }
public void ReadersAndWritersDoNotInterfere() { LockBox <StringBuilder> box = new LockBox <StringBuilder>(new StringBuilder()); int writeCount = 0; bool done = false; for (int i = 0; i < 10; i++) { if (i % 3 != 0) { Tasks.StartThreadTask("Reader", () => { while (!done) { box.Read(value => Assert.IsTrue(value.Length % 2 == 0)); Thread.Sleep(0); } }); } else { Tasks.StartThreadTask("Writer", () => { while (!done) { box.Write(value => { Assert.IsTrue(value.Length % 2 == 0); value.Append('x'); Thread.Sleep(1); Assert.IsTrue(value.Length % 2 == 1); value.Append('x'); writeCount += 1; }); } }); } } Thread.Sleep(200); done = true; Tasks.JoinAndVerify(new TimeSpan(0, 0, 1)); box.Read(value => Assert.AreEqual(writeCount * 2, value.Length)); }
/// <summary> /// Initializes the event arguments. /// </summary> /// <param name="testPackage">The test package configuration.</param> /// <param name="testExplorationOptions">The test exploration options.</param> /// <param name="reportLockBox">The report lock-box which may be used to access the report asynchronously during execution.</param> /// <exception cref="ArgumentNullException">Thrown if <paramref name="testPackage"/> /// or <paramref name="testExplorationOptions"/> is null.</exception> public ExploreStartedEventArgs(TestPackage testPackage, TestExplorationOptions testExplorationOptions, LockBox <Report> reportLockBox) { if (testPackage == null) { throw new ArgumentNullException("testPackage"); } if (testExplorationOptions == null) { throw new ArgumentNullException("testExplorationOptions"); } this.testPackage = testPackage; this.testExplorationOptions = testExplorationOptions; this.reportLockBox = reportLockBox; }
public void WontLockLockedRows() { var db = _setup(); var rows = new LockBox(db, "Tbl", _criteria); Assert.AreNotEqual(0, rows.Count(), "We should have found rows on the first lock"); var rows2 = new LockBox(db, "Tbl", _criteria); Assert.AreEqual(0, rows2.Count(), "We shouldn't have found any rows on the second lock"); }
public void Write_WhenFuncIsNull_Throws() { LockBox <int> box = new LockBox <int>(11); Assert.Throws <ArgumentNullException>(() => box.Write <object>(null)); }
public void Read_WhenActionIsNull_Throws() { LockBox <int> box = new LockBox <int>(11); Assert.Throws <ArgumentNullException>(() => box.Read(null)); }
void Lock_Click(object sender, RoutedEventArgs e) { LockBox a = new LockBox(Recorder.LockPassword.Text); a.Show(); }
private void OnEnable() { _lockBox = GetComponent <LockBox>(); _lockBox.Opened += OnComplete; }
public Listener(TestRunnerEventDispatcher eventDispatcher, TappedLogger tappedLogger, LockBox<Report> reportBox) { this.eventDispatcher = eventDispatcher; this.tappedLogger = tappedLogger; this.reportBox = reportBox; states = new Dictionary<string, TestStepState>(); rootTestStepIds = new List<string>(); rootTestStepStopwatch = Stopwatch.StartNew(); rootTestStepResult = new TestResult() { Outcome = TestOutcome.Passed }; consumer = new MessageConsumer() .Handle<TestDiscoveredMessage>(HandleTestDiscoveredMessage) .Handle<AnnotationDiscoveredMessage>(HandleAnnotationDiscoveredMessage) .Handle<TestStepStartedMessage>(HandleTestStepStartedMessage) .Handle<TestStepLifecyclePhaseChangedMessage>(HandleTestStepLifecyclePhaseChangedMessage) .Handle<TestStepMetadataAddedMessage>(HandleTestStepMetadataAddedMessage) .Handle<TestStepFinishedMessage>(HandleTestStepFinishedMessage) .Handle<TestStepLogAttachMessage>(HandleTestStepLogAttachMessage) .Handle<TestStepLogStreamWriteMessage>(HandleTestStepLogStreamWriteMessage) .Handle<TestStepLogStreamEmbedMessage>(HandleTestStepLogStreamEmbedMessage) .Handle<TestStepLogStreamBeginSectionBlockMessage>(HandleTestStepLogStreamBeginSectionBlockMessage) .Handle<TestStepLogStreamBeginMarkerBlockMessage>(HandleTestStepLogStreamBeginMarkerBlockMessage) .Handle<TestStepLogStreamEndBlockMessage>(HandleTestStepLogStreamEndBlockMessage) .Handle<LogEntrySubmittedMessage>(HandleLogEntrySubmittedMessage); tappedLogger.SetListener(this); }
public void ReadersAndWritersDoNotInterfere() { LockBox<StringBuilder> box = new LockBox<StringBuilder>(new StringBuilder()); int writeCount = 0; bool done = false; for (int i = 0; i < 10; i++) { if (i % 3 != 0) { Tasks.StartThreadTask("Reader", () => { while (! done) { box.Read(value => Assert.IsTrue(value.Length%2 == 0)); Thread.Sleep(0); } }); } else { Tasks.StartThreadTask("Writer", () => { while (!done) { box.Write(value => { Assert.IsTrue(value.Length%2 == 0); value.Append('x'); Thread.Sleep(1); Assert.IsTrue(value.Length%2 == 1); value.Append('x'); writeCount += 1; }); } }); } } Thread.Sleep(200); done = true; Tasks.JoinAndVerify(new TimeSpan(0, 0, 1)); box.Read(value => Assert.AreEqual(writeCount * 2, value.Length)); }
public void Read_WhenActionIsNull_Throws() { LockBox<int> box = new LockBox<int>(11); Assert.Throws<ArgumentNullException>(() => box.Read(null)); }
/// <inheritdoc /> public Report Run(TestPackage testPackage, TestExplorationOptions testExplorationOptions, TestExecutionOptions testExecutionOptions, IProgressMonitor progressMonitor) { if (testPackage == null) throw new ArgumentNullException("testPackageConfig"); if (testExplorationOptions == null) throw new ArgumentNullException("testExplorationOptions"); if (testExecutionOptions == null) throw new ArgumentNullException("testExecutionOptions"); if (progressMonitor == null) throw new ArgumentNullException("progressMonitor"); ThrowIfDisposed(); if (state != State.Initialized) throw new InvalidOperationException("The test runner must be initialized before this operation is performed."); testPackage = testPackage.Copy(); testExplorationOptions = testExplorationOptions.Copy(); testExecutionOptions = testExecutionOptions.Copy(); GenericCollectionUtils.ForEach(testRunnerOptions.Properties, x => testPackage.AddProperty(x.Key, x.Value)); using (progressMonitor.BeginTask("Running the tests.", 10)) { Stopwatch stopwatch = Stopwatch.StartNew(); Report report = new Report() { TestPackage = new TestPackageData(testPackage), TestModel = new TestModelData(), TestPackageRun = new TestPackageRun() { StartTime = DateTime.Now } }; var reportLockBox = new LockBox<Report>(report); eventDispatcher.NotifyRunStarted(new RunStartedEventArgs(testPackage, testExplorationOptions, testExecutionOptions, reportLockBox)); bool success; using (Listener listener = new Listener(eventDispatcher, tappedLogger, reportLockBox)) { try { ITestDriver testDriver = testFrameworkManager.GetTestDriver( testPackage.CreateTestFrameworkSelector(), tappedLogger); using (testIsolationContext.BeginBatch(progressMonitor.SetStatus)) { testDriver.Run(testIsolationContext, testPackage, testExplorationOptions, testExecutionOptions, listener, progressMonitor.CreateSubProgressMonitor(10)); } success = true; } catch (Exception ex) { success = false; tappedLogger.Log(LogSeverity.Error, "A fatal exception occurred while running tests. Possible causes include invalid test runner parameters and stack overflows.", ex); report.TestModel.Annotations.Add(new AnnotationData(AnnotationType.Error, CodeLocation.Unknown, CodeReference.Unknown, "A fatal exception occurred while running tests. See log for details.", null)); } finally { report.TestPackageRun.EndTime = DateTime.Now; report.TestPackageRun.Statistics.Duration = stopwatch.Elapsed.TotalSeconds; } } eventDispatcher.NotifyRunFinished(new RunFinishedEventArgs(success, report)); return report; } }
public void Write_WhenFuncIsNull_Throws() { LockBox<int> box = new LockBox<int>(11); Assert.Throws<ArgumentNullException>(() => box.Write<object>(null)); }
public void UsingBlockClearsLock() { var db = _setup(); using (var rows = new LockBox(db, "Tbl", _criteria)) { Assert.AreNotEqual(0, rows.Count(), "We should have found rows"); } var rows2 = new LockBox(db, "Tbl", _criteria); Assert.AreNotEqual(0, rows2.Count(), "The old lock went out of scope, so we should find rows here - they should be unlocked"); }
/// <inheritdoc /> public Report Run(TestPackage testPackage, TestExplorationOptions testExplorationOptions, TestExecutionOptions testExecutionOptions, IProgressMonitor progressMonitor) { if (testPackage == null) { throw new ArgumentNullException("testPackageConfig"); } if (testExplorationOptions == null) { throw new ArgumentNullException("testExplorationOptions"); } if (testExecutionOptions == null) { throw new ArgumentNullException("testExecutionOptions"); } if (progressMonitor == null) { throw new ArgumentNullException("progressMonitor"); } ThrowIfDisposed(); if (state != State.Initialized) { throw new InvalidOperationException("The test runner must be initialized before this operation is performed."); } testPackage = testPackage.Copy(); testExplorationOptions = testExplorationOptions.Copy(); testExecutionOptions = testExecutionOptions.Copy(); GenericCollectionUtils.ForEach(testRunnerOptions.Properties, x => testPackage.AddProperty(x.Key, x.Value)); using (progressMonitor.BeginTask("Running the tests.", 10)) { Stopwatch stopwatch = Stopwatch.StartNew(); Report report = new Report() { TestPackage = new TestPackageData(testPackage), TestModel = new TestModelData(), TestPackageRun = new TestPackageRun() { StartTime = DateTime.Now } }; var reportLockBox = new LockBox <Report>(report); eventDispatcher.NotifyRunStarted(new RunStartedEventArgs(testPackage, testExplorationOptions, testExecutionOptions, reportLockBox)); bool success; using (Listener listener = new Listener(eventDispatcher, tappedLogger, reportLockBox)) { try { ITestDriver testDriver = testFrameworkManager.GetTestDriver( testPackage.CreateTestFrameworkSelector(), tappedLogger); using (testIsolationContext.BeginBatch(progressMonitor.SetStatus)) { testDriver.Run(testIsolationContext, testPackage, testExplorationOptions, testExecutionOptions, listener, progressMonitor.CreateSubProgressMonitor(10)); } success = true; } catch (Exception ex) { success = false; tappedLogger.Log(LogSeverity.Error, "A fatal exception occurred while running tests. Possible causes include invalid test runner parameters and stack overflows.", ex); report.TestModel.Annotations.Add(new AnnotationData(AnnotationType.Error, CodeLocation.Unknown, CodeReference.Unknown, "A fatal exception occurred while running tests. See log for details.", null)); } finally { report.TestPackageRun.EndTime = DateTime.Now; report.TestPackageRun.Statistics.Duration = stopwatch.Elapsed.TotalSeconds; } } eventDispatcher.NotifyRunFinished(new RunFinishedEventArgs(success, report)); return(report); } }