Initial unit tests for ASP.NET WebAPI integration
* Adds initial set of unit tests for ASP.NET WebAPI integration `HttpConfigurationExtensions` class * Fixes #562 by defaulting to an empty `SimpleCredentialProvider` instance whenever an explicit `ICredentialProvider` is not supplied via configuration options (NOTE: this enables the local dev + emulator scenario) * Add unit test for ASP.NET Core integration that validate #562
This commit is contained in:
Родитель
8b33180055
Коммит
8fd28ed54d
|
@ -102,6 +102,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Integration", "Integration"
|
|||
EndProject
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AspNet.Core.Tests", "tests\integration\AspNet.Core.Tests\AspNet.Core.Tests.csproj", "{8A81D4F6-4E96-472B-9AE8-E1CAA5CC76FD}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AspNet.WebApi.Tests", "tests\integration\AspNet.WebApi.Tests\AspNet.WebApi.Tests.csproj", "{2614D290-1345-4A41-BE90-F85F817CEADE}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug - NuGet Packages|Any CPU = Debug - NuGet Packages|Any CPU
|
||||
|
@ -430,6 +432,14 @@ Global
|
|||
{8A81D4F6-4E96-472B-9AE8-E1CAA5CC76FD}.Documentation|Any CPU.Build.0 = Debug|Any CPU
|
||||
{8A81D4F6-4E96-472B-9AE8-E1CAA5CC76FD}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{8A81D4F6-4E96-472B-9AE8-E1CAA5CC76FD}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{2614D290-1345-4A41-BE90-F85F817CEADE}.Debug - NuGet Packages|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{2614D290-1345-4A41-BE90-F85F817CEADE}.Debug - NuGet Packages|Any CPU.Build.0 = Debug|Any CPU
|
||||
{2614D290-1345-4A41-BE90-F85F817CEADE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{2614D290-1345-4A41-BE90-F85F817CEADE}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{2614D290-1345-4A41-BE90-F85F817CEADE}.Documentation|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{2614D290-1345-4A41-BE90-F85F817CEADE}.Documentation|Any CPU.Build.0 = Debug|Any CPU
|
||||
{2614D290-1345-4A41-BE90-F85F817CEADE}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{2614D290-1345-4A41-BE90-F85F817CEADE}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
|
@ -482,6 +492,7 @@ Global
|
|||
{91178F5C-303C-43B8-9284-84125FB07FFF} = {3ADFB27A-95FA-4330-B211-1D66A29A17AB}
|
||||
{0A0E26B0-7A46-4F1A-8BFE-9A763FDF6CF8} = {AD743B78-D61F-4FBF-B620-FA83CE599A50}
|
||||
{8A81D4F6-4E96-472B-9AE8-E1CAA5CC76FD} = {0A0E26B0-7A46-4F1A-8BFE-9A763FDF6CF8}
|
||||
{2614D290-1345-4A41-BE90-F85F817CEADE} = {0A0E26B0-7A46-4F1A-8BFE-9A763FDF6CF8}
|
||||
EndGlobalSection
|
||||
GlobalSection(ExtensibilityGlobals) = postSolution
|
||||
SolutionGuid = {7173C9F3-A7F9-496E-9078-9156E35D6E16}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<Version Condition=" '$(BUILD_BUILDNUMBER)' == '' ">4.0.0-local</Version>
|
||||
|
@ -69,4 +69,10 @@
|
|||
<ProjectReference Include="..\..\Microsoft.Bot.Connector\Microsoft.Bot.Connector.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<AssemblyAttribute Include="System.Runtime.CompilerServices.InternalsVisibleTo">
|
||||
<_Parameter1>Microsoft.Bot.Builder.Integration.AspNet.Core.Tests</_Parameter1>
|
||||
</AssemblyAttribute>
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
|
|
@ -2,6 +2,9 @@
|
|||
// Licensed under the MIT License.
|
||||
|
||||
using Microsoft.Bot.Builder.Adapters;
|
||||
using Microsoft.Bot.Builder.BotFramework;
|
||||
using Microsoft.Bot.Connector.Authentication;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Options;
|
||||
using Newtonsoft.Json;
|
||||
|
@ -35,6 +38,14 @@ namespace Microsoft.Bot.Builder.Integration.AspNet.Core
|
|||
services.Configure(configureAction);
|
||||
}
|
||||
|
||||
services.PostConfigure<BotFrameworkOptions>(options =>
|
||||
{
|
||||
if (options.CredentialProvider== null)
|
||||
{
|
||||
options.CredentialProvider = new SimpleCredentialProvider();
|
||||
}
|
||||
});
|
||||
|
||||
services.AddTransient<IBot, TBot>();
|
||||
|
||||
services.AddSingleton(sp =>
|
||||
|
|
|
@ -12,6 +12,8 @@ namespace Microsoft.Bot.Builder.Integration.AspNet.WebApi.Handlers
|
|||
{
|
||||
public sealed class BotMessageHandler : BotMessageHandlerBase
|
||||
{
|
||||
internal static readonly string RouteName = "BotFramework - Message Handler";
|
||||
|
||||
public BotMessageHandler(BotFrameworkAdapter botFrameworkAdapter) : base(botFrameworkAdapter)
|
||||
{
|
||||
}
|
||||
|
|
|
@ -39,6 +39,8 @@ namespace Microsoft.Bot.Builder.Integration.AspNet.WebApi.Handlers
|
|||
_botFrameworkAdapter = botFrameworkAdapter ?? throw new ArgumentNullException(nameof(botFrameworkAdapter));
|
||||
}
|
||||
|
||||
internal BotFrameworkAdapter BotFrameworkAdapter => _botFrameworkAdapter;
|
||||
|
||||
protected override async Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
|
||||
{
|
||||
if (request.Method != HttpMethod.Post)
|
||||
|
|
|
@ -13,6 +13,8 @@ namespace Microsoft.Bot.Builder.Integration.AspNet.WebApi.Handlers
|
|||
{
|
||||
public sealed class BotProactiveMessageHandler : BotMessageHandlerBase
|
||||
{
|
||||
internal static readonly string RouteName = "BotFramework - Proactive Message Handler";
|
||||
|
||||
public BotProactiveMessageHandler(BotFrameworkAdapter botFrameworkAdapter) : base(botFrameworkAdapter)
|
||||
{
|
||||
}
|
||||
|
|
|
@ -3,7 +3,9 @@
|
|||
|
||||
using Microsoft.Bot.Builder.Adapters;
|
||||
using Microsoft.Bot.Builder.Integration.AspNet.WebApi.Handlers;
|
||||
using Microsoft.Bot.Connector.Authentication;
|
||||
using System;
|
||||
using System.Configuration;
|
||||
using System.Web.Http;
|
||||
|
||||
namespace Microsoft.Bot.Builder.Integration.AspNet.WebApi
|
||||
|
@ -18,10 +20,15 @@ namespace Microsoft.Bot.Builder.Integration.AspNet.WebApi
|
|||
/// <returns>A reference to this instance after the operation has completed.</returns>
|
||||
public static HttpConfiguration MapBotFramework(this HttpConfiguration httpConfiguration, Action<BotFrameworkConfigurationBuilder> configurer = null)
|
||||
{
|
||||
if (httpConfiguration == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(httpConfiguration));
|
||||
}
|
||||
|
||||
var options = new BotFrameworkOptions();
|
||||
var optionsBuilder = new BotFrameworkConfigurationBuilder(options);
|
||||
|
||||
configurer(optionsBuilder);
|
||||
configurer?.Invoke(optionsBuilder);
|
||||
|
||||
var botFrameworkAdapter = GetOrCreateBotFrameworkAdapter();
|
||||
|
||||
|
@ -34,7 +41,9 @@ namespace Microsoft.Bot.Builder.Integration.AspNet.WebApi
|
|||
{
|
||||
if (!(httpConfiguration.DependencyResolver.GetService(typeof(BotFrameworkAdapter)) is BotFrameworkAdapter adapter))
|
||||
{
|
||||
adapter = new BotFrameworkAdapter(options.CredentialProvider, options.ConnectorClientRetryPolicy, options.HttpClient);
|
||||
var credentialProvider = ResolveCredentialProvider();
|
||||
|
||||
adapter = new BotFrameworkAdapter(credentialProvider, options.ConnectorClientRetryPolicy, options.HttpClient);
|
||||
}
|
||||
|
||||
return adapter;
|
||||
|
@ -61,7 +70,7 @@ namespace Microsoft.Bot.Builder.Integration.AspNet.WebApi
|
|||
if (options.EnableProactiveMessages)
|
||||
{
|
||||
routes.MapHttpRoute(
|
||||
"BotFramework - Proactive Message Handler",
|
||||
BotProactiveMessageHandler.RouteName,
|
||||
baseUrl + options.Paths.ProactiveMessagesPath,
|
||||
defaults: null,
|
||||
constraints: null,
|
||||
|
@ -69,12 +78,25 @@ namespace Microsoft.Bot.Builder.Integration.AspNet.WebApi
|
|||
}
|
||||
|
||||
routes.MapHttpRoute(
|
||||
"BotFramework - Message Handler",
|
||||
BotMessageHandler.RouteName,
|
||||
baseUrl + options.Paths.MessagesPath,
|
||||
defaults: null,
|
||||
constraints: null,
|
||||
handler: new BotMessageHandler(adapter));
|
||||
}
|
||||
}
|
||||
|
||||
ICredentialProvider ResolveCredentialProvider()
|
||||
{
|
||||
var credentialProvider = options.CredentialProvider;
|
||||
|
||||
// If a credential provider was explicitly configured, just return that straight away
|
||||
if (credentialProvider != null)
|
||||
{
|
||||
return credentialProvider;
|
||||
}
|
||||
|
||||
return new SimpleCredentialProvider(ConfigurationManager.AppSettings[MicrosoftAppCredentials.MicrosoftAppIdKey], ConfigurationManager.AppSettings[MicrosoftAppCredentials.MicrosoftAppPasswordKey]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,4 +1,4 @@
|
|||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<Version Condition=" '$(BUILD_BUILDNUMBER)' == '' ">4.0.0-local</Version>
|
||||
|
@ -8,7 +8,7 @@
|
|||
<Configurations>Debug;Release;Documentation;Debug - NuGet Packages;</Configurations>
|
||||
</PropertyGroup>
|
||||
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
|
||||
<SignAssembly>true</SignAssembly>
|
||||
<DelaySign>true</DelaySign>
|
||||
<AssemblyOriginatorKeyFile>..\..\..\build\35MSSharedLib1024.snk</AssemblyOriginatorKeyFile>
|
||||
|
@ -69,7 +69,14 @@
|
|||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Reference Include="System.Configuration" />
|
||||
<Reference Include="System.Web" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<AssemblyAttribute Include="System.Runtime.CompilerServices.InternalsVisibleTo">
|
||||
<_Parameter1>Microsoft.Bot.Builder.Integration.AspNet.WebApi.Tests</_Parameter1>
|
||||
</AssemblyAttribute>
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
|
|
@ -7,7 +7,7 @@ using Microsoft.Extensions.Options;
|
|||
using Moq;
|
||||
using Xunit;
|
||||
|
||||
namespace AspNet.Core
|
||||
namespace Microsoft.Bot.Builder.Integration.AspNet.Core.Tests
|
||||
{
|
||||
public class ApplicationBuilderExtensionsTests
|
||||
{
|
||||
|
|
|
@ -4,10 +4,15 @@
|
|||
<TargetFramework>netcoreapp2.0</TargetFramework>
|
||||
|
||||
<IsPackable>false</IsPackable>
|
||||
|
||||
<AssemblyName>Microsoft.Bot.Builder.Integration.AspNet.Core.Tests</AssemblyName>
|
||||
|
||||
<RootNamespace>Microsoft.Bot.Builder.Integration.AspNet.Core.Tests</RootNamespace>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="FluentAssertions" Version="5.3.0" />
|
||||
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="2.0.0" />
|
||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.7.0" />
|
||||
<PackageReference Include="Moq" Version="4.8.2" />
|
||||
<PackageReference Include="xunit" Version="2.4.0-beta.1.build3958" />
|
||||
|
|
|
@ -1,20 +1,17 @@
|
|||
using System;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.Bot;
|
||||
using Microsoft.Bot.Builder;
|
||||
using FluentAssertions;
|
||||
using Microsoft.Bot.Builder.Adapters;
|
||||
using Microsoft.Bot.Builder.Integration.AspNet.Core;
|
||||
using Microsoft.Bot.Connector.Authentication;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Options;
|
||||
using FluentAssertions;
|
||||
using Moq;
|
||||
using Xunit;
|
||||
|
||||
namespace AspNet.Core
|
||||
namespace Microsoft.Bot.Builder.Integration.AspNet.Core.Tests
|
||||
{
|
||||
public class ServiceCollectionExtensionsTests
|
||||
{
|
||||
public class AddBot
|
||||
public class AddBotTests
|
||||
{
|
||||
[Fact]
|
||||
public void NullServiceCollectionThrows()
|
||||
|
@ -64,14 +61,6 @@ namespace AspNet.Core
|
|||
serviceCollectionMock.Verify(sc => sc.Add(It.Is<ServiceDescriptor>(sd => sd.ServiceType == typeof(BotFrameworkAdapter) && sd.Lifetime == ServiceLifetime.Singleton)));
|
||||
serviceCollectionMock.Verify(sc => sc.Add(It.Is<ServiceDescriptor>(sd => sd.ServiceType == typeof(IConfigureOptions<BotFrameworkOptions>))), Times.Once());
|
||||
}
|
||||
}
|
||||
|
||||
internal sealed class TestBot : IBot
|
||||
{
|
||||
public Task OnTurn(ITurnContext turnContext)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,83 @@
|
|||
using FluentAssertions;
|
||||
using Microsoft.Bot.Builder.Adapters;
|
||||
using Microsoft.Bot.Connector.Authentication;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Options;
|
||||
using Moq;
|
||||
using Xunit;
|
||||
|
||||
namespace Microsoft.Bot.Builder.Integration.AspNet.Core.Tests
|
||||
{
|
||||
public class ServiceResolutionTests
|
||||
{
|
||||
public class ResolveBotFrameworkOptions
|
||||
{
|
||||
[Fact]
|
||||
public void DefaultOptionsShouldResolve()
|
||||
{
|
||||
var serviceCollection = new ServiceCollection()
|
||||
.AddOptions()
|
||||
.AddBot<TestBot>();
|
||||
|
||||
var serviceProvider = serviceCollection.BuildServiceProvider();
|
||||
|
||||
var botFrameworkOptions = serviceProvider.GetService<IOptions<BotFrameworkOptions>>();
|
||||
|
||||
botFrameworkOptions.Value.Should().NotBeNull();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void DefaultOptionsShouldResolveWithDefaultSimpleCredentialProviderWhenNotExplicitlyConfigured()
|
||||
{
|
||||
var serviceCollection = new ServiceCollection()
|
||||
.AddOptions()
|
||||
.AddBot<TestBot>();
|
||||
|
||||
var serviceProvider = serviceCollection.BuildServiceProvider();
|
||||
|
||||
var botFrameworkOptions = serviceProvider.GetService<IOptions<BotFrameworkOptions>>();
|
||||
|
||||
botFrameworkOptions.Value.CredentialProvider.Should().NotBeNull()
|
||||
.And.BeOfType<SimpleCredentialProvider>();
|
||||
}
|
||||
}
|
||||
|
||||
public class ResolveBotFrameworkAdapter
|
||||
{
|
||||
[Fact]
|
||||
public void BotFrameworkAdapterShouldResolve()
|
||||
{
|
||||
var serviceCollection = new ServiceCollection()
|
||||
.AddOptions()
|
||||
.AddBot<TestBot>(options =>
|
||||
{
|
||||
options.CredentialProvider = Mock.Of<ICredentialProvider>();
|
||||
});
|
||||
|
||||
var serviceProvider = serviceCollection.BuildServiceProvider();
|
||||
|
||||
var botFrameworkAdapter = serviceProvider.GetService<BotFrameworkAdapter>();
|
||||
|
||||
botFrameworkAdapter.Should().NotBeNull();
|
||||
}
|
||||
}
|
||||
|
||||
public class ResolveIBot
|
||||
{
|
||||
[Fact]
|
||||
public void IBotShouldResolve()
|
||||
{
|
||||
var serviceCollection = new ServiceCollection()
|
||||
.AddOptions()
|
||||
.AddBot<TestBot>();
|
||||
|
||||
var serviceProvider = serviceCollection.BuildServiceProvider();
|
||||
|
||||
var bot = serviceProvider.GetService<IBot>();
|
||||
|
||||
bot.Should().NotBeNull()
|
||||
.And.BeOfType<TestBot>();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,13 @@
|
|||
using System;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Microsoft.Bot.Builder.Integration.AspNet.Core.Tests
|
||||
{
|
||||
internal sealed class TestBot : IBot
|
||||
{
|
||||
public Task OnTurn(ITurnContext turnContext)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,131 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="15.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<Import Project="..\..\..\packages\xunit.runner.visualstudio.2.3.1\build\net20\xunit.runner.visualstudio.props" Condition="Exists('..\..\..\packages\xunit.runner.visualstudio.2.3.1\build\net20\xunit.runner.visualstudio.props')" />
|
||||
<Import Project="..\..\..\packages\xunit.core.2.3.1\build\xunit.core.props" Condition="Exists('..\..\..\packages\xunit.core.2.3.1\build\xunit.core.props')" />
|
||||
<Import Project="..\..\..\packages\MSTest.TestAdapter.1.2.1\build\net45\MSTest.TestAdapter.props" Condition="Exists('..\..\..\packages\MSTest.TestAdapter.1.2.1\build\net45\MSTest.TestAdapter.props')" />
|
||||
<PropertyGroup>
|
||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
|
||||
<ProjectGuid>{2614D290-1345-4A41-BE90-F85F817CEADE}</ProjectGuid>
|
||||
<OutputType>Library</OutputType>
|
||||
<AppDesignerFolder>Properties</AppDesignerFolder>
|
||||
<RootNamespace>Microsoft.Bot.Builder.Integration.AspNet.WebApi.Tests</RootNamespace>
|
||||
<AssemblyName>Microsoft.Bot.Builder.Integration.AspNet.WebApi.Tests</AssemblyName>
|
||||
<TargetFrameworkVersion>v4.7.1</TargetFrameworkVersion>
|
||||
<FileAlignment>512</FileAlignment>
|
||||
<ProjectTypeGuids>{3AC096D0-A1C2-E12C-1390-A8335801FDAB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
|
||||
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">15.0</VisualStudioVersion>
|
||||
<VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath>
|
||||
<ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\$(VisualStudioVersion)\UITestExtensionPackages</ReferencePath>
|
||||
<IsCodedUITest>False</IsCodedUITest>
|
||||
<TestProjectType>UnitTest</TestProjectType>
|
||||
<NuGetPackageImportStamp>
|
||||
</NuGetPackageImportStamp>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
<DebugType>full</DebugType>
|
||||
<Optimize>false</Optimize>
|
||||
<OutputPath>bin\Debug\</OutputPath>
|
||||
<DefineConstants>DEBUG;TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
|
||||
<DebugType>pdbonly</DebugType>
|
||||
<Optimize>true</Optimize>
|
||||
<OutputPath>bin\Release\</OutputPath>
|
||||
<DefineConstants>TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="Castle.Core, Version=4.0.0.0, Culture=neutral, PublicKeyToken=407dd0808d44fbdc, processorArchitecture=MSIL">
|
||||
<HintPath>..\..\..\packages\Castle.Core.4.2.1\lib\net45\Castle.Core.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="FluentAssertions, Version=5.3.0.0, Culture=neutral, PublicKeyToken=33f2691a05b67b6a, processorArchitecture=MSIL">
|
||||
<HintPath>..\..\..\packages\FluentAssertions.5.3.0\lib\net47\FluentAssertions.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="Microsoft.VisualStudio.TestPlatform.TestFramework, Version=14.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
|
||||
<HintPath>..\..\..\packages\MSTest.TestFramework.1.2.1\lib\net45\Microsoft.VisualStudio.TestPlatform.TestFramework.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="Microsoft.VisualStudio.TestPlatform.TestFramework.Extensions, Version=14.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
|
||||
<HintPath>..\..\..\packages\MSTest.TestFramework.1.2.1\lib\net45\Microsoft.VisualStudio.TestPlatform.TestFramework.Extensions.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="Moq, Version=4.8.0.0, Culture=neutral, PublicKeyToken=69f491c39445e920, processorArchitecture=MSIL">
|
||||
<HintPath>..\..\..\packages\Moq.4.8.2\lib\net45\Moq.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="Newtonsoft.Json, Version=10.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
|
||||
<HintPath>..\..\..\packages\Newtonsoft.Json.10.0.3\lib\net45\Newtonsoft.Json.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.Configuration" />
|
||||
<Reference Include="System.Core" />
|
||||
<Reference Include="System.Net.Http" />
|
||||
<Reference Include="System.Net.Http.Formatting, Version=5.2.4.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
|
||||
<HintPath>..\..\..\packages\Microsoft.AspNet.WebApi.Client.5.2.4\lib\net45\System.Net.Http.Formatting.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System.Threading.Tasks.Extensions, Version=4.1.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
|
||||
<HintPath>..\..\..\packages\System.Threading.Tasks.Extensions.4.3.0\lib\portable-net45+win8+wp8+wpa81\System.Threading.Tasks.Extensions.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System.ValueTuple, Version=4.0.2.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
|
||||
<HintPath>..\..\..\packages\System.ValueTuple.4.4.0\lib\net47\System.ValueTuple.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System.Web.Http, Version=5.2.4.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
|
||||
<HintPath>..\..\..\packages\Microsoft.AspNet.WebApi.Core.5.2.4\lib\net45\System.Web.Http.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System.Xml" />
|
||||
<Reference Include="System.Xml.Linq" />
|
||||
<Reference Include="xunit.abstractions, Version=2.0.0.0, Culture=neutral, PublicKeyToken=8d05b1bb7a6fdb6c, processorArchitecture=MSIL">
|
||||
<HintPath>..\..\..\packages\xunit.abstractions.2.0.1\lib\net35\xunit.abstractions.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="xunit.assert, Version=2.3.1.3858, Culture=neutral, PublicKeyToken=8d05b1bb7a6fdb6c, processorArchitecture=MSIL">
|
||||
<HintPath>..\..\..\packages\xunit.assert.2.3.1\lib\netstandard1.1\xunit.assert.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="xunit.core, Version=2.3.1.3858, Culture=neutral, PublicKeyToken=8d05b1bb7a6fdb6c, processorArchitecture=MSIL">
|
||||
<HintPath>..\..\..\packages\xunit.extensibility.core.2.3.1\lib\netstandard1.1\xunit.core.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="xunit.execution.desktop, Version=2.3.1.3858, Culture=neutral, PublicKeyToken=8d05b1bb7a6fdb6c, processorArchitecture=MSIL">
|
||||
<HintPath>..\..\..\packages\xunit.extensibility.execution.2.3.1\lib\net452\xunit.execution.desktop.dll</HintPath>
|
||||
</Reference>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="HttpConfigurationExtensionsTests.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="app.config" />
|
||||
<None Include="packages.config" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\..\..\libraries\integration\Microsoft.Bot.Builder.Integration.AspNet.WebApi\Microsoft.Bot.Builder.Integration.AspNet.WebApi.csproj">
|
||||
<Project>{bd0b82ef-1601-4e87-b78a-b43de7eb36b0}</Project>
|
||||
<Name>Microsoft.Bot.Builder.Integration.AspNet.WebApi</Name>
|
||||
</ProjectReference>
|
||||
<ProjectReference Include="..\..\..\libraries\Microsoft.Bot.Builder.Core\Microsoft.Bot.Builder.Core.csproj">
|
||||
<Project>{f0c150e2-9b8a-444c-b70e-97ad918cb3d4}</Project>
|
||||
<Name>Microsoft.Bot.Builder.Core</Name>
|
||||
</ProjectReference>
|
||||
<ProjectReference Include="..\..\..\libraries\Microsoft.Bot.Connector\Microsoft.Bot.Connector.csproj">
|
||||
<Project>{6462DA5D-27DC-4CD5-9467-5EFB998FD838}</Project>
|
||||
<Name>Microsoft.Bot.Connector</Name>
|
||||
</ProjectReference>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Analyzer Include="..\..\..\packages\xunit.analyzers.0.7.0\analyzers\dotnet\cs\xunit.analyzers.dll" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(VSToolsPath)\TeamTest\Microsoft.TestTools.targets" Condition="Exists('$(VSToolsPath)\TeamTest\Microsoft.TestTools.targets')" />
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
|
||||
<PropertyGroup>
|
||||
<ErrorText>This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText>
|
||||
</PropertyGroup>
|
||||
<Error Condition="!Exists('..\..\..\packages\MSTest.TestAdapter.1.2.1\build\net45\MSTest.TestAdapter.props')" Text="$([System.String]::Format('$(ErrorText)', '..\..\..\packages\MSTest.TestAdapter.1.2.1\build\net45\MSTest.TestAdapter.props'))" />
|
||||
<Error Condition="!Exists('..\..\..\packages\MSTest.TestAdapter.1.2.1\build\net45\MSTest.TestAdapter.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\..\..\packages\MSTest.TestAdapter.1.2.1\build\net45\MSTest.TestAdapter.targets'))" />
|
||||
<Error Condition="!Exists('..\..\..\packages\xunit.core.2.3.1\build\xunit.core.props')" Text="$([System.String]::Format('$(ErrorText)', '..\..\..\packages\xunit.core.2.3.1\build\xunit.core.props'))" />
|
||||
<Error Condition="!Exists('..\..\..\packages\xunit.core.2.3.1\build\xunit.core.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\..\..\packages\xunit.core.2.3.1\build\xunit.core.targets'))" />
|
||||
<Error Condition="!Exists('..\..\..\packages\xunit.runner.visualstudio.2.3.1\build\net20\xunit.runner.visualstudio.props')" Text="$([System.String]::Format('$(ErrorText)', '..\..\..\packages\xunit.runner.visualstudio.2.3.1\build\net20\xunit.runner.visualstudio.props'))" />
|
||||
</Target>
|
||||
<Import Project="..\..\..\packages\MSTest.TestAdapter.1.2.1\build\net45\MSTest.TestAdapter.targets" Condition="Exists('..\..\..\packages\MSTest.TestAdapter.1.2.1\build\net45\MSTest.TestAdapter.targets')" />
|
||||
<Import Project="..\..\..\packages\xunit.core.2.3.1\build\xunit.core.targets" Condition="Exists('..\..\..\packages\xunit.core.2.3.1\build\xunit.core.targets')" />
|
||||
</Project>
|
|
@ -0,0 +1,79 @@
|
|||
using System;
|
||||
using System.Web.Http;
|
||||
using FluentAssertions;
|
||||
using Microsoft.Bot.Builder.Integration.AspNet.WebApi.Handlers;
|
||||
using Microsoft.Bot.Connector.Authentication;
|
||||
using Moq;
|
||||
using Xunit;
|
||||
|
||||
namespace Microsoft.Bot.Builder.Integration.AspNet.WebApi.Tests
|
||||
{
|
||||
public class HttpConfigurationExtensionsTests
|
||||
{
|
||||
public class MapBotFramework
|
||||
{
|
||||
[Fact]
|
||||
public void NullHttpConfigurationThrows()
|
||||
{
|
||||
var httpConfiguration = default(HttpConfiguration);
|
||||
|
||||
var action = new Action(() => httpConfiguration.MapBotFramework());
|
||||
|
||||
action.Should().Throw<ArgumentNullException>().And.ParamName.Should().Be("httpConfiguration");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void WithoutConfigurationCallback()
|
||||
{
|
||||
var httpConfiguration = new HttpConfiguration();
|
||||
|
||||
httpConfiguration.MapBotFramework();
|
||||
|
||||
var routes = httpConfiguration.Routes;
|
||||
|
||||
routes.Count.Should().Be(1);
|
||||
|
||||
var botMessageHandlerRoute = routes[BotMessageHandler.RouteName];
|
||||
botMessageHandlerRoute.Handler.Should().BeOfType<BotMessageHandler>();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void WithConfigurationCallback()
|
||||
{
|
||||
var httpConfiguration = new HttpConfiguration();
|
||||
|
||||
httpConfiguration.MapBotFramework(config =>
|
||||
{
|
||||
config.Should().NotBeNull();
|
||||
});
|
||||
|
||||
var routes = httpConfiguration.Routes;
|
||||
|
||||
routes.Count.Should().Be(1);
|
||||
|
||||
var botMessageHandlerRoute = routes[BotMessageHandler.RouteName];
|
||||
botMessageHandlerRoute.Handler.Should().BeOfType<BotMessageHandler>();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void EnableProactiveShouldMapMultipleHandlers()
|
||||
{
|
||||
var httpConfiguration = new HttpConfiguration();
|
||||
|
||||
httpConfiguration.MapBotFramework(config =>
|
||||
{
|
||||
config.EnableProactiveMessages();
|
||||
});
|
||||
|
||||
var routes = httpConfiguration.Routes;
|
||||
routes.Count.Should().Be(2);
|
||||
|
||||
var botMessageHandlerRoute = routes[BotMessageHandler.RouteName];
|
||||
botMessageHandlerRoute.Handler.Should().BeOfType<BotMessageHandler>();
|
||||
|
||||
var botProactiveMessageHandlerRoute = routes[BotProactiveMessageHandler.RouteName];
|
||||
botProactiveMessageHandlerRoute.Handler.Should().BeOfType<BotProactiveMessageHandler>();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,20 @@
|
|||
using System.Reflection;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
[assembly: AssemblyTitle("AspNet.WebApi.Tests")]
|
||||
[assembly: AssemblyDescription("")]
|
||||
[assembly: AssemblyConfiguration("")]
|
||||
[assembly: AssemblyCompany("")]
|
||||
[assembly: AssemblyProduct("AspNet.WebApi.Tests")]
|
||||
[assembly: AssemblyCopyright("Copyright © 2018")]
|
||||
[assembly: AssemblyTrademark("")]
|
||||
[assembly: AssemblyCulture("")]
|
||||
|
||||
[assembly: ComVisible(false)]
|
||||
|
||||
[assembly: Guid("2614d290-1345-4a41-be90-f85f817ceade")]
|
||||
|
||||
// [assembly: AssemblyVersion("1.0.*")]
|
||||
[assembly: AssemblyVersion("1.0.0.0")]
|
||||
[assembly: AssemblyFileVersion("1.0.0.0")]
|
|
@ -0,0 +1,11 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<configuration>
|
||||
<runtime>
|
||||
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
|
||||
<dependentAssembly>
|
||||
<assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral" />
|
||||
<bindingRedirect oldVersion="0.0.0.0-10.0.0.0" newVersion="10.0.0.0" />
|
||||
</dependentAssembly>
|
||||
</assemblyBinding>
|
||||
</runtime>
|
||||
</configuration>
|
|
@ -0,0 +1,21 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<packages>
|
||||
<package id="Castle.Core" version="4.2.1" targetFramework="net471" />
|
||||
<package id="FluentAssertions" version="5.3.0" targetFramework="net471" />
|
||||
<package id="Microsoft.AspNet.WebApi.Client" version="5.2.4" targetFramework="net471" />
|
||||
<package id="Microsoft.AspNet.WebApi.Core" version="5.2.4" targetFramework="net471" />
|
||||
<package id="Moq" version="4.8.2" targetFramework="net471" />
|
||||
<package id="MSTest.TestAdapter" version="1.2.1" targetFramework="net471" />
|
||||
<package id="MSTest.TestFramework" version="1.2.1" targetFramework="net471" />
|
||||
<package id="Newtonsoft.Json" version="10.0.3" targetFramework="net471" />
|
||||
<package id="System.Threading.Tasks.Extensions" version="4.3.0" targetFramework="net471" />
|
||||
<package id="System.ValueTuple" version="4.4.0" targetFramework="net471" />
|
||||
<package id="xunit" version="2.3.1" targetFramework="net471" />
|
||||
<package id="xunit.abstractions" version="2.0.1" targetFramework="net471" />
|
||||
<package id="xunit.analyzers" version="0.7.0" targetFramework="net471" />
|
||||
<package id="xunit.assert" version="2.3.1" targetFramework="net471" />
|
||||
<package id="xunit.core" version="2.3.1" targetFramework="net471" />
|
||||
<package id="xunit.extensibility.core" version="2.3.1" targetFramework="net471" />
|
||||
<package id="xunit.extensibility.execution" version="2.3.1" targetFramework="net471" />
|
||||
<package id="xunit.runner.visualstudio" version="2.3.1" targetFramework="net471" developmentDependency="true" />
|
||||
</packages>
|
Загрузка…
Ссылка в новой задаче