Exemplo n.º 1
0
        public void WithResultPassExceptionInstance(IFoo fake, Task<int> task)
        {
            "Given a fake"
                .x(() => fake = A.Fake<IFoo>());

            "And an async method of the fake configured to throw asynchronously"
                .x(() => A.CallTo(() => fake.BazAsync()).ThrowsAsync(new MyException()));

            "When that method is called"
                .x(() => { task = fake.BazAsync(); });

            "Then it returns a failed task"
                .x(() => task.Status.Should().Be(TaskStatus.Faulted));

            "And the task's exception is the configured exception"
                .x(() => task.Exception?.InnerException.Should().BeAnExceptionOfType<MyException>());
        }
Exemplo n.º 2
0
        public static void WithResultPassExceptionInstance(IFoo fake, Task <int> task)
        {
            "Given a fake"
            .x(() => fake = A.Fake <IFoo>());

            "And an async method of the fake configured to throw asynchronously"
            .x(() => A.CallTo(() => fake.BazAsync()).ThrowsAsync(new MyException()));

            "When that method is called"
            .x(() => { task = fake.BazAsync(); });

            "Then it returns a failed task"
            .x(() => task.Status.Should().Be(TaskStatus.Faulted));

            "And the task's exception is the configured exception"
            .x(() => (task.Exception?.InnerException).Should().BeAnExceptionOfType <MyException>());
        }
Exemplo n.º 3
0
        public static void WithResultPassExceptionFactoryWithFourArgs(IFoo fake, Task <int> task)
        {
            "Given a fake"
            .x(() => fake = A.Fake <IFoo>());

            "And an async method of the fake configured to throw asynchronously"
            .x(() => A.CallTo(() => fake.BazAsync(0, "x", false, 0.0))
               .ThrowsAsync((int a, string b, bool c, double d) => new MyException()));

            "When that method is called"
            .x(() => { task = fake.BazAsync(0, "x", false, 0.0); });

            "Then it returns a failed task"
            .x(() => task.Status.Should().Be(TaskStatus.Faulted));

            "And the task's exception is the configured exception"
            .x(() => (task.Exception?.InnerException).Should().BeAnExceptionOfType <MyException>());
        }
Exemplo n.º 4
0
        public void AsyncWithoutResultCanceledTokenWithConfiguredCallForNonCanceledToken(
            IFoo fake,
            CancellationToken cancellationToken,
            Task task)
        {
            "Given a fake"
            .x(() => fake = A.Fake <IFoo>());

            "And a call configured on that fake for a non-canceled token"
            .x(() => A.CallTo(() => fake.BazAsync(A <CancellationToken> .That.IsNotCanceled())).Returns(Task.FromResult(0)));

            "And a cancellation token that is canceled"
            .x(() => cancellationToken = new CancellationToken(true));

            "When the configured async method is called with this cancellation token"
            .x(() => { task = fake.BazAsync(cancellationToken); });

            "Then it returns a canceled task"
            .x(() => task.Status.Should().Be(TaskStatus.Canceled));
        }
Exemplo n.º 5
0
        public void AsyncWithoutResultNonCanceledTokenWithConfiguredCall(
            IFoo fake,
            CancellationToken cancellationToken,
            Task task)
        {
            "Given a fake"
            .x(() => fake = A.Fake <IFoo>());

            "And a call configured on that fake"
            .x(() => A.CallTo(() => fake.BazAsync(A <CancellationToken> ._)).Returns(Task.FromResult(0)));

            "And a cancellation token that is not canceled"
            .x(() => cancellationToken = new CancellationToken(false));

            "When the configured async method is called with this cancellation token"
            .x(() => { task = fake.BazAsync(cancellationToken); });

            "Then it returns a successfully completed task"
            .x(() => task.Status.Should().Be(TaskStatus.RanToCompletion));
        }
Exemplo n.º 6
0
        public void AsyncWithoutResultCanceledToken(
            IFoo fake,
            CancellationToken cancellationToken,
            Task task)
        {
            "Given a fake"
            .x(() => fake = A.Fake <IFoo>());

            "And a cancellation token that is canceled"
            .x(() => cancellationToken = new CancellationToken(true));

            "When an async method is called with this cancellation token"
            .x(() => { task = fake.BazAsync(cancellationToken); });

            "Then it returns a canceled task"
            .x(() => task.Status.Should().Be(TaskStatus.Canceled));
        }
Exemplo n.º 7
0
        public void AsyncWithoutResultNonCanceledToken(
            IFoo fake,
            CancellationToken cancellationToken,
            Task task)
        {
            "Given a fake"
            .x(() => fake = A.Fake <IFoo>());

            "And a cancellation token that is not canceled"
            .x(() => cancellationToken = new CancellationToken(false));

            "When an async method is called with this cancellation token"
            .x(() => { task = fake.BazAsync(cancellationToken); });

            "Then it returns a successfully completed task"
            .x(() => task.Status.Should().Be(TaskStatus.RanToCompletion));
        }
Exemplo n.º 8
0
        public void WithResultPassExceptionFactoryWithFourArgs(IFoo fake, Task<int> task)
        {
            "Given a fake"
                .x(() => fake = A.Fake<IFoo>());

            "And an async method of the fake configured to throw asynchronously"
                .x(() => A.CallTo(() => fake.BazAsync(0, "x", false, 0.0))
                    .ThrowsAsync((int a, string b, bool c, double d) => new MyException()));

            "When that method is called"
                .x(() => { task = fake.BazAsync(0, "x", false, 0.0); });

            "Then it returns a failed task"
                .x(() => task.Status.Should().Be(TaskStatus.Faulted));

            "And the task's exception is the configured exception"
                .x(() => task.Exception?.InnerException.Should().BeAnExceptionOfType<MyException>());
        }
Exemplo n.º 9
0
        public void AsyncWithoutResultCanceledTokenWithConfiguredCallForNonCanceledToken(
            IFoo fake,
            CancellationToken cancellationToken,
            Task task)
        {
            "Given a fake"
                .x(() => fake = A.Fake<IFoo>());

            "And a call configured on that fake for a non-canceled token"
                .x(() => A.CallTo(() => fake.BazAsync(A<CancellationToken>.That.IsNotCanceled())).Returns(Task.FromResult(0)));

            "And a cancellation token that is canceled"
                .x(() => cancellationToken = new CancellationToken(true));

            "When the configured async method is called with this cancellation token"
                .x(() => { task = fake.BazAsync(cancellationToken); });

            "Then it returns a canceled task"
                .x(() => task.Status.Should().Be(TaskStatus.Canceled));
        }
Exemplo n.º 10
0
        public void AsyncWithoutResultCanceledToken(
            IFoo fake,
            CancellationToken cancellationToken,
            Task task)
        {
            "Given a fake"
                .x(() => fake = A.Fake<IFoo>());

            "And a cancellation token that is canceled"
                .x(() => cancellationToken = new CancellationToken(true));

            "When an async method is called with this cancellation token"
                .x(() => { task = fake.BazAsync(cancellationToken); });

            "Then it returns a canceled task"
                .x(() => task.Status.Should().Be(TaskStatus.Canceled));
        }
Exemplo n.º 11
0
        public void AsyncWithoutResultNonCanceledTokenWithConfiguredCall(
            IFoo fake,
            CancellationToken cancellationToken,
            Task task)
        {
            "Given a fake"
                .x(() => fake = A.Fake<IFoo>());

            "And a call configured on that fake"
                .x(() => A.CallTo(() => fake.BazAsync(A<CancellationToken>._)).Returns(Task.FromResult(0)));

            "And a cancellation token that is not canceled"
                .x(() => cancellationToken = new CancellationToken(false));

            "When the configured async method is called with this cancellation token"
                .x(() => { task = fake.BazAsync(cancellationToken); });

            "Then it returns a successfully completed task"
                .x(() => task.Status.Should().Be(TaskStatus.RanToCompletion));
        }
Exemplo n.º 12
0
        public void AsyncWithoutResultNonCanceledToken(
            IFoo fake,
            CancellationToken cancellationToken,
            Task task)
        {
            "Given a fake"
                .x(() => fake = A.Fake<IFoo>());

            "And a cancellation token that is not canceled"
                .x(() => cancellationToken = new CancellationToken(false));

            "When an async method is called with this cancellation token"
                .x(() => { task = fake.BazAsync(cancellationToken); });

            "Then it returns a successfully completed task"
                .x(() => task.Status.Should().Be(TaskStatus.RanToCompletion));
        }