Exemplo n.º 1
0
        public async Task Begin()
        {
            // Arrange
            var context  = A.Fake <ITurnContext>();
            var state    = new ImageHuntState();
            var activity = new Activity()
            {
                Text = "/init gameid=2 teamid=6", ChatId = 15
            };

            A.CallTo(() => context.GetConversationState <ImageHuntState>()).Returns(state);
            A.CallTo(() => context.Activity).Returns(activity);
            // Act
            await _target.Begin(context);

            // Assert
            Check.That(state.GameId).Equals(2);
            Check.That(state.TeamId).Equals(6);
            A.CallTo(() => _gameWebService.GetGameById(2, A <CancellationToken> ._)).MustHaveHappened();
            A.CallTo(() => _teamWebService.GetTeamById(6)).MustHaveHappened();
            Check.That(state.Status).Equals(Status.Initialized);
        }
Exemplo n.º 2
0
        public override async Task Begin(ITurnContext turnContext)
        {
            var state = turnContext.GetConversationState <ImageHuntState>();

            if (state.GameId != 0 && state.TeamId != 0)
            {
                var warningMessage = $"Le groupe {turnContext.ChatId} a déjà été initialisé!";
                await turnContext.ReplyActivity(warningMessage);

                LogInfo <ImageHuntState>(turnContext, warningMessage);
                await turnContext.End();

                return;
            }
            var regEx        = new Regex(@"(?i)\/init gameid=(\d*) teamid=(\d*)");
            var activityText = turnContext.Activity.Text;

            if (regEx.IsMatch(activityText))
            {
                var groups = regEx.Matches(activityText);
                state.GameId = Convert.ToInt32(groups[0].Groups[1].Value);
                state.TeamId = Convert.ToInt32(groups[0].Groups[2].Value);
                LogInfo <ImageHuntState>(turnContext, "Init");
                state.Game = await _gameWebService.GetGameById(state.GameId);

                state.Team = await _teamWebService.GetTeamById(state.TeamId);

                if (state.Game == null || state.Team == null)
                {
                    LogInfo <ImageHuntState>(turnContext, "Unable to find game");
                    await turnContext.ReplyActivity($"Impossible de trouver la partie pour l'Id={state.GameId} ou l'équipe pour l'Id={state.TeamId}");

                    state.GameId = state.TeamId = 0;
                    await turnContext.End();

                    return;
                }

                state.Status = Status.Initialized;
            }
            await base.Begin(turnContext);

            await turnContext.ReplyActivity(
                $"Le groupe de l'équipe {state.Team.Name} pour la chasse {state.Game.Name} qui débute le {state.Game.StartDate} est prêt, bon jeu!");

            await turnContext.End();
        }