public async Task SendsToIndexInBatches() { var indexer = new Mock <IFunctionIndexer <TestFunctionMessageDto> >(); var handler = new FunctionIndexTransactionHandler <TestFunctionMessageDto>(indexer.Object, logsPerIndexBatch: 2); var transaction1 = new Mock <TransactionWithReceipt>(); var transaction2 = new Mock <TransactionWithReceipt>(); var dto1 = new TestFunctionMessageDto(); var dto2 = new TestFunctionMessageDto(); transaction1.Setup(t => t.IsForFunction <TestFunctionMessageDto>()).Returns(true); transaction2.Setup(t => t.IsForFunction <TestFunctionMessageDto>()).Returns(true); transaction1.Setup(t => t.Decode <TestFunctionMessageDto>()).Returns(dto1); transaction2.Setup(t => t.Decode <TestFunctionMessageDto>()).Returns(dto2); var indexedFunctionCalls = CaptureCallsToIndexer(indexer); await handler.HandleTransactionAsync(transaction1.Object); Assert.Empty(indexedFunctionCalls); Assert.Equal(1, handler.Pending); await handler.HandleTransactionAsync(transaction2.Object); Assert.Equal(2, indexedFunctionCalls.Count); Assert.Equal(0, handler.Pending); }
public async Task WhenDisposeIsCalledWillAttemptToIndexPendingItems() { var indexer = new Mock <IFunctionIndexer <TestFunctionMessageDto> >(); var indexedFunctionCalls = CaptureCallsToIndexer(indexer); using (var handler = new FunctionIndexTransactionHandler <TestFunctionMessageDto>(indexer.Object, logsPerIndexBatch: 2)) { var transaction1 = new Mock <TransactionWithReceipt>(); var dto1 = new TestFunctionMessageDto(); transaction1.Setup(t => t.IsForFunction <TestFunctionMessageDto>()).Returns(true); transaction1.Setup(t => t.Decode <TestFunctionMessageDto>()).Returns(dto1); await handler.HandleTransactionAsync(transaction1.Object); Assert.Equal(1, handler.Pending); } //calling dispose should cause app to process remaining pending items Assert.Single(indexedFunctionCalls); }