Esempio n. 1
0
            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);
            }
Esempio n. 2
0
        public void Read_WithFunc_ProvidesContents()
        {
            LockBox<int> box = new LockBox<int>(11);

            int actualValue = box.Read(value => value);
            Assert.AreEqual(11, actualValue);
        }
Esempio n. 3
0
        public void Write_WithAction_ProvidesContents()
        {
            LockBox<int> box = new LockBox<int>(11);

            int actualValue = 0;
            box.Write(value => actualValue = value);
            Assert.AreEqual(11, actualValue);
        }
Esempio n. 4
0
 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");
 }
Esempio n. 5
0
 ///<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>());
 }
Esempio n. 6
0
        public void Write_WithFunc_ProvidesContents()
        {
            LockBox <int> box = new LockBox <int>(11);

            int actualValue = box.Write(value => value);

            Assert.AreEqual(11, actualValue);
        }
Esempio n. 7
0
 ///<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>());
 }
Esempio n. 8
0
        public void Read_WithAction_ProvidesContents()
        {
            LockBox <int> box = new LockBox <int>(11);

            int actualValue = 0;

            box.Read(value => actualValue = value);
            Assert.AreEqual(11, actualValue);
        }
Esempio n. 9
0
        /// <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());
        }
Esempio n. 10
0
        /// <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());
        }
Esempio n. 11
0
        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"]);
        }
Esempio n. 12
0
        /// <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));
        }
Esempio n. 13
0
 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;
        }
Esempio n. 15
0
        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();
        }
Esempio n. 16
0
        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());
        }
Esempio n. 17
0
        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");
        }
Esempio n. 18
0
        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));
        }
Esempio n. 19
0
        /// <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;
        }
Esempio n. 20
0
        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");
        }
Esempio n. 21
0
        public void Write_WhenFuncIsNull_Throws()
        {
            LockBox <int> box = new LockBox <int>(11);

            Assert.Throws <ArgumentNullException>(() => box.Write <object>(null));
        }
Esempio n. 22
0
        public void Read_WhenActionIsNull_Throws()
        {
            LockBox <int> box = new LockBox <int>(11);

            Assert.Throws <ArgumentNullException>(() => box.Read(null));
        }
Esempio n. 23
0
        void Lock_Click(object sender, RoutedEventArgs e)
        {
            LockBox a = new LockBox(Recorder.LockPassword.Text);

            a.Show();
        }
Esempio n. 24
0
 private void OnEnable()
 {
     _lockBox         = GetComponent <LockBox>();
     _lockBox.Opened += OnComplete;
 }
Esempio n. 25
0
            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);
            }
Esempio n. 26
0
        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));
        }
Esempio n. 27
0
        public void Read_WhenActionIsNull_Throws()
        {
            LockBox<int> box = new LockBox<int>(11);

            Assert.Throws<ArgumentNullException>(() => box.Read(null));
        }
Esempio n. 28
0
        /// <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;
            }
        }
Esempio n. 29
0
        public void Write_WhenFuncIsNull_Throws()
        {
            LockBox<int> box = new LockBox<int>(11);

            Assert.Throws<ArgumentNullException>(() => box.Write<object>(null));
        }
Esempio n. 30
0
        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");
        }
Esempio n. 31
0
        /// <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);
            }
        }