Пример #1
0
        public static void RunAsyncTest(IAsyncTest test, CancellationToken ct)
        {
            Console.WriteLine("# Running {0} ...");

            using (var log = LogEnabled ? GetLogFile(test.Name) : null)
            {
                var db = GetLoggedDatabase(Db, log);

                var cts = CancellationTokenSource.CreateLinkedTokenSource(ct);
                try
                {
                    var t = test.Run(db, log ?? Console.Out, cts.Token);

                    t.GetAwaiter().GetResult();
                    Console.WriteLine("# Completed {0}.", test.Name);
                }
                catch (Exception e)
                {
                    Console.Error.WriteLine("# {0} FAILED: {1}", test.Name, e.ToString());
                }
                finally
                {
                    cts.Dispose();
                }
            }
        }
Пример #2
0
        public async Task AsyncProxyWorks()
        {
            AsyncTest  t  = new AsyncTest();
            IAsyncTest tp = AsyncFiberProxy <IAsyncTest> .Create(t);

            await tp.Init();

            await tp.Add(1);

            await tp.Subtract(2);

            await Task.Delay(100);

            Assert.IsTrue(t.Inited);
            Assert.AreEqual(-1, t.Count);
            int result = 0;

            tp.Event1 += x => result = x;

            t.Trigger();
            await Task.Delay(100);

            Assert.AreEqual(1, result);

            tp.Dispose();
            Assert.IsTrue(t.Inited);
            Assert.AreEqual(-1, t.Count);
            Assert.IsTrue(t.Disposed);
        }
Пример #3
0
		public static void RunAsyncTest(IAsyncTest test, CancellationToken ct)
		{
			Console.WriteLine("# Running {0} ...");

			using (var log = LogEnabled ? GetLogFile(test.Name) : null)
			{
				var db = GetLoggedDatabase(Db, log);

				var cts = CancellationTokenSource.CreateLinkedTokenSource(ct);
				try
				{
					var t = test.Run(db, log ?? Console.Out, cts.Token);

					t.GetAwaiter().GetResult();
					Console.WriteLine("# Completed {0}.", test.Name);
				}
				catch (Exception e)
				{
					Console.Error.WriteLine("# {0} FAILED: {1}", test.Name, e.ToString());
				}
				finally
				{
					cts.Dispose();
				}
			}
		}
Пример #4
0
 public void RunTestAsync(IAsyncTest instance, T test)
 {
     if (instance.GetMixinState <AsyncTestState>().UseLoadContext)
     {
         ExecuteInNewLoadContext(test);
     }
     else
     {
         RunTestAsync(ToFuncOfTask(test));
     }
 }
Пример #5
0
 public static void RunTestAsync(this IAsyncTest instance, Func <Task> testAsync)
 => new AsyncTestRunner().RunTestAsync(instance, testAsync);
Пример #6
0
 public static void RunTest(this IAsyncTest instance, Action test)
 => new SyncTestRunner().RunTestAsync(instance, test);