public async Task Begin()
        {
            // Arrange
            var activity = new Activity()
            {
                ActivityType = ActivityType.Message,
                ChatId       = 15,
                Location     = new Location()
                {
                    Latitude = 15.6f, Longitude = 4.2f
                }
            };
            var turnContext = A.Fake <ITurnContext>();

            A.CallTo(() => turnContext.Activity).Returns(activity);
            var imageHuntState = new ImageHuntState()
            {
                Status = Status.Started
            };

            A.CallTo(() => turnContext.GetConversationState <ImageHuntState>()).Returns(imageHuntState);
            // Act
            await _target.Begin(turnContext);

            // Assert
            A.CallTo(() => turnContext.GetConversationState <ImageHuntState>()).MustHaveHappened();
            A.CallTo(() => _actionWebService.LogPosition(A <LogPositionRequest> ._, A <CancellationToken> ._)).MustHaveHappened();
            Check.That(imageHuntState.CurrentLatitude).Equals(15.6f);
            Check.That(imageHuntState.CurrentLongitude).Equals(4.2f);
            A.CallTo(() => _logger.Log(A <LogLevel> ._, A <EventId> ._, A <object> ._, A <Exception> ._,
                                       A <Func <object, Exception, string> > ._))
            .WithAnyArguments()
            .MustHaveHappened();
        }
Esempio n. 2
0
        public override async Task Begin(ITurnContext turnContext)
        {
            var state = turnContext.GetConversationState <ImageHuntState>();

            if (state.Status != Status.Started)
            {
                LogInfo <ImageHuntState>(turnContext, "Game not started");
                await turnContext.End();

                return;
            }
            state.CurrentLatitude  = turnContext.Activity.Location.Latitude;
            state.CurrentLongitude = turnContext.Activity.Location.Longitude;

            _logger.LogInformation($"Received position: [lat:{state.CurrentLatitude}, lng:{state.CurrentLongitude}");
            await base.Begin(turnContext);

            var logPositionRequest = new LogPositionRequest()
            {
                GameId    = state.GameId,
                TeamId    = state.TeamId,
                Latitude  = state.CurrentLatitude,
                Longitude = state.CurrentLongitude
            };
            await _actionWebService.LogPosition(logPositionRequest);

            //await turnContext.ReplyActivity(
            //  $"J'ai enregistré votre nouvelle position {state.CurrentLatitude}, {state.CurrentLongitude}");
            await turnContext.End();
        }