public async Task Process_MultipleMessagesTogether()
        {
            // Setup client to return two success results.
            var messageIds = new Guid?[] { Guid.NewGuid(), Guid.NewGuid(), Guid.NewGuid() };
            var adapter    = GetInfobipAdapter(messageIds);

            // Add a message to the incoming request.
            var httpContext = new DefaultHttpContext();

            httpContext.Request.Body = new MemoryStream(Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(GetInfobipIncomingMessage())));

            var bot = new TestBot
            {
                OnMessageActivity = async(x, t, c) =>
                {
                    // Bot responds with multiple messages separately.
                    var responses = await t.SendActivitiesAsync(new[] { CreateMessageActivity(), CreateMessageActivity(), CreateMessageActivity() }, c).ConfigureAwait(false);

                    // We got a response for each message and they are in the order we sent them.
                    Assert.Equal(messageIds.Length, responses.Length);
                    for (var i = 0; i < messageIds.Length; ++i)
                    {
                        Assert.Equal(messageIds[i].Value.ToString(), responses[i].Id);
                    }
                }
            };

            await adapter.ProcessAsync(httpContext.Request, httpContext.Response, bot, CancellationToken.None).ConfigureAwait(false);

            // Bot was called 1x.
            Assert.Equal(1, bot.OnMessageActivityInvocationCount);
        }
        public async Task Process_SingleMessage()
        {
            // Setup client to return a success message.
            var messageId = Guid.NewGuid();
            var adapter   = GetInfobipAdapter(messageId);

            // Add a message to the incoming request.
            var httpContext = new DefaultHttpContext();

            httpContext.Request.Body = new MemoryStream(Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(GetInfobipIncomingMessage())));

            var bot = new TestBot
            {
                OnMessageActivity = async(_, t, c) =>
                {
                    // Configure the bot to reply to the message with a single activity.
                    var activity = CreateMessageActivity();
                    var response = await t.SendActivityAsync(activity, c).ConfigureAwait(false);

                    // Sending succeeds and bot gets the message id configured above.
                    Assert.Equal(messageId.ToString(), response.Id);
                }
            };

            await adapter.ProcessAsync(httpContext.Request, httpContext.Response, bot, CancellationToken.None).ConfigureAwait(false);

            // Bot was called 1x.
            Assert.Equal(1, bot.OnMessageActivityInvocationCount);
        }
        public async Task NoCallerIdShouldSetNullOAuthScope()
        {
            var mockCredentialProvider = new Mock <ICredentialProvider>();
            var mockSocket             = new Mock <WebSocket>();
            var bot     = new TestBot(null);
            var adapter = new MockAdapter(mockCredentialProvider.Object, bot);

            var originalActivity = CreateBasicActivity(); // Has no callerId, therefore OAuthScope in TurnState should be null.

            adapter.CreateStreamingRequestHandler(mockSocket.Object, originalActivity);

            await adapter.ProcessStreamingActivityAsync(originalActivity, bot.OnTurnAsync);
        }
Ejemplo n.º 4
0
        private void Test()
        {
            world = new World(new Size(300, 300));
            TestBot bot  = new TestBot(world, new Point(150, 150), new Point(2, 5));
            TestBot bot2 = new TestBot(world, new Point(250, 150), new Point(3, 1));
            TestBot bot3 = new TestBot(world, new Point(150, 250), new Point(-2, -3));

            //for (int i = 0; i < 200; i++)
            while (true)
            {
                world.Tick();
                this.Refresh();
            }
        }
        public async Task PublicCloudCallerIdShouldSetCorrectOAuthScope()
        {
            var mockCredentialProvider = new Mock <ICredentialProvider>();
            var mockSocket             = new Mock <WebSocket>();
            var oAuthScope             = AuthenticationConstants.ToBotFromChannelTokenIssuer;
            var bot     = new TestBot(oAuthScope);
            var adapter = new MockAdapter(mockCredentialProvider.Object, bot);

            var originalActivity = CreateBasicActivity();

            originalActivity.CallerId = CallerIdConstants.PublicAzureChannel;
            adapter.CreateStreamingRequestHandler(mockSocket.Object, originalActivity, oAuthScope);

            await adapter.ProcessStreamingActivityAsync(originalActivity, bot.OnTurnAsync);
        }
Ejemplo n.º 6
0
        internal AIEntity CreateAIBot(string name, Vector startPosition, string team, bool canMove)
        {
            var position   = startPosition;
            var maxHealth  = GetMaxHealth(WeaponCode.Axe);
            var attributes = new Attribute[] {
                new IntAttribute(maxHealth, AttributeCode.MaxHealth),
                new HealthAttribute(maxHealth),
                new ActionStateAttribute(),
                new FloatAttribute(0.2f, AttributeCode.Speed)
            };

            var entity   = new Entity(name, position, team, attributes, null);
            var aiEntity = new TestBot(entity);

            aiEntity.canMove = canMove;
            World.Instance.AddEntity(entity);
            return(aiEntity);
        }
        public void Process_MultipleMessagesTogether_OneFails()
        {
            // Setup client to throw for the 2nd message sent (1st and 3rd work fine).
            var messageIds = new Guid?[] { Guid.NewGuid(), null, Guid.NewGuid() };
            var adapter    = GetInfobipAdapter(messageIds);

            // Add a message to the incoming request.
            var httpContext = new DefaultHttpContext();

            httpContext.Request.Body = new MemoryStream(Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(GetInfobipIncomingMessage())));

            var bot = new TestBot
            {
                OnMessageActivity = async(x, t, c) =>
                {
                    // Bot responds with multiple messages separately.
                    var responses = await t.SendActivitiesAsync(new[] { CreateMessageActivity(), CreateMessageActivity(), CreateMessageActivity() }, c).ConfigureAwait(false);
                }
            };

            // Operation fails because send fails.
            Assert.ThrowsAsync <HttpRequestException>(async() => await adapter.ProcessAsync(httpContext.Request, httpContext.Response, bot, CancellationToken.None).ConfigureAwait(false));
        }