예제 #1
0
        public void InvokeICombatStatisticsContainerParameterAllComabtStatisticsProperty_AddMethodOnceWithCorrectParameter()
        {
            // Arrange
            var combatStatisticsFactory = new Mock <ICombatStatisticsFactory>();

            var enterCombatCommandResolutionHandler = new MockEnterCombatCommandResolutionHandler(combatStatisticsFactory.Object);

            var command = new Mock <ICommand>();
            var combatStatisticsContainer = new Mock <ICombatStatisticsContainer>();

            var currentCombatStatistics = new Mock <ICombatStatistics>();
            var allCombatStatistics     = new Mock <ICollection <ICombatStatistics> >();

            combatStatisticsContainer.SetupGet(c => c.AllCombatStatistics).Returns(allCombatStatistics.Object);
            combatStatisticsContainer.SetupGet(c => c.CurrentCombatStatistics).Returns(currentCombatStatistics.Object);

            var combatStatistics = new Mock <ICombatStatistics>();

            combatStatisticsFactory.Setup(f => f.CreateCombatStatistics()).Returns(combatStatistics.Object);

            // Act
            enterCombatCommandResolutionHandler.HandleCommand(command.Object, combatStatisticsContainer.Object);

            // Assert
            allCombatStatistics.Verify(s => s.Add(currentCombatStatistics.Object), Times.Once);
        }
예제 #2
0
        public void AssignCorrectInstance_ToICombatStatisticsContainerParameterCurrentComabtStatisticsProperty()
        {
            // Arrange
            var combatStatisticsFactory = new Mock <ICombatStatisticsFactory>();

            var enterCombatCommandResolutionHandler = new MockEnterCombatCommandResolutionHandler(combatStatisticsFactory.Object);

            var command = new Mock <ICommand>();
            var combatStatisticsContainer = new Mock <ICombatStatisticsContainer>();

            ICombatStatistics actualCombatStatisticsInstance = null;
            var currentCombatStatistics = new Mock <ICombatStatistics>();
            var allCombatStatistics     = new Mock <ICollection <ICombatStatistics> >();

            combatStatisticsContainer.SetupGet(c => c.AllCombatStatistics).Returns(allCombatStatistics.Object);
            combatStatisticsContainer.SetupGet(c => c.CurrentCombatStatistics).Returns(currentCombatStatistics.Object);
            combatStatisticsContainer.SetupSet(c => c.CurrentCombatStatistics = It.IsAny <ICombatStatistics>()).Callback <ICombatStatistics>((combatStats) => actualCombatStatisticsInstance = combatStats);

            var combatStatistics = new Mock <ICombatStatistics>();

            combatStatisticsFactory.Setup(f => f.CreateCombatStatistics()).Returns(combatStatistics.Object);

            var expectedComabtStatisticsInstance = combatStatistics.Object;

            // Act
            enterCombatCommandResolutionHandler.HandleCommand(command.Object, combatStatisticsContainer.Object);

            // Assert
            Assert.That(actualCombatStatisticsInstance, Is.SameAs(expectedComabtStatisticsInstance));
        }
예제 #3
0
        public void ReturnTheSameICombatStatisticsContainerInstance()
        {
            // Arrange
            var combatStatisticsFactory = new Mock <ICombatStatisticsFactory>();

            var enterCombatCommandResolutionHandler = new MockEnterCombatCommandResolutionHandler(combatStatisticsFactory.Object);

            var command = new Mock <ICommand>();
            var combatStatisticsContainer = new Mock <ICombatStatisticsContainer>();

            var currentCombatStatistics = new Mock <ICombatStatistics>();
            var allCombatStatistics     = new Mock <ICollection <ICombatStatistics> >();

            combatStatisticsContainer.SetupGet(c => c.AllCombatStatistics).Returns(allCombatStatistics.Object);
            combatStatisticsContainer.SetupGet(c => c.CurrentCombatStatistics).Returns(currentCombatStatistics.Object);

            var combatStatistics = new Mock <ICombatStatistics>();

            combatStatisticsFactory.Setup(f => f.CreateCombatStatistics()).Returns(combatStatistics.Object);

            var expectedReturnedInstance = combatStatisticsContainer.Object;

            // Act
            var actualReturnedInstance = enterCombatCommandResolutionHandler.HandleCommand(command.Object, combatStatisticsContainer.Object);

            // Assert
            Assert.That(actualReturnedInstance, Is.SameAs(expectedReturnedInstance));
        }
예제 #4
0
        public void InvokeICommandParameter_TimeStampPropertyGetMethodOnce()
        {
            // Arrange
            var combatStatisticsFactory = new Mock <ICombatStatisticsFactory>();

            var enterCombatCommandResolutionHandler = new MockEnterCombatCommandResolutionHandler(combatStatisticsFactory.Object);

            var command = new Mock <ICommand>();
            var combatStatisticsContainer = new Mock <ICombatStatisticsContainer>();

            var currentCombatStatistics = new Mock <ICombatStatistics>();
            var allCombatStatistics     = new Mock <ICollection <ICombatStatistics> >();

            combatStatisticsContainer.SetupGet(c => c.AllCombatStatistics).Returns(allCombatStatistics.Object);
            combatStatisticsContainer.SetupGet(c => c.CurrentCombatStatistics).Returns(currentCombatStatistics.Object);

            var combatStatistics = new Mock <ICombatStatistics>();

            combatStatisticsFactory.Setup(f => f.CreateCombatStatistics()).Returns(combatStatistics.Object);

            // Act
            enterCombatCommandResolutionHandler.HandleCommand(command.Object, combatStatisticsContainer.Object);

            // Assert
            command.VerifyGet(c => c.TimeStamp, Times.Exactly(2));
        }
예제 #5
0
        public void ReturnFalse_WhenICommandParameterEventNamePropertyIsDifferentComparedToEnterCombat(string eventName)
        {
            // Arrange
            var combatStatisticsFactory = new Mock <ICombatStatisticsFactory>();

            var enterCombatCommandResolutionHandler = new MockEnterCombatCommandResolutionHandler(combatStatisticsFactory.Object);

            var command = new Mock <ICommand>();

            command.SetupGet(c => c.EventName).Returns(eventName);

            // Act
            var actualResult = enterCombatCommandResolutionHandler.CanHandleCommand(command.Object);

            // Assert
            Assert.That(actualResult, Is.False);
        }
예제 #6
0
        public void ReturnTrue_WhenICommandParameterEventNamePropertyIsIdenticalToEnterCombat()
        {
            // Arrange
            var combatStatisticsFactory = new Mock <ICombatStatisticsFactory>();

            var enterCombatCommandResolutionHandler = new MockEnterCombatCommandResolutionHandler(combatStatisticsFactory.Object);

            var viableEventName = "EnterCombat";
            var command         = new Mock <ICommand>();

            command.SetupGet(c => c.EventName).Returns(viableEventName);

            // Act
            var actualResult = enterCombatCommandResolutionHandler.CanHandleCommand(command.Object);

            // Assert
            Assert.That(actualResult, Is.True);
        }