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); }
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)); }
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)); }
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)); }