コード例 #1
0
        public void GetTrxAsyncReturnsTransactionFromBlockInCache()
        {
            var trans = new Transaction();

            trans.Version = 15121;
            uint256 blockId = new uint256(2389704);
            Block   block   = new Block();

            block.Header.Version = 1451;
            block.Transactions.Add(trans);

            var dict = new Dictionary <object, object>();

            dict.Add(trans.GetHash(), blockId);
            dict.Add(blockId, block);

            var memoryCacheStub = new MemoryCacheStub(dict);

            this.blockStoreCache = new BlockStoreCache(this.blockRepository.Object, memoryCacheStub);

            var result = this.blockStoreCache.GetTrxAsync(trans.GetHash());

            result.Wait();

            Assert.Equal(trans.GetHash(), result.Result.GetHash());
        }
コード例 #2
0
        public void GetBlockByTrxAsyncBlockNotInCacheLookupNotInRepositoryReturnsNull()
        {
            uint256 txId            = new uint256(3252);
            var     memoryCacheStub = new MemoryCacheStub();

            this.blockStoreCache = new BlockStoreCache(this.blockRepository.Object, memoryCacheStub);
            this.blockRepository.Setup(b => b.GetTrxBlockIdAsync(txId))
            .Returns(Task.FromResult((uint256)null));

            var result = this.blockStoreCache.GetBlockByTrxAsync(txId);

            result.Wait();

            Assert.Null(result.Result);
        }
コード例 #3
0
        public void GetTrxAsyncReturnsNullWhenNotInCache()
        {
            var trans = new Transaction();

            trans.Version = 15121;
            this.blockRepository.Setup(b => b.GetTrxBlockIdAsync(trans.GetHash()))
            .Returns(Task.FromResult((uint256)null));

            var memoryCacheStub = new MemoryCacheStub();

            this.blockStoreCache = new BlockStoreCache(this.blockRepository.Object, memoryCacheStub);

            var result = this.blockStoreCache.GetTrxAsync(trans.GetHash());

            result.Wait();

            Assert.Null(result.Result);
        }
コード例 #4
0
        public void GetBlockAsyncBlockNotInCacheQueriesRepositoryStoresBlockInCacheAndReturnsBlock()
        {
            uint256 blockId         = new uint256(2389704);
            Block   repositoryBlock = new Block();

            repositoryBlock.Header.Version = 1451;
            this.blockRepository.Setup(b => b.GetAsync(blockId))
            .Returns(Task.FromResult(repositoryBlock));

            var memoryCacheStub = new MemoryCacheStub();

            this.blockStoreCache = new BlockStoreCache(this.blockRepository.Object, memoryCacheStub);

            var result = this.blockStoreCache.GetBlockAsync(blockId);

            result.Wait();

            Assert.Equal(blockId, memoryCacheStub.GetLastCreateCalled());
            Assert.Equal(1451, result.Result.Header.Version);
        }
コード例 #5
0
        public void GetBlockByTrxAsyncBlockInCacheReturnsBlock()
        {
            uint256 txId    = new uint256(3252);
            uint256 blockId = new uint256(2389704);
            Block   block   = new Block();

            block.Header.Version = 1451;
            var dict = new Dictionary <object, object>();

            dict.Add(txId, blockId);
            dict.Add(blockId, block);

            var memoryCacheStub = new MemoryCacheStub(dict);

            this.blockStoreCache = new BlockStoreCache(this.blockRepository.Object, memoryCacheStub);

            var result = this.blockStoreCache.GetBlockByTrxAsync(txId);

            result.Wait();

            Assert.Equal(1451, result.Result.Header.Version);
        }
コード例 #6
0
        public void GetBlockByTrxAsyncBlockNotInCacheLookupInRepository()
        {
            uint256 txId    = new uint256(3252);
            uint256 blockId = new uint256(2389704);
            Block   block   = new Block();

            block.Header.Version = 1451;
            var dict = new Dictionary <object, object>();

            dict.Add(blockId, block);

            var memoryCacheStub = new MemoryCacheStub(dict);

            this.blockStoreCache = new BlockStoreCache(this.blockRepository.Object, memoryCacheStub);
            this.blockRepository.Setup(b => b.GetTrxBlockIdAsync(txId))
            .Returns(Task.FromResult(blockId));

            var result = this.blockStoreCache.GetBlockByTrxAsync(txId);

            result.Wait();

            Assert.Equal(1451, result.Result.Header.Version);
            Assert.Equal(txId, memoryCacheStub.GetLastCreateCalled());
        }