public void ShouldRetryCommand()
        {
            // Given
            var command = new CommandStub();
            var target  = new RetryCommandExecutor(new AlwaysRetryPolicyStub(), new ZeroRetrySchedulePolicyStub());

            // When
            target.Execute(command.Execute);

            // Then
            Assert.AreEqual(2, command.Count);
        }
Exemple #2
0
        public void OnExecute_Returns_Successful_ExitCode()
        {
            // Arrange
            var commandLineApplication = new CommandLineApplication();
            var mockConfigurationRoot  = Mock.Of <IConfigurationRoot>();
            var mockServiceCollection  = Mock.Of <IServiceCollection>();
            var sut = new CommandStub(commandLineApplication, mockConfigurationRoot, mockServiceCollection);

            // Act
            var result = sut.OnExecute();

            // Assert
            result.ShouldBe(ExitCodes.SUCCESSFUL);
        }
Exemple #3
0
        public void CommandExecutor_GivenSupportCommand_ExecutesCommand()
        {
            const string commandString = "Test";

            var command = new CommandStub(commandString);

            var sut = new CommandExecutor(new List <ICommand> {
                new CommandStub(commandString)
            });
            var @event = new TestEvent(commandString);

            sut.Handle(@event);

            CommandStub.HandledEvents.Should().Contain(@event);
        }
Exemple #4
0
        // TODO: Whoops, I designed the stubs badly. I should swap the resolution function to the stub classes.
        public void ResolveStub(CommandStub stub)
        {
            var cmdPos = this.ResolveEID(stub.CommandEID).GetComponentOfType <Component_Position>();

            var gameEvent = stub.ReifyStub(this.floors[cmdPos.Z]); // TODO: LOL you should resolve against the floor it's on!

            if (gameEvent != null && gameEvent.CommandEntity == this.nextCommandEntity)
            {
                gameEvent.CommandEntity.HandleEvent(gameEvent);
                if (gameEvent.ShouldLog)
                {
                    this.DungeonLog.Add(gameEvent.LogMessage);
                }
                this.executedCommands.Add(gameEvent);
            }
            else if (gameEvent != null)
            {
                Log.ErrorLine("Can't resolve stub " + stub + " against entity " + gameEvent.CommandEntity +
                              " as next Entity is " + this.nextCommandEntity);
            }
            else
            {
                throw new NullReferenceException("Stub " + stub + " reified to null; instead, return a delay!");
            }

            // Hacky
            if (this.nextCommandEntity == this.Player)
            {
                foreach (var ai in this.DungeonEntities.Where(e => e.HasComponentOfType <Component_AI>()))
                {
                    if (!ai.GetComponentOfType <Component_AI>().Scanned&&
                        FloorState.DistanceBetweenEntities(this.Player, ai) <=
                        ai.TryGetAttribute(EntityAttributeType.SCAN_REQUIRED_RADIUS).Value)
                    {
                        ai.GetComponentOfType <Component_AI>().Scanned = true;
                        this.DungeonLog.Add("Scanned " + ai.Label + "!");
                    }
                }
            }
            this.ForwardToNextAction();
        }