示例#1
0
        public async Task Throw1()
        {
            var ex = new Exception("Bang!");
            var xs = AsyncEnumerableEx.Throw <int>(ex);
            var e  = xs.GetAsyncEnumerator();

            await AssertThrowsAsync(e.MoveNextAsync(), ex);

            Assert.False(await e.MoveNextAsync());
        }
        public async Task AsyncEnumerable_ReadByteAsync_throws_expected_exception1()
        {
            var throwingEnumerable = AsyncEnumerableEx.Throw <ArraySegment <byte> >(new IOException());

            var stream = throwingEnumerable.ToStream();

            stream
            .Awaiting(_ => _.ReadAsync(new byte[1], 0, 1))
            .Should()
            .ThrowExactly <IOException>();
        }
示例#3
0
            public IAsyncEnumerable <TElement> Execute <TElement>(IGremlinQueryBase <TElement> query)
            {
                var serialized = Serializer
                                 .Serialize(query);

                if (serialized == null)
                {
                    return(AsyncEnumerableEx.Throw <TElement>(new Exception("Can't serialize query.")));
                }

                return(Executor
                       .Execute(serialized)
                       .SelectMany(executionResult => Deserializer
                                   .Deserialize <TElement>(executionResult, query.AsAdmin().Environment)));
            }
        public async Task AsyncEnumerable_Concat_produces_correct_sequence_when_first_sequence_faults()
        {
            var ex = new Exception();

            var array = await AsyncEnumerableEx.Throw <int>(ex)
                        .Concat(maybe => AsyncEnumerableEx.Return(1))
                        .Materialize()
                        .ToArrayAsync();

            array
            .Should()
            .HaveCount(1);

            array[0].Exception
            .Should()
            .Be(ex);
        }
            public IAsyncEnumerable <JToken> Execute(GroovySerializedGremlinQuery groovySerializedQuery)
            {
                _logger?.LogTrace("Executing Gremlin query {0}.", groovySerializedQuery.QueryString);

                return(_lazyGremlinClient
                       .Value
                       .SubmitAsync <JToken>(groovySerializedQuery.QueryString, groovySerializedQuery.Bindings)
                       .ToAsyncEnumerable()
                       .SelectMany(x => x
                                   .ToAsyncEnumerable())
                       .Catch <JToken, Exception>(ex =>
                {
                    _logger?.LogError("Error executing Gremlin query {0}.", groovySerializedQuery.QueryString);

                    return AsyncEnumerableEx.Throw <JToken>(ex);
                }));
            }
        public async Task AsyncEnumerable_Materialize_handles_OnError_correctly()
        {
            var ex            = new DivideByZeroException();
            var notifications = await AsyncEnumerable.Range(0, 100)
                                .Take(10)
                                .Concat(AsyncEnumerableEx.Throw <int>(ex))
                                .Materialize()
                                .ToArrayAsync();

            Assert.Equal(11, notifications.Length);

            for (var i = 0; i < notifications.Length - 1; i++)
            {
                Assert.Equal(NotificationKind.OnNext, notifications[i].Kind);
                Assert.Equal(i, notifications[i].Value);
            }

            var lastNotificaton = notifications.Last();

            Assert.Equal(NotificationKind.OnError, lastNotificaton.Kind);
            Assert.Equal(ex, lastNotificaton.Exception);
        }
示例#7
0
            public IAsyncEnumerable <object> Execute(object serializedQuery)
            {
                if (serializedQuery is GroovySerializedGremlinQuery groovySerializedQuery)
                {
                    _logger?.LogTrace("Executing Gremlin query {0}.", groovySerializedQuery.QueryString);

                    return(_lazyGremlinClient
                           .Value
                           .SubmitAsync <JToken>(groovySerializedQuery.QueryString, groovySerializedQuery.Bindings)
                           .ToAsyncEnumerable()
                           .SelectMany(x => x
                                       .ToAsyncEnumerable())
                           .Catch <JToken, Exception>(ex =>
                    {
                        _logger?.LogError("Error executing Gremlin query {0}.", groovySerializedQuery.QueryString);

                        return AsyncEnumerableEx.Throw <JToken>(ex);
                    }));
                }

                throw new ArgumentException($"Cannot handle serialized query of type {serializedQuery.GetType()}.");
            }
        public async Task AsyncEnumerable_Materialize_roundtrip_handles_OnError_correctly()
        {
            var enumerable = AsyncEnumerable.Range(0, 3)
                             .Concat(AsyncEnumerableEx.Throw <int>(new DivideByZeroException()))
                             .Materialize()
                             .Dematerialize();

            await using (var e = enumerable.GetAsyncEnumerator())
            {
                Assert.True(await e.MoveNextAsync());
                Assert.Equal(0, e.Current);

                Assert.True(await e.MoveNextAsync());
                Assert.Equal(1, e.Current);

                Assert.True(await e.MoveNextAsync());
                Assert.Equal(2, e.Current);

                e
                .Awaiting(_ => _.MoveNextAsync().AsTask())
                .Should()
                .ThrowExactly <DivideByZeroException>();
            }
        }
 public IAsyncEnumerable <TElement> Deserialize <TElement>(object result, IGremlinQueryEnvironment environment)
 {
     return(AsyncEnumerableEx.Throw <TElement>(new InvalidOperationException($"{nameof(Deserialize)} must not be called on {nameof(GremlinQueryExecutionResultDeserializer)}.{nameof(Invalid)}. If you are getting this exception while executing a query, configure a proper {nameof(IGremlinQueryExecutionResultDeserializer)} on your {nameof(GremlinQuerySource)}.")));
 }
 public IAsyncEnumerable <TExecutionResult> Execute(TSerializedQuery serializedQuery)
 {
     return(AsyncEnumerableEx.Throw <TExecutionResult>(new InvalidOperationException($"'{nameof(Execute)}' must not be called on GremlinQueryExecutor.Invalid. If you are getting this exception while executing a query, set a proper GremlinQueryExecutor on the GremlinQuerySource (e.g. with 'g.WithRemote(...)' for WebSockets)."))); //TODO: Review message.
 }
示例#11
0
 protected static IAsyncEnumerable <T> Throw <T>(Exception exception) => AsyncEnumerableEx.Throw <T>(exception);
 public IAsyncEnumerable <object> Execute(object serializedQuery)
 {
     return(AsyncEnumerableEx.Throw <object>(new InvalidOperationException($"'{nameof(Execute)}' must not be called on {nameof(GremlinQueryExecutor)}.Invalid. If you are getting this exception while executing a query, set a proper {nameof(GremlinQueryExecutor)} on the {nameof(GremlinQuerySource)} (e.g. with 'g.WithRemote(...)' for WebSockets which can be found in the 'ExRam.Gremlinq.Providers.WebSocket' package).")));
 }