Esempio n. 1
0
        public void ExecuteTest()
        {
            //Arrange
            int getValue = 42;

            bool onGetQuestIsEqualToExpected      = false;
            bool onActionOnQuestIsEqualToExpected = false;
            bool oldValueEqualsToValueFromGetter  = false;

            Quest quest = QuestHelper.CreateQuest();

            MockPropertyChangeQuestCommand command = new MockPropertyChangeQuestCommand();

            command.OnGetPropertyValue += q =>
            {
                onGetQuestIsEqualToExpected = quest == q;
                return(getValue);
            };
            command.OnActionOnQuest += (q, ov) =>
            {
                onActionOnQuestIsEqualToExpected = quest == q;
                oldValueEqualsToValueFromGetter  = ov == getValue;
            };

            //Act
            bool result = command.Execute(quest);

            //Assert
            Assert.IsTrue(result);

            Assert.IsTrue(onGetQuestIsEqualToExpected);
            Assert.IsTrue(onActionOnQuestIsEqualToExpected);
            Assert.IsTrue(oldValueEqualsToValueFromGetter);
        }
Esempio n. 2
0
        public void ExecuteSameQuestTwiceTest()
        {
            //Arrange
            int getPropertyValueCounter = 0;
            int actionOnQuestCounter    = 0;

            Quest quest = QuestHelper.CreateQuest();

            MockPropertyChangeQuestCommand command = new MockPropertyChangeQuestCommand();

            command.OnGetPropertyValue += q => getPropertyValueCounter++;
            command.OnActionOnQuest    += (q, ov) =>
            {
                actionOnQuestCounter++;
            };

            //Act
            bool firstResult  = command.Execute(quest);
            bool secondResult = command.Execute(quest);

            //Assert
            Assert.IsTrue(firstResult);
            Assert.IsFalse(secondResult);

            Assert.AreEqual(1, getPropertyValueCounter);
            Assert.AreEqual(1, actionOnQuestCounter);
        }
Esempio n. 3
0
        public void UndoAfterExecuteTest()
        {
            //Arrange
            int getValue = 42;

            Quest quest      = QuestHelper.CreateQuest();
            Quest questToSet = null;
            int   valueToSet = default(int);

            MockPropertyChangeQuestCommand command = new MockPropertyChangeQuestCommand();

            command.OnGetPropertyValue += q => getValue;
            command.OnActionOnQuest    += (q, ov) => { };
            command.OnSetPropertyValue += (q, v) =>
            {
                questToSet = q;
                valueToSet = v;
            };

            //Act
            command.Execute(quest);
            bool undoResult = command.Undo(quest);

            //Assert
            Assert.IsTrue(undoResult);
            Assert.AreEqual(quest, questToSet);
            Assert.AreEqual(getValue, valueToSet);
        }
Esempio n. 4
0
        public void UndoWithoutExecuteTest()
        {
            //Arrange
            int   setPropertyCalledValue = 0;
            Quest quest = QuestHelper.CreateQuest();

            MockPropertyChangeQuestCommand command = new MockPropertyChangeQuestCommand();

            command.OnSetPropertyValue += (q, v) => { setPropertyCalledValue++; };

            //Act
            bool undoResult = command.Undo(quest);

            //Assert
            Assert.IsFalse(undoResult);
            Assert.AreEqual(0, setPropertyCalledValue);
        }