public async Task GetChatResponseAsyncReturnsApiResponse()
        {
            var chatResponse = new ChatResponse();

            chatResponse.response = new List <string>();
            chatResponse.response.Add("hello world");
            chatResponse.confidence = .42;

            var handlerMock = new Mock <HttpMessageHandler>(MockBehavior.Strict);

            handlerMock.Protected().Setup <Task <HttpResponseMessage> >(
                "SendAsync",
                ItExpr.IsAny <HttpRequestMessage>(),
                ItExpr.IsAny <CancellationToken>()
                ).ReturnsAsync(new HttpResponseMessage()
            {
                StatusCode = HttpStatusCode.OK,
                Content    = new StringContent(JsonConvert.SerializeObject(chatResponse)),
            }).Verifiable();

            var httpClient = new HttpClient(handlerMock.Object)
            {
                BaseAddress = new Uri("http://test.com/"),
            };


            var botConfiguration = new BotConfiguration();
            var service          = new ChatResponseService(httpClient, botConfiguration);

            var result = await service.GetChatResponseAsync("test");

            Assert.Equal(chatResponse.response, result.response);
            Assert.Equal(chatResponse.confidence, result.confidence);
        }
Esempio n. 2
0
        static void Main(string[] args)
        {
            Startup startup = new Startup();
            var botConfiguration = startup.Configure();
            channelbotConfiguration = new ChannelConfigurationService(botConfiguration);
            botConfiguration.Channels = channelbotConfiguration.LoadChannels();

            var client = new HttpClient();
            var apiUtilityService = new ApiUtilityService(botConfiguration);

            chatResponseService = new ChatResponseService(client, apiUtilityService, botConfiguration);
            chatUpdateService = new ChatUpdateService(client, apiUtilityService, botConfiguration);
            userDetailService = new UserDetailService(client, botConfiguration);
            reactionService = new ReactionService(client, apiUtilityService, botConfiguration);
            reactionAddService = new ReactionAddService(client, apiUtilityService, botConfiguration);

            discord = new DiscordClient(new DiscordConfiguration
            {
                Token = botConfiguration.Token,
                TokenType = TokenType.Bot
            });

            botUtilityService = new BotUtilityService(discord, botConfiguration);
            commandService = new CommandService(botConfiguration, channelbotConfiguration);
            botReactionService = new BotReactionService(botConfiguration, new EmojiService(discord));
            requiredPropertyResponseService = new RequiredPropertyResponseService(discord, botUtilityService);

            MainAsync(args).ConfigureAwait(false).GetAwaiter().GetResult();
        }