Пример #1
0
        public void TestIfBombWithSizeFiveExplodesAsExpected()
        {
            string testFieldSize = "6";


            Engine.FieldSizeUnitTestSetter     = new StringReader(testFieldSize);
            Engine.StartMenu.IsStartGameChosen = true;
            Engine    gameEngine = new Engine();
            Playfield testField  = Playfield.Instance;

            testField.SetFieldSize(6);
            testField.InitializeEmptyField();
            testField[4, 4] = new BombCell(5);

            PrivateObject enginePrivateInstance = new PrivateObject(gameEngine);

            enginePrivateInstance.Invoke("HandleExplosion", testField[4, 4]);
            Playfield engineField = (Playfield)enginePrivateInstance.GetFieldOrProperty("playField");
            BombCell  bomb        = new BombCell(5);

            bomb.X            = 4;
            bomb.Y            = 4;
            engineField[4, 4] = bomb;

            enginePrivateInstance.Invoke("ChangeCurrentCell", 4, 4);
            enginePrivateInstance.Invoke("HandleExplosion", engineField[4, 4]);

            Assert.AreEqual(engineField[4, 4].CellType == CellType.BlownCell, true, "Expected that the cell on coordinates 4,5 is CellType.BlownCell. Received {0} ", engineField[4, 4].CellType);
        }
Пример #2
0
        public void TestIfOnDirectionKeyPressedReturnsTrue()
        {
            string testFieldSize = "6";


            Engine.FieldSizeUnitTestSetter     = new StringReader(testFieldSize);
            Engine.StartMenu.IsStartGameChosen = true;
            Engine    gameEngine = new Engine();
            Playfield testField  = Playfield.Instance;

            testField.SetFieldSize(6);
            testField.InitializeEmptyField();


            PrivateObject enginePrivateInstance = new PrivateObject(gameEngine);
            var           output = enginePrivateInstance.Invoke("OnDirectionKeyPressed", ConsoleKey.UpArrow);

            Assert.IsTrue((bool)output, "When left key arrow is pressed should return true");

            output = enginePrivateInstance.Invoke("OnDirectionKeyPressed", ConsoleKey.LeftArrow);

            Assert.IsTrue((bool)output, "When left key arrow is pressed should return true");

            output = enginePrivateInstance.Invoke("OnDirectionKeyPressed", ConsoleKey.RightArrow);

            Assert.IsTrue((bool)output, "When left key arrow is pressed should return true");

            output = enginePrivateInstance.Invoke("OnDirectionKeyPressed", ConsoleKey.DownArrow);

            Assert.IsTrue((bool)output, "When left key arrow is pressed should return true");

            output = enginePrivateInstance.Invoke("OnDirectionKeyPressed", ConsoleKey.E);

            Assert.IsFalse((bool)output, "When left key arrow is pressed should return true");
        }
Пример #3
0
        public void LoadMethodThrowsExeptionIfNullArgumentIsPassed()
        {
            Playfield testField = Playfield.Instance;

            testField.SetFieldSize(5);
            testField.InitializeEmptyField();

            testField.LoadMemento(null);
        }
Пример #4
0
        public void InitializeEmptyFieldThrowsExeptionIfCellsIsNull()
        {
            //Engine.StartMenu.IsQuitGameChosen = false;
            //Engine.StartMenu.IsStartGameChosen = true;
            //Engine gameEngine = new Engine();
            Playfield testField = Playfield.Instance;

            testField.InitializeEmptyField();
        }
Пример #5
0
        /// <summary>
        /// A new instance of a playfield is initialized.
        /// </summary>
        /// <param name="sizeOfField">Integer sizeOfField.</param>
        /// <returns>Returns the field.</returns>
        private Playfield InitializeField(int sizeOfField)
        {
            Playfield field = Playfield.Instance;

            field.SetFieldSize(sizeOfField);
            field.InitializeEmptyField();
            field.PlaceMines();

            return(field);
        }
Пример #6
0
        public void SaveMethodCannotReturnNull()
        {
            Playfield testField = Playfield.Instance;

            testField.SetFieldSize(5);
            testField.InitializeEmptyField();
            testField.PlaceMines();

            Assert.IsNotNull(testField.SaveMemento(), "Zero-based playfield backup cannot be null");
        }
Пример #7
0
        public void SaveMethodCannotReturnMementoWithNullZeroBaseArray()
        {
            Playfield testField = Playfield.Instance;

            testField.SetFieldSize(5);
            testField.InitializeEmptyField();
            testField.PlaceMines();

            MementoField memento = new MementoField();

            memento = testField.SaveMemento();

            Assert.IsNotNull(memento.ZeroBasedPlayField, "Zero-based playfield backup cannot be null");
        }
Пример #8
0
        public void TestOnCurrentCellChangedDontRiseEvent()
        {
            string testFieldSize = "6";


            Engine.FieldSizeUnitTestSetter     = new StringReader(testFieldSize);
            Engine.StartMenu.IsStartGameChosen = true;
            Engine    gameEngine = new Engine();
            Playfield testField  = Playfield.Instance;

            testField.SetFieldSize(6);
            testField.InitializeEmptyField();


            PrivateObject enginePrivateInstance = new PrivateObject(gameEngine);

            enginePrivateInstance.Invoke("OnCurrentCellChanged", new CellEventArgs(new EmptyCell()));
        }
Пример #9
0
        public void TestIfHandleExplosionHandleAllCases()
        {
            string testFieldSize = "6";


            Engine.FieldSizeUnitTestSetter     = new StringReader(testFieldSize);
            Engine.StartMenu.IsStartGameChosen = true;
            Engine    gameEngine = new Engine();
            Playfield testField  = Playfield.Instance;

            testField.SetFieldSize(6);
            testField.InitializeEmptyField();


            PrivateObject enginePrivateInstance = new PrivateObject(gameEngine);

            enginePrivateInstance.Invoke("HandleExplosion", new BombCell(1));
            enginePrivateInstance.Invoke("HandleExplosion", new BombCell(2));
            enginePrivateInstance.Invoke("HandleExplosion", new BombCell(3));
            enginePrivateInstance.Invoke("HandleExplosion", new BombCell(4));
        }
Пример #10
0
        public void TestIfOnSaveLoadButtonPressedReturnsTrue()
        {
            string testFieldSize = "6";


            Engine.FieldSizeUnitTestSetter     = new StringReader(testFieldSize);
            Engine.StartMenu.IsStartGameChosen = true;
            Engine    gameEngine = new Engine();
            Playfield testField  = Playfield.Instance;

            testField.SetFieldSize(6);
            testField.InitializeEmptyField();


            PrivateObject enginePrivateInstance = new PrivateObject(gameEngine);
            var           output = enginePrivateInstance.Invoke("OnSaveLoadButtonPressed", ConsoleKey.F5);

            Assert.IsTrue((bool)output, "When save key is pressed should return true");

            output = enginePrivateInstance.Invoke("OnSaveLoadButtonPressed", ConsoleKey.F6);

            Assert.IsTrue((bool)output, "When load button is pressed should return true");
        }