示例#1
0
        public void Callback_WhenHasNeutralStronghold_ShouldNotActivateAStronghold(
            [Frozen] ISystemVariableManager systemVariableManager,
            [Frozen] IStrongholdActivationCondition activationCondition,
            [Frozen] IStrongholdManager strongholdManager,
            IStronghold sh1,
            IStronghold sh2,
            IFixture fixture)
        {
            sh1.StrongholdState.Returns(StrongholdState.Inactive);
            sh2.StrongholdState.Returns(StrongholdState.Neutral);

            var lastCheckTime = Substitute.For <SystemVariable>();

            lastCheckTime.Value.Returns(SystemClock.Now.AddHours(-8));
            systemVariableManager["Stronghold.neutral_check"].Returns(lastCheckTime);

            var locker = new LockerStub();

            fixture.Register <ILocker>(() => locker);

            strongholdManager.GetEnumerator().Returns(_ => new List <IStronghold> {
                sh1, sh2
            }.GetEnumerator());

            var checker = fixture.Create <StrongholdActivationChecker>();

            checker.Callback(null);

            strongholdManager.DidNotReceive().Activate(sh2);
            strongholdManager.DidNotReceive().Activate(sh1);
        }
示例#2
0
        public void Callback_WhenInactiveStrongholdsHaveSameScore_ShouldActivateClosestToCenter(
            [Frozen] ISystemVariableManager systemVariableManager,
            [Frozen] IStrongholdActivationCondition activationCondition,
            [Frozen] IStrongholdManager strongholdManager,
            [Frozen] ITileLocator tileLocator,
            IStronghold sh1,
            IStronghold sh2,
            IFixture fixture)
        {
            sh1.StrongholdState.Returns(StrongholdState.Inactive);
            sh1.PrimaryPosition.Returns(new Position(10, 20));

            sh2.StrongholdState.Returns(StrongholdState.Inactive);
            sh2.PrimaryPosition.Returns(new Position(30, 40));

            activationCondition.Score(null).ReturnsForAnyArgs(0);

            tileLocator.TileDistance(sh1.PrimaryPosition, 1, Arg.Any <Position>(), 1)
            .Returns(10);

            tileLocator.TileDistance(sh2.PrimaryPosition, 1, Arg.Any <Position>(), 1)
            .Returns(5);

            var lastCheckTime = Substitute.For <SystemVariable>();

            lastCheckTime.Value.Returns(SystemClock.Now.AddHours(-8));
            systemVariableManager["Stronghold.neutral_check"].Returns(lastCheckTime);

            var locker = new LockerStub();

            fixture.Register <ILocker>(() => locker);

            strongholdManager.GetEnumerator().Returns(_ => new List <IStronghold> {
                sh1, sh2
            }.GetEnumerator());

            var checker = fixture.Create <StrongholdActivationChecker>();

            checker.Callback(null);

            strongholdManager.Received().Activate(sh2);
            strongholdManager.DidNotReceive().Activate(sh1);
        }