-
Notifications
You must be signed in to change notification settings - Fork 20
Jo 13138 #15
Jo 13138 #15
Changes from all commits
4b264c5
52e8ef4
ba3981d
c545667
5bd8f91
7d41359
47fa876
e1f08d4
e5ec4ec
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,18 +10,16 @@ | |
namespace Vsar.TSBot.UnitTests | ||
{ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Threading.Tasks; | ||
using System.Web.Http; | ||
using Autofac; | ||
using Autofac.Integration.WebApi; | ||
using Cards; | ||
using Dialogs; | ||
using Microsoft.ApplicationInsights; | ||
using Microsoft.Bot.Builder.Dialogs; | ||
using Microsoft.Bot.Connector; | ||
using Microsoft.VisualStudio.TestTools.UnitTesting; | ||
using Resources; | ||
|
||
/// <summary> | ||
/// Contains Test methods for <see cref="ConnectDialog"/> | ||
|
@@ -44,18 +42,22 @@ public ConnectDialogTests() | |
[TestMethod] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I recommend a TestCategory on every test method. I like to define some constants in a TestCategories class (can be a common file that is linked into the test projects). I know we can't use it in SpecFlow tests but we should use it elsewhere. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Need to setup a guidance for the team. |
||
public async Task FirstTimeConnectionTest() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The name of the test should be a little more descriptive so that if it fails I know from the name more about what has gone wrong. I often use a class called "GivenXYZ", with test methods inside called "WhenSomething_ThenThisThingHappens". I don't know what this test is going to test for from the name. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also, we need to setup guidance for the team. |
||
{ | ||
var toBot = this.Fixture.CreateMessage(); | ||
toBot.From.Id = Guid.NewGuid().ToString(); | ||
toBot.Text = "connect anaccount"; | ||
var fromId = Guid.NewGuid().ToString(); | ||
var toBot1 = this.Fixture.CreateMessage(); | ||
toBot1.From.Id = fromId; | ||
toBot1.Text = "Hi"; | ||
|
||
var toBot2 = this.Fixture.CreateMessage(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Probably one of those "religious" debates, but I dislike var at the best of times. I will accept var where the type is explicit on the right hand side, but I really think it should not be used if the type is not clear by inspection. You can't necessarily program to an interface if you use var as well. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let's get some guidance for the team, and refactor after. |
||
toBot2.From.Id = fromId; | ||
toBot2.Text = "connect anaccount"; | ||
|
||
const string appId = "AnAppId"; | ||
const string authorizeUrl = "https://www.authorizationUrl.com"; | ||
const string scope = | ||
"vso.agentpools_manage%20vso.build_execute%20vso.chat_manage%20vso.code_manage%20vso.code_status%20" + | ||
"vso.connected_server%20vso.dashboards_manage%20vso.entitlements%20vso.extension.data_write%20" + | ||
"vso.extension_manage%20vso.gallery_acquire%20vso.gallery_manage%20vso.identity%20vso.loadtest_write%20" + | ||
"vso.notification_manage%20vso.packaging_manage%20vso.profile_write%20vso.project_manage%20" + | ||
"vso.release_manage%20vso.security_manage%20vso.serviceendpoint_manage%20vso.test_write%20vso.work_write"; | ||
"vso.agentpools%20vso.build_execute%20vso.chat_write%20vso.code%20vso.connected_server%20" + | ||
"vso.dashboards%20vso.entitlements%20vso.extension%20vso.extension.data%20vso.gallery%20" + | ||
"vso.identity%20vso.loadtest%20vso.notification%20vso.packaging%20vso.project%20" + | ||
"vso.release_execute%20vso.serviceendpoint%20vso.taskgroups%20vso.test%20vso.work"; | ||
|
||
var builder = this.Fixture.Build(); | ||
builder.RegisterType<TelemetryClient>(); | ||
|
@@ -69,19 +71,21 @@ public async Task FirstTimeConnectionTest() | |
GlobalConfiguration.Configure(config => config.DependencyResolver = new AutofacWebApiDependencyResolver(container)); | ||
var root = new RootDialog(); | ||
|
||
var toUser = await this.Fixture.GetResponse(container, root, toBot); | ||
// First trigger the welcome message. | ||
await this.Fixture.GetResponse(container, root, toBot1); | ||
var toUser = await this.Fixture.GetResponse(container, root, toBot2); | ||
|
||
var attachment = toUser.Attachments.FirstOrDefault(); | ||
Assert.IsNotNull(attachment, "Expecting an attachment."); | ||
|
||
var card = attachment.Content as SigninCard; | ||
var card = attachment.Content as LogOnCard; | ||
Assert.IsNotNull(card, "Missing signin card."); | ||
|
||
var button = card.Buttons.FirstOrDefault(); | ||
Assert.IsNotNull(button, "Button is missing"); | ||
|
||
var expected = | ||
$"https://app.vssps.visualstudio.com/oauth2/authorize?client_id={appId}&response_type=Assertion&state={toBot.ChannelId};{toBot.From.Id}&scope={scope}&redirect_uri={authorizeUrl}/"; | ||
$"https://app.vssps.visualstudio.com/oauth2/authorize?client_id={appId}&response_type=Assertion&state={toBot2.ChannelId};{toBot2.From.Id}&scope={scope}&redirect_uri={authorizeUrl}/"; | ||
Assert.AreEqual(expected.ToLower(), button.Value.ToString().ToLower(), "OAuth url is invalid."); | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I wonder if this could be done as multiple unit tests rather than have a lot of asserts in a single test? Extracting the setup code into methods with intent-revealing names will also make the test much more readable. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There should be one in the test and one in the api code. We can extract to a common. |
||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,15 +9,6 @@ | |
|
||
namespace Vsar.TSBot.UnitTests | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why no tests for rootdialog? It seems like rootdialog has lots of functionality. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. agreed. |
||
{ | ||
using System; | ||
using System.Threading.Tasks; | ||
using System.Web.Http; | ||
using Autofac; | ||
using Autofac.Integration.WebApi; | ||
using Dialogs; | ||
using FluentAssertions; | ||
using Microsoft.ApplicationInsights; | ||
using Microsoft.Bot.Builder.Dialogs; | ||
using Microsoft.VisualStudio.TestTools.UnitTesting; | ||
|
||
/// <summary> | ||
|
@@ -33,32 +24,5 @@ public RootDialogTests() | |
: base(new DialogFixture()) | ||
{ | ||
} | ||
|
||
/// <summary> | ||
/// Temporary | ||
/// </summary> | ||
/// <returns>Nothing.</returns> | ||
[TestMethod] | ||
public async Task EchoDialog() | ||
{ | ||
var toBot = this.Fixture.CreateMessage(); | ||
toBot.From.Id = Guid.NewGuid().ToString(); | ||
toBot.Text = "Test"; | ||
|
||
var builder = this.Fixture.Build(); | ||
builder.RegisterType<TelemetryClient>(); | ||
builder | ||
.RegisterType<EchoDialog>() | ||
.As<IDialog<object>>(); | ||
|
||
var container = builder.Build(); | ||
GlobalConfiguration.Configure(config => config.DependencyResolver = new AutofacWebApiDependencyResolver(container)); | ||
|
||
var root = new RootDialog(); | ||
|
||
var toUser = await this.Fixture.GetResponse(container, root, toBot); | ||
|
||
toUser.Text.Should().Contain("4").And.Contain("Test"); | ||
} | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't agree that we should suppress CA1305.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You are right, my mistake. Then we need to use 'string result = FormattableString.Invariant($"{name}");" for interpolated strings.