Пример #1
0
        public virtual void TestGenerationStampUpdate()
        {
            // Setup a mock object and stub out a few routines to
            // retrieve the generation stamp counters.
            BlockIdManager bid = Org.Mockito.Mockito.Mock <BlockIdManager>();
            long           nextGenerationStampV1 = 5000;
            long           nextGenerationStampV2 = 20000;

            Org.Mockito.Mockito.When(bid.GetNextGenerationStampV1()).ThenReturn(nextGenerationStampV1
                                                                                );
            Org.Mockito.Mockito.When(bid.GetNextGenerationStampV2()).ThenReturn(nextGenerationStampV2
                                                                                );
            // Make sure that the generation stamp is set correctly for both
            // kinds of blocks.
            Org.Mockito.Mockito.When(bid.NextGenerationStamp(AnyBoolean())).ThenCallRealMethod
                ();
            Assert.AssertThat(bid.NextGenerationStamp(true), CoreMatchers.Is(nextGenerationStampV1
                                                                             ));
            Assert.AssertThat(bid.NextGenerationStamp(false), CoreMatchers.Is(nextGenerationStampV2
                                                                              ));
        }
Пример #2
0
        public virtual void TestBlockTypeDetection()
        {
            // Setup a mock object and stub out a few routines to
            // retrieve the generation stamp counters.
            BlockIdManager bid = Org.Mockito.Mockito.Mock <BlockIdManager>();
            long           maxGenStampForLegacyBlocks = 10000;

            Org.Mockito.Mockito.When(bid.GetGenerationStampV1Limit()).ThenReturn(maxGenStampForLegacyBlocks
                                                                                 );
            Block legacyBlock = Org.Mockito.Mockito.Spy(new Block());

            Org.Mockito.Mockito.When(legacyBlock.GetGenerationStamp()).ThenReturn(maxGenStampForLegacyBlocks
                                                                                  / 2);
            Block newBlock = Org.Mockito.Mockito.Spy(new Block());

            Org.Mockito.Mockito.When(newBlock.GetGenerationStamp()).ThenReturn(maxGenStampForLegacyBlocks
                                                                               + 1);
            // Make sure that isLegacyBlock() can correctly detect
            // legacy and new blocks.
            Org.Mockito.Mockito.When(bid.IsLegacyBlock(Any <Block>())).ThenCallRealMethod();
            Assert.AssertThat(bid.IsLegacyBlock(legacyBlock), CoreMatchers.Is(true));
            Assert.AssertThat(bid.IsLegacyBlock(newBlock), CoreMatchers.Is(false));
        }