public async Task MapsFunctionDtoToSearchDocument()
        {
            var index = new Index();
            var mockSearchIndexClient = new SearchIndexClientMock <SearchDocument>();

            var indexer = new AzureFunctionIndexer <TransferFunction, SearchDocument>(
                mockSearchIndexClient.SearchIndexClient, (tx) => new SearchDocument(tx));

            TransactionForFunctionVO <TransferFunction> transactionForFunction = IndexerTestData.CreateSampleTransactionForFunction();

            await indexer.IndexAsync(transactionForFunction);

            Assert.Single(mockSearchIndexClient.IndexedBatches);
            var firstIndexAction = mockSearchIndexClient.IndexedBatches[0].Actions.First();
            var document         = firstIndexAction.Document;

            //check function message mapping
            Assert.Equal(transactionForFunction.Transaction.TransactionHash, document.TransactionHash);
            Assert.Equal(transactionForFunction.FunctionMessage.To, document.To);
            Assert.Equal(transactionForFunction.FunctionMessage.Value.ToString(), document.Value);
        }
Пример #2
0
        public async Task MapsFunctionDtoToGenericSearchDocument()
        {
            var indexDefinition       = new FunctionIndexDefinition <TransferFunction>();
            var index                 = indexDefinition.ToAzureIndex();
            var mockSearchIndexClient = new SearchIndexClientMock <GenericSearchDocument>();

            var indexer = new AzureFunctionIndexer <TransferFunction>(
                mockSearchIndexClient.SearchIndexClient, indexDefinition);

            TransactionForFunctionVO <TransferFunction> transactionForFunction = IndexerTestData.CreateSampleTransactionForFunction();

            await indexer.IndexAsync(transactionForFunction);

            Assert.Single(mockSearchIndexClient.IndexedBatches);
            var firstIndexAction = mockSearchIndexClient.IndexedBatches[0].Actions.First();
            var document         = firstIndexAction.Document;

            //check generic mapping
            Assert.Equal(transactionForFunction.Transaction.BlockNumber.ToString(), document[PresetSearchFieldName.tx_block_number.ToString()]);
            //check function message mapping
            Assert.Equal(transactionForFunction.FunctionMessage.To, document["to"]);
            Assert.Equal(transactionForFunction.FunctionMessage.Value.ToString(), document["value"]);
        }