Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrates Tests tests to Xunit #4082

Merged
merged 2 commits into from
Jun 17, 2020
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
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,12 @@
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.1.1" />
<PackageReference Include="MSTest.TestAdapter" Version="1.4.0" />
<PackageReference Include="MSTest.TestFramework" Version="1.4.0" />
<PackageReference Include="Moq" Version="4.13.1" targetFramework="net46" />
<PackageReference Include="Moq" Version="4.13.1" targetFramework="net46" />
<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>
Expand Down
111 changes: 45 additions & 66 deletions tests/Microsoft.Bot.Builder.Tests/Skills/SkillHandlerTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,12 @@
using Microsoft.Bot.Connector.Authentication;
using Microsoft.Bot.Schema;
using Microsoft.Extensions.Logging;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Moq;
using Newtonsoft.Json;
using Xunit;

namespace Microsoft.Bot.Builder.Tests.Skills
{
[TestClass]
public class SkillHandlerTests
{
private readonly ClaimsIdentity _claimsIdentity;
Expand Down Expand Up @@ -62,7 +61,7 @@ public SkillHandlerTests()
_conversationId = _testConversationIdFactory.CreateSkillConversationIdAsync(options, CancellationToken.None).Result;
}

[TestMethod]
[Fact]
public async Task LegacyConversationIdFactoryTest()
{
var legacyFactory = new TestLegacyConversationIdFactory();
Expand Down Expand Up @@ -90,11 +89,11 @@ public async Task LegacyConversationIdFactoryTest()
activity.ApplyConversationReference(conversationReference);

await sut.TestOnSendToConversationAsync(_claimsIdentity, conversationId, (Activity)activity, CancellationToken.None);
Assert.IsNotNull(botCallback);
Assert.NotNull(botCallback);
await botCallback.Invoke(new TurnContext(_mockAdapter.Object, (Activity)activity), CancellationToken.None);
}

[TestMethod]
[Fact]
public async Task OnSendToConversationAsyncTest()
{
BotCallbackHandler botCallback = null;
Expand All @@ -109,14 +108,14 @@ public async Task OnSendToConversationAsyncTest()
var activity = (Activity)Activity.CreateMessageActivity();
activity.ApplyConversationReference(_conversationReference);

Assert.IsNull(activity.CallerId);
Assert.Null(activity.CallerId);
await sut.TestOnSendToConversationAsync(_claimsIdentity, _conversationId, activity, CancellationToken.None);
Assert.IsNotNull(botCallback);
Assert.NotNull(botCallback);
await botCallback.Invoke(new TurnContext(_mockAdapter.Object, _conversationReference.GetContinuationActivity()), CancellationToken.None);
Assert.IsNull(activity.CallerId);
Assert.Null(activity.CallerId);
}

[TestMethod]
[Fact]
public async Task OnOnReplyToActivityAsyncTest()
{
BotCallbackHandler botCallback = null;
Expand All @@ -133,141 +132,121 @@ public async Task OnOnReplyToActivityAsyncTest()
activity.ApplyConversationReference(_conversationReference);

await sut.TestOnReplyToActivityAsync(_claimsIdentity, _conversationId, activityId, activity, CancellationToken.None);
Assert.IsNotNull(botCallback);
Assert.NotNull(botCallback);
await botCallback.Invoke(new TurnContext(_mockAdapter.Object, _conversationReference.GetContinuationActivity()), CancellationToken.None);
Assert.IsNull(activity.CallerId);
Assert.Null(activity.CallerId);
}

[TestMethod]
[Fact]
public async Task EventActivityAsyncTest()
{
var activity = (Activity)Activity.CreateEventActivity();
await TestActivityCallback(activity);
Assert.AreEqual($"{CallerIdConstants.BotToBotPrefix}{_skillId}", activity.CallerId);
Assert.Equal($"{CallerIdConstants.BotToBotPrefix}{_skillId}", activity.CallerId);
}

[TestMethod]
[Fact]
public async Task EndOfConversationActivityAsyncTest()
{
var activity = (Activity)Activity.CreateEndOfConversationActivity();
await TestActivityCallback(activity);
Assert.AreEqual($"{CallerIdConstants.BotToBotPrefix}{_skillId}", activity.CallerId);
Assert.Equal($"{CallerIdConstants.BotToBotPrefix}{_skillId}", activity.CallerId);
}

[TestMethod]
[Fact]
public async Task OnUpdateActivityAsyncTest()
{
var sut = CreateSkillHandlerForTesting();
var activity = Activity.CreateMessageActivity();
var activityId = Guid.NewGuid().ToString("N");
activity.ApplyConversationReference(_conversationReference);

await Assert.ThrowsExceptionAsync<NotImplementedException>(async () =>
{
await sut.TestOnUpdateActivityAsync(_claimsIdentity, _conversationId, activityId, (Activity)activity, CancellationToken.None);
});
await Assert.ThrowsAsync<NotImplementedException>(() =>
sut.TestOnUpdateActivityAsync(_claimsIdentity, _conversationId, activityId, (Activity)activity, CancellationToken.None));
}

[TestMethod]
[Fact]
public async Task OnDeleteActivityAsyncTest()
{
var sut = CreateSkillHandlerForTesting();
var activityId = Guid.NewGuid().ToString("N");
await Assert.ThrowsExceptionAsync<NotImplementedException>(async () =>
{
await sut.TestOnDeleteActivityAsync(_claimsIdentity, _conversationId, activityId, CancellationToken.None);
});
await Assert.ThrowsAsync<NotImplementedException>(() =>
sut.TestOnDeleteActivityAsync(_claimsIdentity, _conversationId, activityId, CancellationToken.None));
}

[TestMethod]
[Fact]
public async Task OnGetActivityMembersAsyncTest()
{
var sut = CreateSkillHandlerForTesting();
var activityId = Guid.NewGuid().ToString("N");
await Assert.ThrowsExceptionAsync<NotImplementedException>(async () =>
{
await sut.TestOnGetActivityMembersAsync(_claimsIdentity, _conversationId, activityId, CancellationToken.None);
});
await Assert.ThrowsAsync<NotImplementedException>(() =>
sut.TestOnGetActivityMembersAsync(_claimsIdentity, _conversationId, activityId, CancellationToken.None));
}

[TestMethod]
[Fact]
public async Task OnCreateConversationAsyncTest()
{
var sut = CreateSkillHandlerForTesting();
var conversationParameters = new ConversationParameters();
await Assert.ThrowsExceptionAsync<NotImplementedException>(async () =>
{
await sut.TestOnCreateConversationAsync(_claimsIdentity, conversationParameters, CancellationToken.None);
});
await Assert.ThrowsAsync<NotImplementedException>(() =>
sut.TestOnCreateConversationAsync(_claimsIdentity, conversationParameters, CancellationToken.None));
}

[TestMethod]
[Fact]
public async Task OnGetConversationsAsyncTest()
{
var sut = CreateSkillHandlerForTesting();
var conversationId = Guid.NewGuid().ToString("N");
await Assert.ThrowsExceptionAsync<NotImplementedException>(async () =>
{
await sut.TestOnGetConversationsAsync(_claimsIdentity, conversationId, string.Empty, CancellationToken.None);
});
await Assert.ThrowsAsync<NotImplementedException>(() =>
sut.TestOnGetConversationsAsync(_claimsIdentity, conversationId, string.Empty, CancellationToken.None));
}

[TestMethod]
[Fact]
public async Task OnGetConversationMembersAsyncTest()
{
var sut = CreateSkillHandlerForTesting();
var conversationId = Guid.NewGuid().ToString("N");
await Assert.ThrowsExceptionAsync<NotImplementedException>(async () =>
{
await sut.TestOnGetConversationMembersAsync(_claimsIdentity, conversationId, CancellationToken.None);
});
await Assert.ThrowsAsync<NotImplementedException>(() =>
sut.TestOnGetConversationMembersAsync(_claimsIdentity, conversationId, CancellationToken.None));
}

[TestMethod]
[Fact]
public async Task OnGetConversationPagedMembersAsyncTest()
{
var sut = CreateSkillHandlerForTesting();
var conversationId = Guid.NewGuid().ToString("N");
await Assert.ThrowsExceptionAsync<NotImplementedException>(async () =>
{
await sut.TestOnGetConversationPagedMembersAsync(_claimsIdentity, conversationId, null, null, CancellationToken.None);
});
await Assert.ThrowsAsync<NotImplementedException>(() =>
sut.TestOnGetConversationPagedMembersAsync(_claimsIdentity, conversationId, null, null, CancellationToken.None));
}

[TestMethod]
[Fact]
public async Task OnDeleteConversationMemberAsyncTest()
{
var sut = CreateSkillHandlerForTesting();
var conversationId = Guid.NewGuid().ToString("N");
var memberId = Guid.NewGuid().ToString("N");
await Assert.ThrowsExceptionAsync<NotImplementedException>(async () =>
{
await sut.TestOnDeleteConversationMemberAsync(_claimsIdentity, conversationId, memberId, CancellationToken.None);
});
await Assert.ThrowsAsync<NotImplementedException>(() =>
sut.TestOnDeleteConversationMemberAsync(_claimsIdentity, conversationId, memberId, CancellationToken.None));
}

[TestMethod]
[Fact]
public async Task OnSendConversationHistoryAsyncTest()
{
var sut = CreateSkillHandlerForTesting();
var conversationId = Guid.NewGuid().ToString("N");
var transcript = new Transcript();
await Assert.ThrowsExceptionAsync<NotImplementedException>(async () =>
{
await sut.TestOnSendConversationHistoryAsync(_claimsIdentity, conversationId, transcript, CancellationToken.None);
});
await Assert.ThrowsAsync<NotImplementedException>(() =>
sut.TestOnSendConversationHistoryAsync(_claimsIdentity, conversationId, transcript, CancellationToken.None));
}

[TestMethod]
[Fact]
public async Task OnUploadAttachmentAsyncTest()
{
var sut = CreateSkillHandlerForTesting();
var conversationId = Guid.NewGuid().ToString("N");
var attachmentData = new AttachmentData();
await Assert.ThrowsExceptionAsync<NotImplementedException>(async () =>
{
await sut.TestOnUploadAttachmentAsync(_claimsIdentity, conversationId, attachmentData, CancellationToken.None);
});
await Assert.ThrowsAsync<NotImplementedException>(() =>
sut.TestOnUploadAttachmentAsync(_claimsIdentity, conversationId, attachmentData, CancellationToken.None));
}

private async Task TestActivityCallback(Activity activity)
Expand All @@ -286,7 +265,7 @@ private async Task TestActivityCallback(Activity activity)
activity.ApplyConversationReference(_conversationReference);

await sut.TestOnReplyToActivityAsync(_claimsIdentity, _conversationId, activityId, activity, CancellationToken.None);
Assert.IsNotNull(botCallback);
Assert.NotNull(botCallback);
await botCallback.Invoke(new TurnContext(_mockAdapter.Object, activity), CancellationToken.None);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,13 @@

using Microsoft.Bot.Schema;
using Microsoft.Bot.Schema.Teams;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Xunit;

namespace Microsoft.Bot.Builder.Teams.Tests
{
[TestClass]
public class TeamsActivityExtensionsTests
{
[TestMethod]
[Fact]
public void TeamsGetTeamId()
{
// Arrange
Expand All @@ -20,10 +19,10 @@ public void TeamsGetTeamId()
var teamId = activity.TeamsGetTeamInfo().Id;

// Assert
Assert.AreEqual("team123", teamId);
Assert.Equal("team123", teamId);
}

[TestMethod]
[Fact]
public void TeamsGetTeamIdTyped()
{
// Arrange
Expand All @@ -33,10 +32,10 @@ public void TeamsGetTeamIdTyped()
var teamId = activity.TeamsGetTeamInfo().Id;

// Assert
Assert.AreEqual("team123", teamId);
Assert.Equal("team123", teamId);
}

[TestMethod]
[Fact]
public void TeamsNotifyUser()
{
// Arrange
Expand All @@ -46,10 +45,10 @@ public void TeamsNotifyUser()
activity.TeamsNotifyUser();

// Assert
Assert.AreEqual(true, ((TeamsChannelData)activity.ChannelData).Notification.Alert);
Assert.Equal(true, ((TeamsChannelData)activity.ChannelData).Notification.Alert);
}

[TestMethod]
[Fact]
public void TeamsNotifyUserExistingNotification()
{
// Arrange
Expand All @@ -59,8 +58,8 @@ public void TeamsNotifyUserExistingNotification()
activity.TeamsNotifyUser();

// Assert
Assert.AreEqual(true, ((TeamsChannelData)activity.ChannelData).Notification.Alert);
Assert.AreEqual("team123", ((TeamsChannelData)activity.ChannelData).Team.Id);
Assert.Equal(true, ((TeamsChannelData)activity.ChannelData).Notification.Alert);
Assert.Equal("team123", ((TeamsChannelData)activity.ChannelData).Team.Id);
}
}
}
Original file line number Diff line number Diff line change
@@ -1,20 +1,18 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

using System.Threading;
using System.Threading.Tasks;
using Microsoft.Bot.Builder.Tests;
using Microsoft.Bot.Schema;
using Microsoft.Bot.Schema.Teams;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Newtonsoft.Json.Linq;
using Xunit;

namespace Microsoft.Bot.Builder.Teams.Tests
{
[TestClass]
public class TeamsActivityHandlerBadRequestTests
{
[TestMethod]
[Fact]
public async Task TestFileConsentBadAction()
{
// Arrange
Expand Down Expand Up @@ -47,13 +45,13 @@ void CaptureSend(Activity[] arg)
await ((IBot)bot).OnTurnAsync(turnContext);

// Assert
Assert.IsNotNull(activitiesToSend);
Assert.AreEqual(1, activitiesToSend.Length);
Assert.IsInstanceOfType(activitiesToSend[0].Value, typeof(InvokeResponse));
Assert.AreEqual(400, ((InvokeResponse)activitiesToSend[0].Value).Status);
Assert.NotNull(activitiesToSend);
Assert.Single(activitiesToSend);
Assert.IsType<InvokeResponse>(activitiesToSend[0].Value);
Assert.Equal(400, ((InvokeResponse)activitiesToSend[0].Value).Status);
}

[TestMethod]
[Fact]
public async Task TestMessagingExtensionSubmitActionPreviewBadAction()
{
// Arrange
Expand All @@ -80,10 +78,10 @@ void CaptureSend(Activity[] arg)
await ((IBot)bot).OnTurnAsync(turnContext);

// Assert
Assert.IsNotNull(activitiesToSend);
Assert.AreEqual(1, activitiesToSend.Length);
Assert.IsInstanceOfType(activitiesToSend[0].Value, typeof(InvokeResponse));
Assert.AreEqual(400, ((InvokeResponse)activitiesToSend[0].Value).Status);
Assert.NotNull(activitiesToSend);
Assert.Single(activitiesToSend);
Assert.IsType<InvokeResponse>(activitiesToSend[0].Value);
Assert.Equal(400, ((InvokeResponse)activitiesToSend[0].Value).Status);
}
}
}
Loading