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

feat: multiple users per alias #88

Merged
merged 15 commits into from
Jun 24, 2021
Merged
Show file tree
Hide file tree
Changes from 6 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 @@ -19,6 +19,9 @@ public class TestConfiguration

private const string GetUserException = "Unable to retrieve user configuration. Please ensure a user with the given alias exists in the config.";

private object userEnumeratorsLock = new object();
private Dictionary<string, IEnumerator<UserConfiguration>> userEnumerators;

/// <summary>
/// Initializes a new instance of the <see cref="TestConfiguration"/> class.
/// </summary>
Expand Down Expand Up @@ -51,6 +54,28 @@ public TestConfiguration()
[YamlMember(Alias = "applicationUser")]
public ClientCredentials ApplicationUser { get; set; }

[YamlIgnore]
private Dictionary<string, IEnumerator<UserConfiguration>> UserEnumerators
{
get
{
lock (this.userEnumeratorsLock)
{
if (this.userEnumerators == null)
{
this.userEnumerators = this.Users
.Select(user => user.Alias)
.Distinct()
.ToDictionary(
alias => alias,
alias => this.Users.Where(u => u.Alias == alias).GetEnumerator());
}
}

return this.userEnumerators;
}
}

/// <summary>
/// Gets the target URL.
/// </summary>
Expand All @@ -67,14 +92,29 @@ public Uri GetTestUrl()
/// <returns>The user configuration.</returns>
public UserConfiguration GetUser(string userAlias)
bancey marked this conversation as resolved.
Show resolved Hide resolved
{
UserConfiguration user;

try
{
return this.Users.First(u => u.Alias == userAlias);
lock (this.userEnumeratorsLock)
{
var aliasEnumerator = this.UserEnumerators[userAlias];
if (!aliasEnumerator.MoveNext())
{
this.UserEnumerators[userAlias] = this.Users.Where(u => u.Alias == userAlias).GetEnumerator();
aliasEnumerator = this.UserEnumerators[userAlias];
aliasEnumerator.MoveNext();
}

user = aliasEnumerator.Current;
}
}
catch (Exception ex)
{
throw new ConfigurationErrorsException($"{GetUserException} User: {userAlias}", ex);
}

return user;
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@
<PackageReference Include="Microsoft.CrmSdk.XrmTooling.CoreAssembly" Version="9.1.0.64" />
<PackageReference Include="MSTest.TestAdapter" Version="2.1.2" />
<PackageReference Include="MSTest.TestFramework" Version="2.1.2" />
<PackageReference Include="Selenium.WebDriver.ChromeDriver" Version="87.0.4280.8800" />
<PackageReference Include="SpecFlow" Version="3.5.14" />
<PackageReference Include="Selenium.WebDriver.ChromeDriver" Version="91.0.4472.10100" />
<PackageReference Include="SpecFlow" Version="3.5.14" />
<PackageReference Include="SpecFlow.MsTest" Version="3.5.14" />
<PackageReference Include="SpecFlow.Tools.MsBuild.Generation" Version="3.5.14" />
</ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,11 @@ users:
- username: POWERAPPS_SPECFLOW_BINDINGS_TEST_ADMIN_USERNAME
password: POWERAPPS_SPECFLOW_BINDINGS_TEST_ADMIN_PASSWORD
alias: an admin
- username: POWERAPPS_SPECFLOW_BINDINGS_TEST_ADMIN_USERNAME2
password: POWERAPPS_SPECFLOW_BINDINGS_TEST_ADMIN_PASSWORD2
alias: an admin
- username: POWERAPPS_SPECFLOW_BINDINGS_TEST_ADMIN_USERNAME3
bancey marked this conversation as resolved.
Show resolved Hide resolved
password: POWERAPPS_SPECFLOW_BINDINGS_TEST_ADMIN_PASSWORD3
alias: an admin
- username: POWERAPPS_SPECFLOW_BINDINGS_TEST_ADMIN_USERNAME
alias: an aliased user