Пример #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 ActionResult Index(
            [Bind(Include = "Angle,Velocity,TargetX,TargetY,ShotsTaken")] GameFlowView model)
        {
            if (ModelState.IsValid)
            {
                model.WasTargetHit = _gameFlow.TakeShot(Request["ShotCount"].AsInt(),
                                                        model.Angle, model.Velocity,
                                                        new Coordinate(model.TargetX, model.TargetY));

                model.ShotsTaken = _gameFlow.GetShotCount();
            }
            return(View(model));
        }
Пример #4
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);
        }
Пример #5
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);
        }
Пример #6
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);
        }
Пример #7
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);
        }