-
Notifications
You must be signed in to change notification settings - Fork 40
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add copy constructor to VirtualClientComponent to help ensure paramet…
…ers, metadata and extensions are passed to components created for client/server scenarios.
- Loading branch information
Showing
4 changed files
with
118 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,8 +10,10 @@ namespace VirtualClient.Contracts | |
using System.Threading.Tasks; | ||
using Microsoft.Extensions.DependencyInjection; | ||
using Moq; | ||
using Newtonsoft.Json.Linq; | ||
using NUnit.Framework; | ||
using VirtualClient.Common; | ||
using VirtualClient.Common.Contracts; | ||
using VirtualClient.Common.Telemetry; | ||
|
||
[TestFixture] | ||
|
@@ -33,6 +35,13 @@ public void VirtualClientComponentConstructorsValidateRequiredParameters() | |
Assert.Throws<ArgumentException>(() => new TestVirtualClientComponent(null, this.mockFixture.Parameters)); | ||
} | ||
|
||
[Test] | ||
public void VirtualClientComponentConstructorsValidateRequiredParameters_2() | ||
{ | ||
// Copy constructors | ||
Assert.Throws<ArgumentException>(() => new TestVirtualClientComponent(null as VirtualClientComponent)); | ||
} | ||
|
||
[Test] | ||
public void VirtualClientComponentConstructorsSetPropertiesToExpectedValues() | ||
{ | ||
|
@@ -48,6 +57,68 @@ public void VirtualClientComponentConstructorsSetPropertiesToExpectedValues() | |
component.Parameters.Select(p => $"{p.Key}={p.Value}")); | ||
} | ||
|
||
[Test] | ||
public void VirtualClientComponentConstructorsSetPropertiesToExpectedValues_2() | ||
{ | ||
// The existence of the layout causes the 'Role' parameter to be added automatically. | ||
// We want to do a pure parameter comparison. | ||
this.mockFixture.Dependencies.RemoveAll<EnvironmentLayout>(); | ||
|
||
// Setup: | ||
// The copy constructor is used more often with client/server implementations. Add in parameters | ||
// common to those scenarios. | ||
this.mockFixture.Parameters[nameof(VirtualClientComponent.ClientRequestId)] = Guid.NewGuid().ToString(); | ||
this.mockFixture.Parameters[nameof(VirtualClientComponent.SupportedPlatforms)] = "win-x64,linux-x64"; | ||
|
||
TestVirtualClientComponent originalComponent = new TestVirtualClientComponent(this.mockFixture.Dependencies, this.mockFixture.Parameters); | ||
|
||
// Expectation: | ||
// The following information should be copied from the original component to the new component: | ||
// | ||
// Properties | ||
originalComponent.ExecutionSeed = 7777; | ||
originalComponent.FailFast = true; | ||
originalComponent.LogToFile = true; | ||
originalComponent.SupportedRoles = new List<string> { "Client", "Server" }; | ||
|
||
// Parameters | ||
originalComponent.Parameters["Parameter"] = 101010; | ||
|
||
// Metadata | ||
originalComponent.Metadata.Add("Metadata", 1234); | ||
|
||
// Metadata Contract | ||
originalComponent.MetadataContract.Add("ScenarioProperty", 9876, MetadataContractCategory.Scenario); | ||
|
||
// Extensions | ||
originalComponent.Extensions.Add("Contacts", JToken.Parse("[ '[email protected]' ]")); | ||
|
||
// Copy constructor | ||
VirtualClientComponent component = new TestVirtualClientComponent(originalComponent); | ||
|
||
Assert.IsTrue(object.ReferenceEquals(originalComponent.Dependencies, component.Dependencies)); | ||
Assert.AreEqual(originalComponent.ClientRequestId, component.ClientRequestId); | ||
Assert.AreEqual(originalComponent.ExecutionSeed, component.ExecutionSeed); | ||
Assert.AreEqual(originalComponent.FailFast, component.FailFast); | ||
Assert.AreEqual(originalComponent.LogToFile, component.LogToFile); | ||
CollectionAssert.AreEquivalent(originalComponent.SupportedPlatforms, component.SupportedPlatforms); | ||
CollectionAssert.AreEquivalent(originalComponent.SupportedRoles, component.SupportedRoles); | ||
|
||
CollectionAssert.AreEquivalent( | ||
originalComponent.Parameters.Select(p => $"{p.Key}={p.Value}"), | ||
component.Parameters.Select(p => $"{p.Key}={p.Value}")); | ||
|
||
CollectionAssert.AreEquivalent( | ||
originalComponent.Metadata.Select(p => $"{p.Key}={p.Value}"), | ||
component.Metadata.Select(p => $"{p.Key}={p.Value}")); | ||
|
||
CollectionAssert.AreEquivalent( | ||
originalComponent.MetadataContract.Get(MetadataContractCategory.Scenario).Select(p => $"{p.Key}={p.Value}"), | ||
component.MetadataContract.Get(MetadataContractCategory.Scenario).Select(p => $"{p.Key}={p.Value}")); | ||
|
||
Assert.AreEqual(originalComponent.Extensions["Contacts"], component.Extensions["Contacts"]); | ||
} | ||
|
||
[Test] | ||
public void VirtualClientComponentTagsPropertyIsNeverNull() | ||
{ | ||
|
@@ -601,6 +672,11 @@ public void VirtualClientComponentIsSupportedRespectsSupportedPlatformAttribute( | |
|
||
private class TestVirtualClientComponent : VirtualClientComponent | ||
{ | ||
public TestVirtualClientComponent(VirtualClientComponent component) | ||
: base(component) | ||
{ | ||
} | ||
|
||
public TestVirtualClientComponent(IServiceCollection dependencies, IDictionary<string, IConvertible> parameters) | ||
: base(dependencies, parameters) | ||
{ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters