public void ThreadsDoNotShareLogicalOperationsStack()
        {
            CrossThreadTestRunner t = new CrossThreadTestRunner(new ThreadStart(this.DoOtherThreadWork));

            t.Run();

            Assert.AreEqual(0, Trace.CorrelationManager.LogicalOperationStack.Count);
            Assert.IsFalse(testActivityId1 == Trace.CorrelationManager.ActivityId);
        }
Esempio n. 2
0
 /// <summary>
 /// Exports the model in a STA.
 /// </summary>
 /// <param name="e">The exporter.</param>
 /// <param name="stream">The output stream.</param>
 /// <param name="visual">The visual to export.</param>
 protected void ExportModel(IExporter e, Stream stream, Func <Visual3D> visual)
 {
     CrossThreadTestRunner.RunInSTA(
         () =>
     {
         var vp = new Viewport3D {
             Camera = CameraHelper.CreateDefaultCamera(), Width = 1280, Height = 720
         };
         vp.Children.Add(new DefaultLights());
         vp.Children.Add(visual());
         e.Export(vp, stream);
     });
 }
Esempio n. 3
0
        /// <summary>
        /// Exports a simple model in a STA.
        /// </summary>
        /// <param name="e">The exporter.</param>
        /// <param name="stream">The stream.</param>
        protected void ExportSimpleModel(IExporter e, Stream stream)
        {
            CrossThreadTestRunner.RunInSTA(
                () =>
            {
                var vp = new Viewport3D {
                    Camera = CameraHelper.CreateDefaultCamera(), Width = 1280, Height = 720
                };
                vp.Children.Add(new DefaultLights());
                var box = new BoxVisual3D();
                box.UpdateModel();
                vp.Children.Add(box);

                e.Export(vp, stream);
            });
        }
Esempio n. 4
0
        protected void ExportSimpleModel(Exporter e)
        {
            var runner = new CrossThreadTestRunner();

            runner.RunInSTA(
                delegate
            {
                Console.WriteLine(Thread.CurrentThread.GetApartmentState());

                var vp = new Viewport3D {
                    Camera = CameraHelper.CreateDefaultCamera(), Width = 1280, Height = 720
                };
                vp.Children.Add(new DefaultLights());
                var box = new BoxVisual3D();
                box.UpdateModel();
                vp.Children.Add(box);

                e.Export(vp);
            });
        }
Esempio n. 5
0
        public void ActivityIdsAreUniqueOnEachThread()
        {
            // This will put two events into the sink using testCategory2 and testActivityId2
            using (new Tracer(Context, testCategory2, testActivityId2))
            {
                // This will put two events into the sink using testCategory1 and testActivityId1
                CrossThreadTestRunner t = new CrossThreadTestRunner(new ThreadStart(this.DoOtherThreadWork));
                t.Run();

                // Confirm that the Tracer on this thread has the expected activityID
                Assert.AreEqual(testActivityId2, Tracer.CurrentActivityId);
            }

            Assert.AreEqual(null, Tracer.CurrentActivityId);

            Assert.AreEqual(4, MockLogSink.Count);
            AssertLogEntryIsValid(MockLogSink.GetEntry(0), Tracer.startTitle, testCategory2, testActivityId2, true);
            AssertLogEntryIsValid(MockLogSink.GetEntry(1), Tracer.startTitle, testCategory1, testActivityId1, true);
            AssertLogEntryIsValid(MockLogSink.GetEntry(2), Tracer.endTitle, testCategory1, testActivityId1, false);
            AssertLogEntryIsValid(MockLogSink.GetEntry(3), Tracer.endTitle, testCategory2, testActivityId2, false);
        }
        public void CreatePositions_CoincidingPoints_ShouldNotReturnNaN()
        {
            Point3DCollection result = null;

            CrossThreadTestRunner.RunInSTA(
                () =>
            {
                var vp     = new Viewport3D();
                var visual = new ModelVisual3D();
                vp.Children.Add(visual);

                var b = new LineGeometryBuilder(visual);
                b.UpdateTransforms();
                result = b.CreatePositions(new[] { new Point3D(0, 0, 0), new Point3D(0, 0, 0) });
            });

            for (int i = 0; i < result.Count; i++)
            {
                Assert.IsTrue(
                    !double.IsNaN(result[i].X) && !double.IsNaN(result[i].Y) && !double.IsNaN(result[i].Z),
                    "Point " + i + " is invalid");
            }
        }
Esempio n. 7
0
 public void SetUp()
 {
     _runner = new CrossThreadTestRunner();
 }
Esempio n. 8
0
		public void TablesUniquelyNamedOnlyWithinThread()
		{
			var uniqueIntegerList = new System.Collections.Concurrent.ConcurrentBag<int>();
			var method = new ThreadStart(() =>
			                             {
				                             Table tbl1 = new Table();
				                             Table tbl2 = new Table();

				                             // Store these values for later comparison
				                             uniqueIntegerList.Add(tbl1.UniqueInteger);
				                             uniqueIntegerList.Add(tbl2.UniqueInteger);

				                             // Ensure that within a thread we have unique integers
				                             Assert.AreEqual(tbl1.UniqueInteger + 1, tbl2.UniqueInteger);
			                             });

			var thread1 = new CrossThreadTestRunner(method);
			var thread2 = new CrossThreadTestRunner(method);

			thread1.Start();
			thread2.Start();

			thread1.Join();
			thread2.Join();

			// There should in total be 4 tables, but only two distinct identifiers.
			Assert.AreEqual(4, uniqueIntegerList.Count);
			Assert.AreEqual(2, uniqueIntegerList.Distinct().Count());
		}