public Task <HandlerResponse> Handle(Message message)
        {
            if (message.RequestType != MessageType.StartRound)
            {
                return(Task.FromResult(NextHandler?.Handle(message).Result));
            }

            if (!FightContext.CanStartNewRound())
            {
                return(Task.FromResult(new HandlerResponse
                {
                    ResponseType = ResponseType.Skip
                }));
            }
            FightContext.StartRound();
            var roundId = FightContext.GetRoundNumber();

            return(Task.FromResult(new HandlerResponse
            {
                ResponseType = ResponseType.ToAll,
                Message = new Message
                {
                    RequestType = message.RequestType,
                    Data = roundId.ToString()
                }
            }));
        }
Exemple #2
0
        public void StartRound_ShouldStartRound()
        {
            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.StartRound();
            Thread.Sleep(1000);

            var state = fightContext.GetFightState();

            Assert.Equal(state.Id, 1);
            Assert.Equal(state.Paused, false);
            Assert.Equal(state.Started, true);
            Assert.True(state.RemainingTime > 1000);
            Assert.Equal(state.Round, 1);
            Assert.Equal(state.RedFighter.Id, "efgh");
            Assert.Equal(state.BlueFighter.Id, "abcd");
        }