Skip to content
This repository was archived by the owner on Jan 15, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

using System.IO;
using System.Threading.Tasks;
using Microsoft.Bot.Builder;
using Microsoft.Bot.Builder.Dialogs;
using Microsoft.Bot.Builder.Dialogs.Adaptive;
using Microsoft.Bot.Builder.Dialogs.Adaptive.Testing;
using Microsoft.Bot.Builder.Dialogs.Declarative;
using Microsoft.Bot.Builder.Dialogs.Declarative.Obsolete;
using Microsoft.Bot.Builder.Dialogs.Declarative.Resources;
using Xunit;

namespace Microsoft.Bot.Components.Teams.Tests
{
public class ConditionalTests
{
public ConditionalTests()
{
ComponentRegistration.Add(new DeclarativeComponentRegistration());
ComponentRegistration.Add(new DialogsComponentRegistration());
ComponentRegistration.Add(new AdaptiveComponentRegistration());
ComponentRegistration.Add(new LanguageGenerationComponentRegistration());
ComponentRegistration.Add(new AdaptiveTestingComponentRegistration());
ComponentRegistration.Add(new DeclarativeComponentRegistrationBridge<TeamsBotComponent>());

ResourceExplorer = new ResourceExplorer()
.AddFolder(Path.Combine(TestUtils.GetProjectPath(), "Tests", nameof(ConditionalTests)), monitorChanges: false);
}

public static ResourceExplorer ResourceExplorer { get; set; }

[Fact]
public async Task ConditionalsTests_OnTeamsActivityTypes()
{
await TestUtils.RunTestScript(ResourceExplorer);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework Condition="'$(BuildTarget)' == 'netcoreapp21'">netcoreapp2.1</TargetFramework>
<TargetFramework Condition="'$(BuildTarget)' == 'netcoreapp31'">netcoreapp3.1</TargetFramework>
<TargetFrameworks Condition="'$(BuildTarget)' == ''">netcoreapp2.1;netcoreapp3.1</TargetFrameworks>
<IsPackable>false</IsPackable>
<Configurations>Debug;Release</Configurations>
<LangVersion>latest</LangVersion>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Bot.Builder.Dialogs.Adaptive.Testing" Version="4.13.2-preview" />
<PackageReference Include="Microsoft.Bot.Builder.Dialogs.Declarative" Version="4.13.2" />
<PackageReference Include="Microsoft.Extensions.Configuration" Version="2.1.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="2.1.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.1.1" />
<PackageReference Include="xunit" Version="2.4.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.2">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\..\..\..\packages\Teams\dotnet\Microsoft.Bot.Components.Teams.csproj" />
</ItemGroup>

<ItemGroup>
<None Update="appsettings.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

using System;
using System.IO;
using Microsoft.Bot.Builder.Dialogs.Declarative.Resources;

namespace Microsoft.Bot.Components.Teams.Tests
{
public class ResourceExplorerFixture : IDisposable
{
private string _folderPath = string.Empty;

public ResourceExplorerFixture()
{
ResourceExplorer = new ResourceExplorer();
}

public ResourceExplorer ResourceExplorer { get; private set; }

public ResourceExplorerFixture Initialize(string resourceFolder)
{
if (_folderPath.Length == 0)
{
_folderPath = Path.Combine(TestUtils.GetProjectPath(), "Tests", resourceFolder);
ResourceExplorer = ResourceExplorer.AddFolder(_folderPath, monitorChanges: false);
}

return this;
}

public void Dispose()
{
_folderPath = string.Empty;
ResourceExplorer.Dispose();
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Threading.Tasks;
using Microsoft.Bot.Builder;
using Microsoft.Bot.Builder.Adapters;
using Microsoft.Bot.Builder.Dialogs.Adaptive.Testing;
using Microsoft.Bot.Builder.Dialogs.Declarative.Resources;
using Microsoft.Bot.Connector;
using Microsoft.Bot.Schema;
using Microsoft.Extensions.Configuration;

namespace Microsoft.Bot.Components.Teams.Tests
{
public class TestUtils
{
public static IConfiguration DefaultConfiguration { get; set; } = new ConfigurationBuilder().AddInMemoryCollection().Build();

public static string RootFolder { get; set; } = GetProjectPath();

public static IEnumerable<object[]> GetTestScripts(string relativeFolder)
{
var testFolder = Path.GetFullPath(Path.Combine(RootFolder, PathUtils.NormalizePath(relativeFolder)));
return Directory.EnumerateFiles(testFolder, "*.test.dialog", SearchOption.AllDirectories).Select(s => new object[] { Path.GetFileName(s) }).ToArray();
}

public static async Task RunTestScript(ResourceExplorer resourceExplorer, string resourceId = null, IConfiguration configuration = null, [CallerMemberName] string testName = null, IEnumerable<IMiddleware> middleware = null, string adapterChannel = Channels.Msteams)
{
var storage = new MemoryStorage();
var convoState = new ConversationState(storage);
var userState = new UserState(storage);

var adapter = (TestAdapter)new TestAdapter(CreateConversation(adapterChannel, testName));

if (middleware != null)
{
foreach (var m in middleware)
{
adapter.Use(m);
}
}

adapter.Use(new RegisterClassMiddleware<IConfiguration>(DefaultConfiguration))
.UseStorage(storage)
.UseBotState(userState, convoState)
.Use(new TranscriptLoggerMiddleware(new TraceTranscriptLogger(traceActivity: false)));

adapter.OnTurnError += async (context, err) =>
{
if (err.Message.EndsWith("MemoryAssertion failed"))
{
throw err;
}

await context.SendActivityAsync(err.Message);
};

var script = resourceExplorer.LoadType<TestScript>(resourceId ?? $"{testName}.test.dialog");
script.Configuration = configuration ?? new ConfigurationBuilder().AddInMemoryCollection().Build();
script.Description ??= resourceId;
await script.ExecuteAsync(adapter: adapter, testName: testName, resourceExplorer: resourceExplorer).ConfigureAwait(false);
}

public static string GetProjectPath()
{
var parent = Environment.CurrentDirectory;
while (!string.IsNullOrEmpty(parent))
{
if (Directory.EnumerateFiles(parent, "*proj").Any())
{
break;
}

parent = Path.GetDirectoryName(parent);
}

return parent;
}

public static ConversationReference CreateConversation(string channel, string conversationName)
{
return new ConversationReference
{
ChannelId = channel ?? Channels.Test,
ServiceUrl = "https://test.com",
User = new ChannelAccount("user1", "User1"),
Bot = new ChannelAccount("bot", "Bot"),
Conversation = new ConversationAccount(false, "personal", conversationName),
Locale = "en-US",
};
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
{
"$schema": "../../../tests.schema",
"$kind": "Microsoft.Test.Script",
"dialog": {
"$kind": "Microsoft.AdaptiveDialog",
"id": "planningTest",
"triggers": [
{
"$kind": "Microsoft.OnUnknownIntent",
"actions": [
{
"$kind": "Teams.GetMeetingParticipant",
"property": "conversation.result"
},
{
"$kind": "Teams.GetMeetingParticipant",
"property": "conversation.resultWithCustomProperties",
"meetingId": "customMeetingId",
"participantId": "customParticipantId",
"tenantId": "customTenantId"
}
]
}
]
},
"script": [
{
"$kind": "Microsoft.Test.UserActivity",
"activity": {
"type": "message",
"text": "hi",
"from": {
"id": "participant-id",
"aadObjectId": "participant-aad-id-1"
},
"channelData": {
"tenant": {
"id": "tenant-id-1"
},
"meeting": {
"id": "meeting-id-1"
}
}
}
},
{
"$kind": "Microsoft.Test.MemoryAssertions",
"assertions": [
"conversation.result.conversation.conversationType == 'personal'",
"conversation.result.conversation.id == 'a:oneOnOneConversationId'",
"conversation.result.conversation.isGroup == false",
"conversation.result.conversation.name == 'oneOnOne'",
"conversation.result.conversation.tenantId == 'tenantId-Guid'",
"conversation.result.meeting.role == 'Organizer'",
"conversation.result.user.userPrincipalName == 'userPrincipalName-1'",
"conversation.resultWithCustomProperties.conversation.conversationType == 'personal'",
"conversation.resultWithCustomProperties.conversation.id == 'a:oneOnOneConversationId'",
"conversation.resultWithCustomProperties.conversation.isGroup == false",
"conversation.resultWithCustomProperties.conversation.name == 'oneOnOne'",
"conversation.resultWithCustomProperties.conversation.tenantId == 'tenantId-Guid'",
"conversation.resultWithCustomProperties.meeting.role == 'Organizer'",
"conversation.resultWithCustomProperties.user.userPrincipalName == 'userPrincipalName-1'"
]
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
{
"$schema": "../../../tests.schema",
"$kind": "Microsoft.Test.Script",
"dialog": {
"$kind": "Microsoft.AdaptiveDialog",
"id": "planningTest",
"triggers": [
{
"$kind": "Microsoft.OnUnknownIntent",
"actions": [
{
"$kind": "Teams.GetMeetingParticipant",
"property": "$result"
},
{
"$kind": "Microsoft.SendActivity",
"activity": "${$result}"
}
]
},
{
"$kind": "Microsoft.OnError",
"actions": [
{
"$kind": "Microsoft.SendActivity",
"activity": "${turn.dialogEvent.value.message}"
}
]
}
]
},
"script": [
{
"$kind": "Microsoft.Test.UserSays",
"text": "hi"
},
{
"$kind": "Microsoft.Test.AssertReply",
"text": "Teams.GetMeetingParticipant works only on the Teams channel."
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
{
"$schema": "../../../tests.schema",
"$kind": "Microsoft.Test.Script",
"dialog": {
"$kind": "Microsoft.AdaptiveDialog",
"id": "planningTest",
"triggers": [
{
"$kind": "Microsoft.OnUnknownIntent",
"actions": [
{
"$kind": "Teams.GetMeetingParticipant",
"property": "$result",
"participantId": "=turn.channelData.doesNotExist"
},
{
"$kind": "Microsoft.SendActivity",
"activity": "${$result}"
}
]
},
{
"$kind": "Microsoft.OnError",
"actions": [
{
"$kind": "Microsoft.SendActivity",
"activity": "${turn.dialogEvent.value.message}"
}
]
}
]
},
"script": [
{
"$kind": "Microsoft.Test.UserSays",
"text": "hi"
},
{
"$kind": "Microsoft.Test.AssertReply",
"text": "Teams.GetMeetingParticipant could not determine the participant id by expression value provided. participantId is required."
}
]
}
Loading