Пример #1
0
        public void That_TakeShot_ThrowsWhenAngleIsInvalid()
        {
            // given a game flow object
            IGameFlow serviceToTest = GetTestGameFlowObject(
                out Mock <ITargetGenerator> mockTargetGenerator,
                out Mock <IAngleValidator> mockAngleValidator,
                TestTarget, isAngleValid: false);

            // when TakeShot is called
            Exception exActual = null;

            try
            {
                serviceToTest.TakeShot(currentShotCount: 0,
                                       angle: 45M, velocity: 10M, currentTarget: TestTarget);
            }
            catch (Exception ex)
            {
                exActual = ex;
            }

            // error is thrown
            Assert.IsNotNull(exActual);
            Assert.AreEqual(MOCK_ANGLE_ERROR_MSG, exActual.Message);
        }
Пример #2
0
        public void That_TakeShot_DoesNotCallCounterWhenVelocityIsInvalid()
        {
            // given a game flow object
            IGameFlow serviceToTest = GetTestGameFlowObject(
                out Mock <ITargetGenerator> mockTargetGenerator,
                out Mock <IAngleValidator> mockAngleValidator,
                out Mock <IVelocityValidator> mockVelocityValidator,
                out Mock <IShotCounter> mockShotCounter,
                TestTarget, isAngleValid: true,
                isVelocityValid: false,
                shotCount: 1);

            // when TakeShot is called
            try
            {
                serviceToTest.TakeShot(currentShotCount: 0,
                                       angle: 45M, velocity: 10M, currentTarget: TestTarget);
            }
            catch (Exception)
            {
            }

            // then shot counter is not called
            mockShotCounter.Verify(x => x.AddShot(It.IsAny <int>()), Times.Never);
        }
Пример #3
0
 public CharacterManager(
     IGameState gameState,
     Lazy <INavigation> navigation,
     IGameFlow gameFlow,
     List <Character> characterList)
 {
     _gameState     = gameState ?? throw new ArgumentNullException(nameof(gameState));
     _navigation    = navigation ?? throw new ArgumentNullException(nameof(navigation));
     _gameFlow      = gameFlow ?? throw new ArgumentNullException(nameof(gameFlow));
     _characterList = characterList ?? throw new ArgumentNullException(nameof(characterList));
 }
Пример #4
0
        public void That_Start_CallsTargetGeneratorWithNoParamsOnce()
        {
            // given a game flow object
            IGameFlow serviceToTest = GetTestGameFlowObject(
                out Mock <ITargetGenerator> mockTargetGenerator,
                new Coordinate(x: 1, y: 2));

            // when GetNewTarget is called
            Coordinate actual = serviceToTest.GetNewTarget();

            // ITargetGenerator is called once
            mockTargetGenerator.Verify(x => x.GetTarget(), Times.Once);
        }
Пример #5
0
        public void That_Start_ReturnsTargetFromTargetGenerator()
        {
            // given a game flow object
            var testStartTarget = new Coordinate(x: 1, y: 2);

            IGameFlow serviceToTest = GetTestGameFlowObject(
                out Mock <ITargetGenerator> mockTargetGenerator,
                testStartTarget);

            // when GetNewTarget is called
            Coordinate actual = serviceToTest.GetNewTarget();

            // assert - returns target from TargetGenerator
            Assert.AreEqual(testStartTarget, actual);
        }
Пример #6
0
        public void That_TakeShot_CallsYCalculatorForValidShot()
        {
            IGameFlow serviceToTest = GetTestGameFlowObject(
                out Mock <IXCoordinateCalculator> mockXCalculator,
                out Mock <IYCoordinateCalculator> mockYCalculator,
                shotCount: 0);

            // when TakeShot is called
            serviceToTest.TakeShot(currentShotCount: 0,
                                   angle: 45M, velocity: 10M, currentTarget: TestTarget);

            // then YCalculator is called
            mockYCalculator.Verify(x => x.Get(It.IsAny <decimal>(), It.IsAny <decimal>()),
                                   Times.Once);
        }
Пример #7
0
        public MainForm(IStateDetector detector, IGameFlow flow)
        {
            CheckForIllegalCrossThreadCalls = false;

            _detector = detector;
            _flow     = flow;

            _flow.StateChanged += (sender, state) => { label2.Text = state.ToString(); };


            InitializeComponent();

            comboChar.SelectedIndex     = 0;
            comboGamePlan.SelectedIndex = 0;
        }
Пример #8
0
    public GameScore()
    {
        IGameFlow gameFlow = GameFacade.GameFlow;

        scoreChange    = new ValueChage <int>();
        timer          = new Timer();
        timer.Elapsed += HandleElapsed;

        gameFlow.GameStart   += (sender, e) => Start();
        gameFlow.GameStop    += (sender, e) => Pause();
        gameFlow.GameResume  += (sender, e) => Resume();
        gameFlow.GameRestart += (sender, e) => Restart();
        gameFlow.GamePause   += (sender, e) => Pause();
        gameFlow.GameExit    += (sender, e) => Stop();
    }
Пример #9
0
        public void That_TakeShot_CallsAngleValidatorOnce()
        {
            // given a game flow object
            IGameFlow serviceToTest = GetTestGameFlowObject(
                out Mock <ITargetGenerator> mockTargetGenerator,
                out Mock <IAngleValidator> mockAngleValidator,
                TestTarget, isAngleValid: true);

            // when TakeShot is called
            bool actual = serviceToTest.TakeShot(currentShotCount: 0,
                                                 angle: 45M, velocity: 10M, currentTarget: TestTarget);

            // IAngleValidator is called once
            mockAngleValidator.Verify(x => x.GetIsValid(It.IsAny <decimal>()),
                                      Times.Once);
        }
Пример #10
0
        public void That_TakeShot_CallsShotCounterForValidShot()
        {
            // given a game flow object
            IGameFlow serviceToTest = GetTestGameFlowObject(
                out Mock <ITargetGenerator> mockTargetGenerator,
                out Mock <IAngleValidator> mockAngleValidator,
                out Mock <IVelocityValidator> mockVelocityValidator,
                out Mock <IShotCounter> mockShotCounter,
                TestTarget, isAngleValid: true,
                isVelocityValid: true,
                shotCount: 1);

            // when TakeShot is called
            serviceToTest.TakeShot(currentShotCount: 0,
                                   angle: 45M, velocity: 10M, currentTarget: TestTarget);

            // then shot counter is called once
            mockShotCounter.Verify(x => x.AddShot(It.IsAny <int>()), Times.Once);
        }
Пример #11
0
        public void That_TakeShot_ReturnsTrueForValidShotMissed()
        {
            // given a game flow object
            var testStartTarget = new Coordinate(x: 1, y: 2);

            IGameFlow serviceToTest = GetTestGameFlowObject(
                out Mock <ITargetGenerator> mockTargetGenerator,
                out Mock <IAngleValidator> mockAngleValidator,
                out Mock <IVelocityValidator> mockVelocityValidator,
                out Mock <IShotCounter> mockShotCounter,
                out Mock <IXCoordinateCalculator> xCalculator,
                out Mock <IYCoordinateCalculator> yCalculator,
                testStartTarget, isAngleValid: true,
                isVelocityValid: true,
                shotCount: 1, xResult: 1, yResult: 2);

            // when TakeShot is called for vaid hit shot
            bool actual = serviceToTest.TakeShot(currentShotCount: 0,
                                                 angle: 45M, velocity: 10M, currentTarget: testStartTarget);

            // then true is returned
            Assert.IsTrue(actual);
        }
Пример #12
0
 private void InitGame()
 {
     GameFlow = new GameFlowController();
 }
Пример #13
0
 public HomeController(IGameFlow gameFlow)
 {
     _gameFlow = gameFlow;
 }
Пример #14
0
 public WelcomeViewPresenter()
 {
     gameFlow = GameFacade.GameFlow;
 }