Пример #1
0
        public void WhenSomeoneJoins(IEnumerable <int> moveTimes, DateTime expectedTime)
        {
            var   tribe      = Substitute.For <ITribe>();
            var   targetCity = Substitute.For <ICity>();
            ICity stubCity;
            var   stub              = CreateStub(out stubCity);
            var   formula           = Substitute.For <Formula>();
            var   dbManager         = Substitute.For <IDbManager>();
            var   gameObjectLocator = Substitute.For <IGameObjectLocator>();
            var   scheduler         = Substitute.For <IScheduler>();
            var   procedure         = Substitute.For <Procedure>();
            var   radiusLocator     = Substitute.For <ITileLocator>();
            var   actionFactory     = Substitute.For <IActionFactory>();
            var   locker            = new LockerStub(gameObjectLocator);
            var   initializer       = Substitute.For <ITroopObjectInitializerFactory>();
            ICity newCity;
            var   newStub = CreateStub(out newCity);
            ICity newCity2;
            var   newStub2 = CreateStub(out newCity2);

            SystemClock.SetClock(startTime);

            Queue <int> moveTimeReturns = new Queue <int>();

            foreach (var moveTime in moveTimes)
            {
                moveTimeReturns.Enqueue(moveTime);
            }
            formula.MoveTimeTotal(Arg.Any <ITroopStub>(), 0, true).Returns(x => moveTimeReturns.Dequeue());

            Assignment assignment = new Assignment(tribe,
                                                   TARGET_X,
                                                   TARGET_Y,
                                                   targetCity,
                                                   AttackMode.Normal,
                                                   targetTime,
                                                   "Description",
                                                   true,
                                                   formula,
                                                   dbManager,
                                                   gameObjectLocator,
                                                   scheduler,
                                                   procedure,
                                                   radiusLocator,
                                                   actionFactory,
                                                   locker,
                                                   initializer);

            assignment.Add(stub);
            assignment.Add(newStub);
            assignment.Add(newStub2);
            assignment.TroopCount.Should().Be(3);
            dbManager.Received(3).Save(assignment);
            scheduler.Received(3).Put(assignment);

            assignment.Callback(null);

            assignment.Time.Should().Be(expectedTime);
        }
Пример #2
0
        public void WhenDefensiveAssignmentScheduled()
        {
            var   tribe      = Substitute.For <ITribe>();
            var   targetCity = Substitute.For <ICity>();
            ICity stubCity;
            var   stub                    = CreateStub(out stubCity);
            var   formula                 = Substitute.For <Formula>();
            var   gameObjectLocator       = Substitute.For <IGameObjectLocator>();
            var   targetStructure         = Substitute.For <IStructure>();
            var   actionWorker            = Substitute.For <IActionWorker>();
            var   troopObject             = Substitute.For <ITroopObject>();
            var   troopInitializerFactory = Substitute.For <ITroopObjectInitializerFactory>();

            troopObject.ObjectId.Returns((uint)99);

            gameObjectLocator.Regions.GetObjectsInTile(TARGET_X, TARGET_Y).Returns(new List <ISimpleGameObject> {
                targetStructure
            });

            targetStructure.City.Returns(targetCity);

            targetCity.Id.Returns((uint)100);
            targetCity.LocationType.Returns(LocationType.City);
            targetCity.LocationId.Returns((uint)100);

            actionWorker.DoPassive(Arg.Any <ICity>(), Arg.Any <PassiveAction>(), true).Returns(Error.Ok);

            stubCity.Worker.Returns(actionWorker);
            stubCity.Id.Returns((uint)20);

            var troopInitializer = Substitute.For <ITroopObjectInitializer>();

            troopInitializerFactory.CreateAssignmentTroopObjectInitializer(troopObject, TroopBattleGroup.Defense, AttackMode.Strong).Returns(troopInitializer);

            SystemClock.SetClock(startTime);

            // troop should be dispatched a minute later
            formula.MoveTimeTotal(stub, Arg.Any <int>(), false).Returns(300);

            ITroopObject outTroopObject;
            var          procedure = Substitute.For <Procedure>();

            procedure.When(m => m.TroopObjectCreate(stubCity, stub, out outTroopObject)).Do(x =>
            {
                x[2] = troopObject;
            });

            var actionFactory = Substitute.For <IActionFactory>();

            var assignment = new Assignment(tribe,
                                            TARGET_X,
                                            TARGET_Y,
                                            targetCity,
                                            AttackMode.Strong,
                                            targetTime,
                                            "Description",
                                            false,
                                            formula,
                                            Substitute.For <IDbManager>(),
                                            gameObjectLocator,
                                            Substitute.For <IScheduler>(),
                                            procedure,
                                            Substitute.For <ITileLocator>(),
                                            actionFactory,
                                            new LockerStub(gameObjectLocator),
                                            troopInitializerFactory)
            {
                stub
            };

            assignment.Callback(null);
            assignment.Time.Should().Be(targetTime.AddMinutes(-5));

            SystemClock.SetClock(targetTime.AddSeconds(-90));

            // Dispatch first troop
            assignment.Callback(null);
            actionFactory.Received().CreateCityDefenseChainAction(20, troopInitializer, 100);
        }
Пример #3
0
        public void WhenSomeoneAlreadyDispatched()
        {
            var   tribe      = Substitute.For <ITribe>();
            var   targetCity = Substitute.For <ICity>();
            ICity stubCity;
            var   stub              = CreateStub(out stubCity);
            var   formula           = Substitute.For <Formula>();
            var   dbManager         = Substitute.For <IDbManager>();
            var   gameObjectLocator = Substitute.For <IGameObjectLocator>();
            var   scheduler         = Substitute.For <IScheduler>();
            var   procedure         = Substitute.For <Procedure>();
            var   radiusLocator     = Substitute.For <ITileLocator>();
            var   actionFactory     = Substitute.For <IActionFactory>();
            ICity newCity;
            var   newStub         = CreateStub(out newCity);
            var   targetStructure = Substitute.For <IStructure>();
            var   actionWorker    = Substitute.For <IActionWorker>();
            var   troopObject     = Substitute.For <ITroopObject>();
            var   initializer     = Substitute.For <ITroopObjectInitializerFactory>();

            SystemClock.SetClock(startTime);

            troopObject.ObjectId.Returns((uint)95);

            gameObjectLocator.Regions.GetObjectsInTile(TARGET_X, TARGET_Y).Returns(new List <ISimpleGameObject> {
                targetStructure
            });

            targetStructure.City.Returns(targetCity);

            targetCity.Id.Returns((uint)100);

            actionWorker.DoPassive(Arg.Any <ICity>(), Arg.Any <PassiveAction>(), true).Returns(Error.Ok);

            stubCity.Worker.Returns(actionWorker);

            ITroopObject outTroopObject;

            procedure.When(x => x.TroopObjectCreate(stubCity, stub, out outTroopObject)).Do(x =>
                                                                                            { x[2] = troopObject; });

            formula.MoveTimeTotal(Arg.Any <ITroopStub>(), 0, true).Returns(300, 300, 120);

            Assignment assignment = new Assignment(tribe,
                                                   TARGET_X,
                                                   TARGET_Y,
                                                   targetCity,
                                                   AttackMode.Normal,
                                                   targetTime,
                                                   "Description",
                                                   true,
                                                   formula,
                                                   dbManager,
                                                   gameObjectLocator,
                                                   scheduler,
                                                   procedure,
                                                   radiusLocator,
                                                   actionFactory,
                                                   new LockerStub(gameObjectLocator),
                                                   initializer)
            {
                stub
            };

            SystemClock.SetClock(targetTime.AddSeconds(-90));

            // Dispatch first troop
            assignment.Callback(null);
            assignment.TroopCount.Should().Be(0);

            // Add new troop
            assignment.Add(newStub);
            assignment.TroopCount.Should().Be(1);
            assignment.Time.Should().Be(SystemClock.Now);

            assignment.Callback(null);
            assignment.Time.Should().Be(targetTime);
            assignment.TroopCount.Should().Be(0);
        }