public async void ShouldThrowExceptionIfPreviousTxFailed() { var mockConn = new Mock <IConnection>(); var tx = new AsyncTransaction(mockConn.Object, Mock.Of <ITransactionResourceHandler>()); await tx.MarkToClose(); var error = await ExceptionAsync(() => tx.RunAsync("ttt")); error.Should().BeOfType <ClientException>(); }
public async void ShouldDelegateToBoltProtocol() { var protocol = new Mock <IBoltProtocol>(); var mockConn = NewMockedConnection(protocol.Object); var tx = new AsyncTransaction(mockConn.Object); var statement = new Statement("lala"); await tx.RunAsync(statement); protocol.Verify(x => x.RunInExplicitTransactionAsync(It.IsAny <IConnection>(), statement, false)); }
public async void ShouldDelegateToBoltProtocol() { var protocol = new Mock <IBoltProtocol>(); var mockConn = NewMockedConnection(protocol.Object); var tx = new AsyncTransaction(mockConn.Object, Mock.Of <ITransactionResourceHandler>()); var query = new Query("lala"); await tx.RunAsync(query); protocol.Verify(x => x.RunInExplicitTransactionAsync(It.IsAny <IConnection>(), query, false, It.IsAny <long>())); }
public async Task ShouldBeOpenWhenRun() { var protocol = new Mock <IBoltProtocol>(); var mockConn = NewMockedConnection(protocol.Object); var tx = new AsyncTransaction(mockConn.Object, Mock.Of <ITransactionResourceHandler>()); await tx.BeginTransactionAsync(TransactionConfig.Default); await tx.RunAsync("RETURN 1"); tx.IsOpen.Should().BeTrue(); }
public async void ShouldThrowExceptionIfFailedToRunAndFetchResult() { var protocol = new Mock <IBoltProtocol>(); var mockConn = NewMockedConnection(protocol.Object); var tx = new AsyncTransaction(mockConn.Object); var statement = new Statement("lala"); protocol.Setup(x => x.RunInExplicitTransactionAsync(It.IsAny <IConnection>(), statement, false)) .Throws <Neo4jException>(); var error = await ExceptionAsync(() => tx.RunAsync(statement)); error.Should().BeOfType <Neo4jException>(); }
public async void ShouldThrowExceptionIfFailedToRunAndFetchResult() { var protocol = new Mock <IBoltProtocol>(); var mockConn = NewMockedConnection(protocol.Object); var tx = new AsyncTransaction(mockConn.Object, Mock.Of <ITransactionResourceHandler>()); var query = new Query("lala"); protocol.Setup(x => x.RunInExplicitTransactionAsync(It.IsAny <IConnection>(), query, false, It.IsAny <long>())) .Throws <Neo4jException>(); var error = await ExceptionAsync(() => tx.RunAsync(query)); error.Should().BeOfType <Neo4jException>(); }
public async Task ShouldThrowExceptionToRunAfterMarkToClosed() { var protocol = new Mock <IBoltProtocol>(); var mockConn = NewMockedConnection(protocol.Object); var tx = new AsyncTransaction(mockConn.Object); mockConn.Invocations.Clear(); tx.MarkToClose(); var exception = await Record.ExceptionAsync(() => tx.RunAsync("should not run")); exception.Should().BeOfType <ClientException>(); exception.Message.Should().StartWith("Cannot run more statements in this transaction"); protocol.Verify(x => x.RollbackTransactionAsync(It.IsAny <IConnection>()), Times.Never); mockConn.Verify(x => x.SyncAsync(), Times.Never); }