// Note: Example of handling asynchronous method completion. private static void WaitForFightCompleted(IFightStrategy target) { bool isFightCompleted = false; target.Completed += (s, e) => { isFightCompleted = true; }; SpinWait spintWait = new SpinWait(); DateTime start = DateTime.Now; while (DateTime.Now - start < new TimeSpan(0, 1, 0)) { // Note: Example of forcing Dispatcher to work in Unit Tests // Dispatcher does not automatically process events during tests, so I manually cause processing. DispatcherAssist.DoEvents(); spintWait.SpinOnce(); if (isFightCompleted) { return; } } Assert.Fail("Fight did not complete in expected amount of time."); }
public void WhenConstructedWithNullRepository_ThenThrows() { // Arrange Mock <IFightStrategy> mockFightStrategy = new Mock <IFightStrategy>(); ISuperRepository repository = null; IFightStrategy fightStrategy = mockFightStrategy.Object; // Act ChallengeArena actual = new ChallengeArena(repository, fightStrategy); // Assert }
public void WhenConstructed_ThenInitialized() { // Arrange Mock <ISuperRepository> mockRepository = new Mock <ISuperRepository>(); Mock <IFightStrategy> mockFightStrategy = new Mock <IFightStrategy>(); ISuperRepository repository = mockRepository.Object; IFightStrategy fightStrategy = mockFightStrategy.Object; // Act ChallengeArena actual = new ChallengeArena(repository, fightStrategy); // Assert Assert.IsNotNull(actual); }
public ChallengeArena(ISuperRepository repository, IFightStrategy fightStrategy) { if (repository == null) { throw new ArgumentNullException("repository"); } if (fightStrategy == null) { throw new ArgumentNullException("fightStrategy"); } this.repository = repository; this.fightStrategy = fightStrategy; this.Heroes = new ObservableCollection <SuperPerson>(); this.Villians = new ObservableCollection <SuperPerson>(); this.fightStrategy.Started += this.FightStrategy_Started; this.fightStrategy.Completed += this.FightStrategy_Completed; }
public void ChangeFightStrategy(IFightStrategy strategy) { this.army1.FightStrategy = strategy; this.army2.FightStrategy = strategy; }
public Army() { this.Units = new List <IUnit>(); this.FightStrategy = new StackFightStrategy(); }