public async Task ShouldThrowExceptionWhenTxConfigIsUsed()
            {
                var mockConn        = new Mock <IConnection>();
                var statement       = new Statement("A cypher query");
                var bookmarkTracker = new Mock <IBookmarkTracker>();
                var resourceHandler = new Mock <IResultResourceHandler>();
                var txConfig        = new TransactionConfig
                {
                    Timeout  = TimeSpan.FromMinutes(1),
                    Metadata = new Dictionary <string, object> {
                        { "key1", "value1" }
                    }
                };

                mockConn.Setup(x =>
                               x.EnqueueAsync(It.IsAny <RunMessage>(), It.IsAny <V1.RunResponseHandler>(), PullAllMessage.PullAll,
                                              It.IsAny <V1.PullResponseHandler>()))
                .Callback <IRequestMessage, IResponseHandler, IRequestMessage, IResponseHandler>(
                    (msg1, h1, msg2, h2) => { h1?.OnSuccess(new Dictionary <string, object>()); });

                var error = await Xunit.Record.ExceptionAsync(() =>
                                                              BoltV1.RunInAutoCommitTransactionAsync(mockConn.Object, statement, true, bookmarkTracker.Object,
                                                                                                     resourceHandler.Object, null, txConfig));

                error.Should().BeOfType <ArgumentException>();
                error.Message.Should()
                .StartWith("Driver is connected to the database that does not support transaction configuration");
            }
Example #2
0
            public async Task EnqueueCommitAndSync()
            {
                var mockConn = new Mock <IConnection>();
                await BoltV1.CommitTransactionAsync(mockConn.Object);

                mockConn.Verify(x => x.Enqueue(Commit, It.IsAny <BookmarkCollector>(), PullAll), Times.Once);
                mockConn.Verify(x => x.SyncAsync(), Times.Once);
            }
Example #3
0
            public void ResultBuilderShouldObtainServerInfoFromConnection()
            {
                var mockConn = new Mock <IConnection>();
                var statment = new Statement("lalala");

                BoltV1.RunInExplicitTransaction(mockConn.Object, statment);
                mockConn.Verify(x => x.Server, Times.Once);
            }
Example #4
0
            public async Task ShouldNotSyncIfBookmarkIsNull()
            {
                var mockConn = new Mock <IConnection>();
                await BoltV1.BeginTransactionAsync(mockConn.Object, null);

                mockConn.Verify(x => x.Enqueue(It.IsAny <RunMessage>(), It.IsAny <IMessageResponseCollector>(), PullAll), Times.Once);
                mockConn.Verify(x => x.SyncAsync(), Times.Never);
            }
Example #5
0
            public async Task ShouldSyncIfValidBookmarkGiven()
            {
                var mockConn = new Mock <IConnection>();
                var bookmark = Bookmark.From(FakeABookmark(234));
                await BoltV1.BeginTransactionAsync(mockConn.Object, bookmark);

                mockConn.Verify(x => x.Enqueue(It.IsAny <RunMessage>(), It.IsAny <IMessageResponseCollector>(), PullAll), Times.Once);
                mockConn.Verify(x => x.SyncAsync(), Times.Once);
            }
Example #6
0
            public void ShouldEnqueueRollbackAndSync()
            {
                var mockConn = new Mock <IConnection>();

                BoltV1.RollbackTransactionAsync(mockConn.Object);

                mockConn.Verify(x => x.Enqueue(Rollback, It.IsAny <BookmarkCollector>(), DiscardAll), Times.Once);
                mockConn.Verify(x => x.SyncAsync(), Times.Once);
            }
Example #7
0
            public async Task ResultBuilderShouldObtainServerInfoFromConnection()
            {
                var mockConn = MockedConnectionWithSuccessResponse();
                var statment = new Statement("lalala");

                await BoltV1.RunInExplicitTransactionAsync(mockConn.Object, statment);

                mockConn.Verify(x => x.Server, Times.Once);
            }
Example #8
0
            public void ResultBuilderShouldObtainServerInfoFromConnection()
            {
                var mockConn    = new Mock <IConnection>();
                var statement   = new Statement("A cypher query");
                var mockHandler = new Mock <IResultResourceHandler>();

                BoltV1.RunInAutoCommitTransaction(mockConn.Object, statement, mockHandler.Object);

                mockConn.Verify(x => x.Server, Times.Once);
            }
Example #9
0
            public async Task ShouldEnqueueInitAndSync()
            {
                var mockConn = new Mock <IConnection>();

                mockConn.Setup(x => x.Server).Returns(new ServerInfo(new Uri("http://neo4j.com")));
                await BoltV1.AuthenticateAsync(mockConn.Object, "user-zhen", AuthTokens.None);

                mockConn.Verify(x => x.Enqueue(It.IsAny <InitMessage>(), It.IsAny <InitCollector>(), null), Times.Once);
                mockConn.Verify(x => x.SyncAsync());
            }
Example #10
0
            public async Task ShouldRunPullAllSync()
            {
                var mockConn = MockedConnectionWithSuccessResponse();
                var statment = new Statement("lalala");

                await BoltV1.RunInExplicitTransactionAsync(mockConn.Object, statment);

                mockConn.Verify(x => x.Enqueue(It.IsAny <RunMessage>(), It.IsAny <ResultCursorBuilder>(), PullAll), Times.Once);
                mockConn.Verify(x => x.SendAsync(), Times.Once);
            }
Example #11
0
            public void ShouldRunPullAllSync()
            {
                var mockConn = new Mock <IConnection>();
                var statment = new Statement("lalala");

                BoltV1.RunInExplicitTransaction(mockConn.Object, statment);

                mockConn.Verify(x => x.Enqueue(It.IsAny <RunMessage>(), It.IsAny <ResultBuilder>(), PullAll), Times.Once);
                mockConn.Verify(x => x.Send(), Times.Once);
            }
Example #12
0
            public void ShouldNotSyncIfInvalidBookmarkGiven()
            {
                var mockConn = new Mock <IConnection>();
                var bookmark = Bookmark.From((string)null);

                BoltV1.BeginTransaction(mockConn.Object, bookmark);

                mockConn.Verify(x => x.Enqueue(It.IsAny <RunMessage>(), It.IsAny <IMessageResponseCollector>(), PullAll), Times.Once);
                mockConn.Verify(x => x.Sync(), Times.Never);
            }
Example #13
0
            public void ShouldEnqueueRunAndPullAllAndSend()
            {
                var mockConn    = new Mock <IConnection>();
                var statement   = new Statement("A cypher query");
                var mockHandler = new Mock <IResultResourceHandler>();

                BoltV1.RunInAutoCommitTransaction(mockConn.Object, statement, mockHandler.Object);

                mockConn.Verify(x => x.Enqueue(It.IsAny <RunMessage>(), It.IsAny <ResultBuilder>(), PullAll), Times.Once);
                mockConn.Verify(x => x.Send());
            }
            public async Task ShouldEnqueueRollbackAndSync()
            {
                var mockConn = new Mock <IConnection>();

                await BoltV1.RollbackTransactionAsync(mockConn.Object);

                mockConn.Verify(
                    x => x.EnqueueAsync(Rollback, It.IsAny <V1.RollbackResponseHandler>(), DiscardAllMessage.DiscardAll,
                                        It.IsAny <V1.RollbackResponseHandler>()), Times.Once);
                mockConn.Verify(x => x.SyncAsync(), Times.Once);
            }
            public async Task ShouldSyncIfValidBookmarkGiven()
            {
                var mockConn = new Mock <IConnection>();
                var bookmark = Bookmark.From(SessionTests.FakeABookmark(234));
                await BoltV1.BeginTransactionAsync(mockConn.Object, bookmark, null);

                mockConn.Verify(
                    x => x.EnqueueAsync(It.IsAny <RunMessage>(), It.IsAny <V1.BeginResponseHandler>(), PullAllMessage.PullAll,
                                        It.IsAny <V1.BeginResponseHandler>()),
                    Times.Once);
                mockConn.Verify(x => x.SyncAsync(), Times.Once);
            }
            public async Task EnqueueCommitAndSync()
            {
                var mockConn        = new Mock <IConnection>();
                var bookmarkTracker = new Mock <IBookmarkTracker>();

                await BoltV1.CommitTransactionAsync(mockConn.Object, bookmarkTracker.Object);

                mockConn.Verify(
                    x => x.EnqueueAsync(Commit, It.IsAny <V1.CommitResponseHandler>(), PullAllMessage.PullAll,
                                        It.IsAny <V1.CommitResponseHandler>()), Times.Once);
                mockConn.Verify(x => x.SyncAsync(), Times.Once);
            }
            public async Task ShouldRunPullAllSync()
            {
                var mockConn  = SessionTests.MockedConnectionWithSuccessResponse();
                var statement = new Statement("lalala");

                await BoltV1.RunInExplicitTransactionAsync(mockConn.Object, statement, true);

                mockConn.Verify(
                    x => x.EnqueueAsync(It.IsAny <RunMessage>(), It.IsAny <V1.RunResponseHandler>(), PullAllMessage.PullAll,
                                        It.IsAny <V1.PullResponseHandler>()),
                    Times.Once);
                mockConn.Verify(x => x.SendAsync(), Times.Once);
            }
Example #18
0
            public async Task ResultBuilderShouldObtainServerInfoFromConnection()
            {
                var mockConn    = new Mock <IConnection>();
                var statement   = new Statement("A cypher query");
                var mockHandler = new Mock <IResultResourceHandler>();

                mockConn.Setup(x => x.Enqueue(It.IsAny <IRequestMessage>(), It.IsAny <IMessageResponseCollector>(), PullAll))
                .Callback <IRequestMessage, IMessageResponseCollector, IRequestMessage>(
                    (msg1, h, msg2) =>
                {
                    h?.DoneSuccess();
                });
                await BoltV1.RunInAutoCommitTransactionAsync(mockConn.Object, statement, mockHandler.Object);

                mockConn.Verify(x => x.Server, Times.Once);
            }
            public async Task ShouldThrowExceptionIfTxConfigIsGiven()
            {
                var mockConn = new Mock <IConnection>();
                var txConfig = new TransactionConfig
                {
                    Timeout  = TimeSpan.FromMinutes(1),
                    Metadata = new Dictionary <string, object> {
                        { "key1", "value1" }
                    }
                };

                var error = await Xunit.Record.ExceptionAsync(() =>
                                                              BoltV1.BeginTransactionAsync(mockConn.Object, null, txConfig));

                error.Should().BeOfType <ArgumentException>().Which.Message.Should().StartWith(
                    "Driver is connected to the database that does not support transaction configuration.");
            }
Example #20
0
            public async Task ShouldEnqueueRunAndPullAllAndSend()
            {
                var mockConn    = new Mock <IConnection>();
                var statement   = new Statement("A cypher query");
                var mockHandler = new Mock <IResultResourceHandler>();

                mockConn.Setup(x => x.Enqueue(It.IsAny <IRequestMessage>(), It.IsAny <IMessageResponseCollector>(), It.IsAny <IRequestMessage>()))
                .Callback <IRequestMessage, IMessageResponseCollector, IRequestMessage>(
                    (msg1, h, msg2) =>
                {
                    h?.DoneSuccess();
                });

                await BoltV1.RunInAutoCommitTransactionAsync(mockConn.Object, statement, mockHandler.Object, null, null);

                mockConn.Verify(x => x.Enqueue(It.IsAny <RunMessage>(), It.IsAny <ResultCursorBuilder>(), PullAll), Times.Once);
                mockConn.Verify(x => x.SendAsync());
            }
            public async Task ResultBuilderShouldObtainServerInfoFromConnection()
            {
                var mockConn        = new Mock <IConnection>();
                var statement       = new Statement("A cypher query");
                var bookmarkTracker = new Mock <IBookmarkTracker>();
                var resourceHandler = new Mock <IResultResourceHandler>();

                mockConn.Setup(x =>
                               x.EnqueueAsync(It.IsAny <RunMessage>(), It.IsAny <V1.RunResponseHandler>(), PullAllMessage.PullAll,
                                              It.IsAny <V1.PullResponseHandler>()))
                .Returns(TaskHelper.GetCompletedTask())
                .Callback <IRequestMessage, IResponseHandler, IRequestMessage, IResponseHandler>(
                    (msg1, h1, msg2, h2) => { h1?.OnSuccess(new Dictionary <string, object>()); });

                await BoltV1.RunInAutoCommitTransactionAsync(mockConn.Object, statement, true, bookmarkTracker.Object,
                                                             resourceHandler.Object, null, null);

                mockConn.Verify(x => x.Server, Times.Once);
            }
Example #22
0
            public void ShouldThrowExceptionWhenTxConfigIsUsed()
            {
                var mockConn = new Mock <IConnection>();

                var statement   = new Statement("A cypher query");
                var mockHandler = new Mock <IResultResourceHandler>();
                var txConfig    = new TransactionConfig
                {
                    Timeout  = TimeSpan.FromMinutes(1),
                    Metadata = new Dictionary <string, object> {
                        { "key1", "value1" }
                    }
                };

                var error = Xunit.Record.Exception(() =>
                                                   BoltV1.RunInAutoCommitTransaction(mockConn.Object, statement, mockHandler.Object, null, txConfig));

                error.Should().BeOfType <ArgumentException>();
                error.Message.Should()
                .StartWith("Driver is connected to the database that does not support transaction configuration");
            }