Exemple #1
0
        public void CreateTResult_With_CancellationToken_Should_Succeed()
        {
            var source = UnsafeCompletionSource <int> .Create(new CancellationToken());

            Assert.That(source.ResultTask, Is.Not.Null);
            Assert.That(source.ResultTask.Status, Is.EqualTo(PandaTaskStatus.Pending));
        }
Exemple #2
0
        public void TrySetError_Should_Not_RejectTask_WithDefaultException()
        {
            var source = UnsafeCompletionSource.Create();

            source.SetError();
            Assert.IsFalse(source.TrySetError());
        }
Exemple #3
0
        public void TryCancelTaskTResult_Should_Not_RejectTask()
        {
            var source = UnsafeCompletionSource <int> .Create();

            source.CancelTask();
            Assert.IsFalse(source.TryCancelTask());
        }
Exemple #4
0
        public void TrySetValueTResult_Should_Not_ResolveTask()
        {
            var source = UnsafeCompletionSource <int> .Create();

            source.SetValue(123);
            Assert.IsFalse(source.TrySetValue(123));
        }
Exemple #5
0
        public void TryResolve_Should_Not_ResolveTask()
        {
            var source = UnsafeCompletionSource.Create();

            source.Resolve();
            Assert.IsFalse(source.TryResolve());
        }
Exemple #6
0
        public void Create_Should_Succeed()
        {
            var source = UnsafeCompletionSource.Create();

            Assert.That(source.Task, Is.Not.Null);
            Assert.That(source.Task.Status, Is.EqualTo(PandaTaskStatus.Pending));
        }
Exemple #7
0
        public void TrySetErrorTResult_Should_RejectTask_WithDefaultException()
        {
            var source = UnsafeCompletionSource <int> .Create();

            Assert.IsTrue(source.TrySetError());
            Assert.That(source.ResultTask.Status, Is.EqualTo(PandaTaskStatus.Rejected));
            Assert.That(source.ResultTask.Error, Is.InstanceOf <TaskRejectedException>());
        }
Exemple #8
0
        public void Resolve_Should_ResolveTask()
        {
            var source = UnsafeCompletionSource.Create();

            source.Resolve();

            Assert.That(source.Task.Status, Is.EqualTo(PandaTaskStatus.Resolved));
        }
Exemple #9
0
        public void TrySetError_Should_Not_RejectTask_WithSpecificException()
        {
            var source    = UnsafeCompletionSource.Create();
            var exception = new ArgumentException();

            source.SetError(exception);
            Assert.IsFalse(source.TrySetError(exception));
        }
Exemple #10
0
        public void CancelTaskTResult_Should_RejectTask_WithTaskCancelled()
        {
            var source = UnsafeCompletionSource <int> .Create();

            source.CancelTask();

            Assert.That(source.ResultTask.Status, Is.EqualTo(PandaTaskStatus.Rejected));
            Assert.That(source.ResultTask.Error, Is.InstanceOf <TaskCanceledException>());
        }
Exemple #11
0
        public void SetValueTResult_Should_ResolveTask()
        {
            var source = UnsafeCompletionSource <int> .Create();

            source.SetValue(123);

            Assert.That(source.ResultTask.Status, Is.EqualTo(PandaTaskStatus.Resolved));
            Assert.That(source.ResultTask.Result, Is.EqualTo(123));
        }
Exemple #12
0
        public void TryResolve_Should_ResolveTask()
        {
            var source = UnsafeCompletionSource.Create();

            var result = source.TryResolve();

            Assert.IsTrue(result);
            Assert.That(source.Task.Status, Is.EqualTo(PandaTaskStatus.Resolved));
        }
Exemple #13
0
        public void TrySetError_Should_RejectTask_WithSpecificException()
        {
            var source    = UnsafeCompletionSource.Create();
            var exception = new ArgumentException();

            Assert.IsTrue(source.TrySetError(exception));
            Assert.That(source.Task.Status, Is.EqualTo(PandaTaskStatus.Rejected));
            Assert.That(source.Task.Error, Is.EqualTo(exception));
        }
Exemple #14
0
        public void CancelTaskTResult_Should_RejectTask_WithCancellationToken()
        {
            var cancellationToken = new CancellationTokenSource();
            var source            = UnsafeCompletionSource <int> .Create(cancellationToken.Token);

            cancellationToken.Cancel();

            Assert.That(source.ResultTask.Status, Is.EqualTo(PandaTaskStatus.Rejected));
            Assert.That(source.ResultTask.Error, Is.InstanceOf <TaskCanceledException>());
        }
Exemple #15
0
        public void SetErrorTResult_Should_RejectTask_WithSpecificException()
        {
            var source = UnsafeCompletionSource <int> .Create();

            var exception = new ArgumentException();

            source.SetError(exception);

            Assert.That(source.ResultTask.Status, Is.EqualTo(PandaTaskStatus.Rejected));
            Assert.That(source.ResultTask.Error, Is.EqualTo(exception));
        }
Exemple #16
0
        public void TrySetErrorTResult_Should_Throw_WithNullException()
        {
            var source = UnsafeCompletionSource <int> .Create();

            Assert.That(() => source.TrySetError(null), Throws.ArgumentNullException);
        }