public void IAsyncOperation_StartAsTask_Error()
		{
			var error = new Exception("error");
			var operation = new MockAsyncOperation<bool>();
			Task<bool> t = operation.StartAsTask();

			operation.ErrorCode = error;
			operation.Status = AsyncStatus.Error;
			operation.Completed (operation);

			Assert.IsTrue (t.IsFaulted);
			Assert.AreSame (error, t.Exception.InnerExceptions.First());
			Assert.Throws<AggregateException>(() => t.Wait());
		}
		public void IAsyncOperation_StartAsTask_Completed()
		{
			var operation = new MockAsyncOperation<bool>();
			Task<bool> t = operation.StartAsTask();

			operation.Result = true;
			operation.Status = AsyncStatus.Completed;
			operation.Completed (operation);

			Assert.AreEqual (TaskStatus.RanToCompletion, t.Status);
			Assert.AreEqual (true, t.Result);
		}
		public void IAsyncOperation_StartAsTask_StartStatus()
		{
			var operation = new MockAsyncOperation<bool>();
			Task<bool> t = operation.StartAsTask();

			Assert.AreEqual (TaskStatus.WaitingForActivation, t.Status);
			Assert.AreEqual (AsyncStatus.Started, operation.Status);
		}
		public void IAsyncOperation_StartAsTask_Canceled()
		{
			var action = new MockAsyncOperation<bool>();
			Task<bool> t = action.StartAsTask();

			action.Cancel();

			Assert.Throws<AggregateException>(() => t.Wait());
			Assert.AreEqual (TaskStatus.Canceled, t.Status);
		}
		public void IAsyncOperation_StartAsTask_CreatedOnly()
		{
			var operation = new MockAsyncOperation<bool>();

			operation.Status = AsyncStatus.Error;
			Assert.Throws<InvalidOperationException>(() => operation.StartAsTask());

			operation.Status = AsyncStatus.Started;
			Assert.Throws<InvalidOperationException>(() => operation.StartAsTask());

			operation.Status = AsyncStatus.Completed;
			Assert.Throws<InvalidOperationException>(() => operation.StartAsTask());

			operation.Status = AsyncStatus.Canceled;
			Assert.Throws<InvalidOperationException>(() => operation.StartAsTask());
		}