public void LevelUpHeroThenKillHim_ResultsInClassesAndRacesUnchanged_Test() { // Arrange var dwarf = "Dwarf"; var priest = "Priest"; var quest = QuestFactory.CreateStartedWithMaleHero( out var gameStore, out var gameId, out var playerId, out var sequence); var raceMessage = RaceMessage.CreateAdd(sequence.Next, playerId, new[] { dwarf }); var classMessage = ClassMessage.CreateAdd(sequence.Next, playerId, new[] { priest }); var deathMsg = DeathMessage.Create(sequence.Next, playerId); // Act quest.AddMessage(gameId, raceMessage); quest.AddMessage(gameId, classMessage); var game = quest.AddMessage(gameId, deathMsg); // Assert var hero = game.GetHero(playerId); Assert.Single(hero.Races); Assert.Single(hero.Classes); }
public void RemoveNotExistingRaceFromHero_ThrowsException_Test() { // Arrange var removeRaceMessage = RaceMessage.CreateRemove(_sequence.Next, _playerId, new[] { _humanRace }); // Act & Assert Assert.Throws<InvalidActionException>(() => _quest.AddMessage(_gameId, removeRaceMessage)); }
public void RemoveRaceFromUnknownHero_ThrowsException_Test() { // Arrange var removeRaceMessage = RaceMessage.CreateRemove(_sequence.Next, Guid.NewGuid(), new[] { _humanRace }); // Act & Assert Assert.Throws<InvalidActionException>(() => _quest.AddMessage(_gameId, removeRaceMessage)); }
public void AddRaceToHeroTwice_ThrowsException_Test() { // Arrange var addRaceMessage = RaceMessage.CreateAdd(_sequence.Next, _playerId, new[] { _humanRace }); var addAnotherRaceMessage = RaceMessage.CreateAdd(_sequence.Next, _playerId, new[] { _humanRace }); // Act & Assert _quest.AddMessage(_gameId, addRaceMessage); Assert.Throws<InvalidActionException>(() => _quest.AddMessage(_gameId, addAnotherRaceMessage)); }
public void AddRaceToHero_ThenUndoIt_ResultsInNoChange_Test() { // Arrange var addRaceMessage = RaceMessage.CreateAdd(_sequence.Next, _playerId, new[] { _humanRace }); // Act _quest.AddMessage(_gameId, addRaceMessage); var game = _quest.Undo(_gameId); // Assert Assert.Empty(game.Score.Heroes.First(x => x.Player.Id == _playerId).Races); }
public void AddRaceToHero_ResultsInAddedRace_Test() { // Arrange var addRaceMessage = RaceMessage.CreateAdd(_sequence.Next, _playerId, new[] { _humanRace }); // Act var game = _quest.AddMessage(_gameId, addRaceMessage); // Assert Assert.Single(game.Score.Heroes.First(x => x.Player.Id == _playerId).Races); Assert.Contains(_humanRace, game.Score.Heroes.First(x => x.Player.Id == _playerId).Races); }
public void AddRaceToHero_ThenSwitchIt_ResultsInSwitchedRace_Test() { // Arrange var addRaceMessage = RaceMessage.CreateAdd(_sequence.Next, _playerId, new[] { _humanRace }); var switchRaceMessage = RaceMessage.Create(_sequence.Next, _playerId, new[] { _dwarfRace }, new[] { _humanRace }); // Act _quest.AddMessage(_gameId, addRaceMessage); var game = _quest.AddMessage(_gameId, switchRaceMessage); // Assert Assert.Single(game.Score.Heroes.First(x => x.Player.Id == _playerId).Races); Assert.Equal(_dwarfRace, game.Score.Heroes.First(x => x.Player.Id == _playerId).Races.First()); }
private void UpdateRaceData(RaceMessage msg) { if (Race == null) { Race = msg.Race; RaceChanged?.Invoke(this, new EventArgs()); GoalChanged?.Invoke(this, new EventArgs()); UserListRefreshed?.Invoke(this, new EventArgs()); return; } switch (msg.Race?.State) { case RaceState.Starting: Model.CurrentState.Run.Offset = -msg.Race.StartDelay; Model.Start(); break; case RaceState.Cancelled: Model.Reset(); break; } if (RacetimeAPI.Instance.Authenticator.Identity == null) { return; } if ((Race.State == RaceState.Open || Race.State == RaceState.OpenInviteOnly) && Model.CurrentState.Run.Offset < TimeSpan.Zero && (msg.Race.StartDelay != Race.StartDelay)) { Model.CurrentState.Run.Offset = -msg.Race.StartDelay; } Race = msg.Race ?? Race; var newIdentity = msg.Race.Entrants?.FirstOrDefault(x => x.Name.ToLower() == RacetimeAPI.Instance.Authenticator.Identity.Name?.ToLower()); switch (newIdentity?.Status) { case UserStatus.Racing: Model.CurrentState.Run.Offset = DateTime.UtcNow - msg.Race.StartedAt; if (Model.CurrentState.CurrentPhase == TimerPhase.Ended) { Model.UndoSplit(); } if (Model.CurrentState.CurrentPhase == TimerPhase.Paused) { Model.Pause(); } if (Model.CurrentState.CurrentPhase == TimerPhase.NotRunning) { Model.Start(); } break; case UserStatus.Disqualified: Model.Reset(); break; case UserStatus.Finished: Model.Split(); break; case UserStatus.Forfeit: Model.Reset(); break; } RaceChanged?.Invoke(this, new EventArgs()); StateChanged?.Invoke(this, Race.State); UserListRefreshed?.Invoke(this, new EventArgs()); GoalChanged?.Invoke(this, new EventArgs()); }