Exemple #1
0
        public void OnStart()
        {
            #region arrange
            //var gameLogicHandler = Substitute.For<ILogicHandler>();

            //var gameEngineInterface = Substitute.For<IGameEngineInterface>();
            var btnWinOk   = Substitute.For <IGameObject>();
            var pnlGameWin = Substitute.For <IGameObject>();
            _gameEngineInterface.FindGameObject(Arg.Any <string>()).Returns(btnWinOk, pnlGameWin);

            //var dataLayer = Substitute.For<IDataLayer>();

            //var winLogicProvider = new WinLogicProvider(gameLogicHandler, gameEngineInterface, dataLayer);

            #endregion

            #region act
            _winLogicProvider.OnStart();
            #endregion

            #region assert
            Assert.IsNotNull(btnWinOk.LogicHandler);
            pnlGameWin.Received().SetActive(false);
            _gameEngineInterface.Received(1).FindGameObject("btnGameWinOk");
            _gameEngineInterface.Received(1).FindGameObject("btnGameWinNextLevel");
            _gameEngineInterface.Received(1).FindGameObject("txtWinMessage");
            _gameEngineInterface.Received(1).FindGameObject("pnlGameWin");
            #endregion
        }
        public void OnStart()
        {
            _outOfLivesLogicProvider.OnStart();

            _gameEngineInterface.Received().FindGameObject("btnOutOfLivesOk");
            Assert.AreEqual(_logicHandler, _btnOutOfLivesOk.LogicHandler);

            _gameEngineInterface.Received().FindGameObject("pnlOutOfLives");
            _pnlOutOfLives.Received().SetActive(false);
        }
        public void OnStart()
        {
            _howToPlayLogicProvider.OnStart();

            _gameEngineInterface.Received(1).FindGameObject("pnlHowToPlay");
            _pnlHowToPlay.Received(1).SetActive(false);

            _gameEngineInterface.Received(1).FindGameObject("btnHowToPlayOk");
            Assert.AreEqual(_logicHandler, _btnHowToPlayOk.LogicHandler);
        }
        public void CalculateXMinAndXMax()
        {
            var result = CallPrivateMethod <float[]>(_asteroidPlacementLogicImplementer, "CalculateXMinAndXMax", new object[0]);

            _gameEngineInterface.Received(1).FindGameObject("MainCamera");

            _gameEngineInterface.ScreenUtils.Received(2).GetWorldPointFromScreenPoint(Arg.Any <IVector3>());

            _gameEngineInterface.ScreenUtils.ReceivedWithAnyArgs(2).GetWorldPointFromScreenPoint(null);
            //todo 2nd game: figure out how to check for receiving matching arguments when it's a reference type
            //_gameEngineInterface.ScreenUtils.Received(2).GetWorldPointFromScreenPoint(Arg.Is<Vector3>(v => v.X == 0 && v.Y == 0 && v.Z == CAMERA_HEIGHT));
            //_gameEngineInterface.ScreenUtils.ReceivedWithAnyArgs(2).GetWorldPointFromScreenPoint(Arg.Is<Vector3>(v => v.X == SCREEN_WIDTH && v.Y == 0 && v.Z == CAMERA_HEIGHT));
            Assert.IsNotNull(result);
            Assert.AreEqual(0, result[0]);
            Assert.AreEqual(WORLD_WIDTH, result[1]);
        }
        public void TestInitialize()
        {
            _sourceAsteroid = Substitute.For <IGameObject>();
            _playerShip     = Substitute.For <IGameObject>();
            _mainCamera     = Substitute.For <IGameObject>();

            _gameEngineInterface = Substitute.For <IGameEngineInterface>();
            _gameEngineInterface.FindGameObject("PlayerShip").Returns(_playerShip);
            _gameEngineInterface.FindGameObject("Asteroid").Returns(_sourceAsteroid);
            _gameEngineInterface.FindGameObject("MainCamera").Returns(_mainCamera);

            _sourceAsteroid.GetSize().X.Returns(2);
            _playerShip.GetSize().X.Returns(10);

            _asteroidPlacementLogicImplementer = new AsteroidPlacementLogicImplementer(_gameEngineInterface, _asteroidDensity);
            _asteroidPlacementLogicImplementer.SourceAsteroid   = _sourceAsteroid;
            _asteroidPlacementLogicImplementer.LogToDebugOutput = LogToDebugOutput;

            SetPrivateMember("X_MAX", _asteroidPlacementLogicImplementer, 40);
            SetPrivateMember("_asteroidDensity", _asteroidPlacementLogicImplementer, 1);

            //asserts for constructor test:
            _playerShip.Received().GetSize();
            _sourceAsteroid.Received().GetSize();

            _gameEngineInterface.Received(1).FindGameObject("PlayerShip");

            //these mocks used to be part of CalculateXMinAndXMax
            const float CAMERA_HEIGHT = 5;
            const int   SCREEN_WIDTH  = 100; //the screen is 100 pixels wide

            var leftEdgeOfScreen  = new Vector3(0, 0, 0);
            var rightEdgeOfScreen = new Vector3(SCREEN_WIDTH, 0, 0);

            _sourceAsteroid.Transform.Position.Y.Returns(0);
            _mainCamera.Transform.Position.Y.Returns(CAMERA_HEIGHT);

            _gameEngineInterface.Screen.Width.Returns(SCREEN_WIDTH);

            _gameEngineInterface.ScreenUtils = Substitute.For <IScreenUtils>();
            _gameEngineInterface.ScreenUtils
            .GetWorldPointFromScreenPoint(Arg.Is <IVector3>(v => v.X == 0 && v.Y == 0 && v.Z == CAMERA_HEIGHT))
            .Returns(new Vector3(0, 0, 0));

            _gameEngineInterface.ScreenUtils
            .GetWorldPointFromScreenPoint(Arg.Is <IVector3>(v => v.X == SCREEN_WIDTH && v.Y == 0 && v.Z == CAMERA_HEIGHT))
            .Returns(new Vector3(WORLD_WIDTH, 0, 0));
        }
        public void OnStart()
        {
            _getMoreLivesLogicProvider.OnStart();

            _gameEngineInterface.Received().FindGameObject("btnGetMoreLivesCancel");
            Assert.AreEqual(_logicHandler, _btnCancel.LogicHandler);

            _gameEngineInterface.Received().FindGameObject("btnBuyLivesSmall");
            Assert.AreEqual(_logicHandler, _btnBuyLivesSmall.LogicHandler);

            _gameEngineInterface.Received().FindGameObject("btnBuyLivesMedium");
            Assert.AreEqual(_logicHandler, _btnBuyLivesMedium.LogicHandler);

            _gameEngineInterface.Received().FindGameObject("btnBuyLivesLarge");
            Assert.AreEqual(_logicHandler, _btnBuyLivesLarge.LogicHandler);

            _gameEngineInterface.Received(1).FindGameObject("txtCurrentLives");
            _txtCurrentLivesGameObject.Received(1).GetComponent <IText>();

            _gameEngineInterface.Received().FindGameObject("pnlGetMoreLives");
            _pnlGetMoreLives.Received().SetActive(false);
        }
        public void OnStart_FirstLevel()
        {
            #region arrange
            _logicHandler.GameController.CurLevel = new LevelInfo(1, 1);
            _dataLayer.GetCurLevel().Returns(new LevelInfo(1, 1));

            var btnStart = Substitute.For <IGameObject>();
            _gameEngineInterface.FindGameObject("btnChooseLevelStart").Returns(btnStart);

            var btnCancel = Substitute.For <IGameObject>();
            _gameEngineInterface.FindGameObject("btnChooseLevelCancel").Returns(btnCancel);

            var btnNextLevel = Substitute.For <IGameObject>();
            _gameEngineInterface.FindGameObject("btnNextLevel").Returns(btnNextLevel);

            var btnPrevLevel = Substitute.For <IGameObject>();
            _gameEngineInterface.FindGameObject("btnPrevLevel").Returns(btnPrevLevel);
            #endregion

            #region act
            _chooseLevelLogicProvider.OnStart();
            #endregion

            #region
            _dataLayer.Received(1).GetCurLevel();

            _gameEngineInterface.Received(1).FindGameObject("txtSelectedLevel");
            _gameEngineInterface.Received(1).FindGameObject("btnChooseLevelStart");
            _gameEngineInterface.Received(1).FindGameObject("btnChooseLevelCancel");
            _gameEngineInterface.Received(1).FindGameObject("btnNextLevel");
            _gameEngineInterface.Received(1).FindGameObject("btnPrevLevel");
            _gameEngineInterface.Received(1).FindGameObject("pnlChooseLevel");

            Assert.IsNotNull(btnStart.LogicHandler);
            Assert.IsNotNull(btnCancel.LogicHandler);
            Assert.IsNotNull(btnNextLevel.LogicHandler);
            Assert.IsNotNull(btnPrevLevel.LogicHandler);

            btnPrevLevel.Received(1).SetActive(false);
            btnNextLevel.Received(1).SetActive(false);

            var selectedLevelIndex = GetPrivateMember <int>("_selectedLevelIndex", _chooseLevelLogicProvider);
            Assert.AreEqual(0, selectedLevelIndex);

            var maxLevelIndex = GetPrivateMember <int>("_maxLevelIndex", _chooseLevelLogicProvider);
            Assert.AreEqual(selectedLevelIndex, maxLevelIndex);

            var txtSelectedLevel = GetPrivateMember <IText>("_txtSelectedLevel", _chooseLevelLogicProvider);
            Assert.AreEqual("1-1", txtSelectedLevel.Text);
            #endregion
        }
        public void OnStart()
        {
            #region arrange
            _gameEngineInterface.AppStoreService = Substitute.For <IAppStoreService>();
            _gameEngineInterface.AppStoreService.OnPurchaseFailedEventHandler = null;

            var btnStartGame = Substitute.For <IGameObject>();
            btnStartGame.LogicHandler = null;
            _gameEngineInterface.FindGameObject("btnStartGame").Returns(btnStartGame);

            var btnGetMoreLives = Substitute.For <IGameObject>();
            btnGetMoreLives.LogicHandler = null;
            _gameEngineInterface.FindGameObject("btnGetMoreLives").Returns(btnGetMoreLives);

            var btnExitGame = Substitute.For <IGameObject>();
            btnExitGame.LogicHandler = null;
            _gameEngineInterface.FindGameObject("btnExitGame").Returns(btnExitGame);

            var btnPurchaseSucceededOk = Substitute.For <IGameObject>();
            btnPurchaseSucceededOk.LogicHandler = null;
            _gameEngineInterface.FindGameObject("btnStorePurchaseSucceededOk").Returns(btnPurchaseSucceededOk);

            var btnPurchaseFailedOk = Substitute.For <IGameObject>();
            btnPurchaseFailedOk.LogicHandler = null;
            _gameEngineInterface.FindGameObject("btnStorePurchaseFailedOk").Returns(btnPurchaseFailedOk);

            var pnlPurchaseSucceeded = Substitute.For <IGameObject>();
            _gameEngineInterface.FindGameObject("pnlStorePurchaseSucceeded").Returns(pnlPurchaseSucceeded);

            var pnlPurchaseFailed = Substitute.For <IGameObject>();
            _gameEngineInterface.FindGameObject("pnlStorePurchaseFailed").Returns(pnlPurchaseFailed);

            var pnlChooseLevel = Substitute.For <IGameObject>();
            _gameEngineInterface.FindGameObject("pnlChooseLevel").Returns(pnlChooseLevel);

            #endregion

            #region act
            _inMenuLogicProvider.OnStart();
            #endregion

            #region assert
            _gameEngineInterface.Received(1).FindGameObject("btnStartGame");
            Assert.IsNotNull(btnStartGame.LogicHandler);

            _gameEngineInterface.Received(1).FindGameObject("btnHowToPlay");
            Assert.IsNotNull(_btnHowToPlay.LogicHandler);

            _gameEngineInterface.Received(1).FindGameObject("btnShare");
            Assert.IsNotNull(_btnShare.LogicHandler);

            _gameEngineInterface.Received(1).FindGameObject("btnGetMoreLives");
            Assert.IsNotNull(btnGetMoreLives.LogicHandler);

            _gameEngineInterface.Received(1).FindGameObject("btnExitGame");
            Assert.IsNotNull(btnExitGame.LogicHandler);

            _gameEngineInterface.Received(1).FindGameObject("btnPrivacyPolicy");
            Assert.IsNotNull(_btnPrivacyPolicy.LogicHandler);

            _gameEngineInterface.Received(1).FindGameObject("txtVersionNumber");
            var expectedVersionNumber = "v" + _gameEngineInterface.AppVersion;
            Assert.AreEqual(expectedVersionNumber, _txtVersionNumber.Text);

            _gameEngineInterface.Received(1).FindGameObject("btnStorePurchaseSucceededOk");
            Assert.IsNotNull(btnPurchaseSucceededOk.LogicHandler);

            _gameEngineInterface.Received(1).FindGameObject("btnStorePurchaseFailedOk");
            Assert.IsNotNull(btnPurchaseFailedOk.LogicHandler);

            _gameEngineInterface.Received(1).FindGameObject("pnlMainMenu");
            _pnlMainMenu.Received(1).SetActive(false);

            _gameEngineInterface.Received(1).FindGameObject("pnlStorePurchaseSucceeded");
            pnlPurchaseSucceeded.Received(1).SetActive(false);

            _gameEngineInterface.Received(1).FindGameObject("pnlStorePurchaseFailed");
            pnlPurchaseFailed.Received(1).SetActive(false);

            _gameEngineInterface.Received(1).FindGameObject("pnlChooseLevel");
            pnlChooseLevel.Received(1).SetActive(false);

            Assert.AreEqual(1, _gameEngineInterface.TimeScale);

            Assert.IsNotNull(_gameEngineInterface.AppStoreService.OnPurchaseFailedEventHandler);
            #endregion
        }
        public void OnStart()
        {
            #region arrange
            var playerShip       = Substitute.For <IGameObject>();
            var playerShipScript = Substitute.For <IPlayerShipScript>();
            playerShipScript.GameEngineInterface = null;
            playerShip.GetComponent <IPlayerShipScript>().Returns(playerShipScript);
            _gameEngineInterface.FindGameObject("PlayerShip").Returns(playerShip);

            var quad = Substitute.For <IGameObject>();
            _gameEngineInterface.FindGameObject("Quad").Returns(quad);

            var txtLives   = Substitute.For <IGameObject>();
            var iTextLives = Substitute.For <IText>();
            txtLives.GetComponent <IText>().Returns(iTextLives);
            _gameEngineInterface.FindGameObject("txtLives").Returns(txtLives);

            var txtCurLevel   = Substitute.For <IGameObject>();
            var iTextCurLevel = Substitute.For <IText>();
            txtCurLevel.GetComponent <IText>().Returns(iTextCurLevel);
            _gameEngineInterface.FindGameObject("txtCurLevel").Returns(txtCurLevel);

            _dataLayer.GetNumLivesRemaining().Returns(1);

            _logicHandler.GameController = Substitute.For <IGameController>();
            _logicHandler.GameController.CurLevel.Returns(new LevelInfo(1, 1));

            _asteroidPlacementLogicImplementer.InitAsteroids(Arg.Any <int>(), Arg.Any <int>()).Returns((IGameObject)null);

            #endregion

            #region act
            _gameLogicProvider.OnStart();
            #endregion

            #region assert
            _gameEngineInterface.Received(1).FindGameObject("GlobalObject");
            _gameEngineInterface.Received(1).FindGameObject("PlayerShip");
            //_gameEngineInterface.Received(1).FindGameObject("PlayerShield");
            _gameEngineInterface.Received(1).FindGameObject("MainCamera");

            playerShip.Received().GetComponent <IPlayerShipScript>();
            Assert.IsNotNull(playerShipScript.GameEngineInterface);

            _gameEngineInterface.Received(1).FindGameObject("Asteroid");
            _gameEngineInterface.Received(1).FindGameObject("Explosion");
            _gameEngineInterface.Received(1).FindGameObject("Quad");
            quad.Received(1).EnableTextureWrapping();

            _gameEngineInterface.Received(1).FindGameObject("txtLives");
            Assert.AreEqual("LIVES: 1", iTextLives.Text);

            _gameEngineInterface.Received(1).FindGameObject("txtCurLevel");
            Assert.AreEqual("LEVEL: 1-1", iTextCurLevel.Text);

            _gameEngineInterface.Received(1).SetupLighting();

            _asteroidPlacementLogicImplementer.Received(1).InitAsteroids(Arg.Any <int>(), Arg.Any <int>());

            Assert.AreEqual(1, playerShipScript.Health);
            #endregion
        }