public void EndRound_ShouldEndRound() { var context = new Mocks().GetDefaultDatabaseContext(); var fightEntity = new Fight { Id = 1, BlueAthleteId = "abcd", RedAthleteId = "efgh", Structure = new FightStructure() { Round = new Round() { BreakDuration = 1000, Duration = 3000, RoundsCount = 3 } } }; context.Fights.Add(fightEntity); context.SaveChanges(); var fightContext = new FightContext(context); fightContext.InitState(1); fightContext.EndRound(); Thread.SpinWait(1000); var state = fightContext.GetFightState(); Assert.Equal(state.Id, 1); Assert.Equal(state.Paused, false); Assert.Equal(state.Started, false); Assert.True(state.RemainingTime < 1000); Assert.Equal(state.Round, 1); Assert.Equal(state.RedFighter.Id, "efgh"); Assert.Equal(state.BlueFighter.Id, "abcd"); }
public Task <HandlerResponse> Handle(Message message) { if (message.RequestType != MessageType.PersisedState) { return(Task.FromResult(NextHandler?.Handle(message).Result)); } if (FightContext.GetFightId() == 0) { var fightId = message.Data.ToInt(); FightContext.InitState(fightId); } var serializedState = FightContext.GetFightState().Serialize(); return(Task.FromResult(new HandlerResponse { ResponseType = ResponseType.ToSelf, Message = new Message { RequestType = MessageType.PersisedState, Data = serializedState } })); }