本文整理汇总了C#中Variables.Set方法的典型用法代码示例。如果您正苦于以下问题:C# Variables.Set方法的具体用法?C# Variables.Set怎么用?C# Variables.Set使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Variables
的用法示例。
在下文中一共展示了Variables.Set方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Setup
public TestHostContext Setup([CallerMemberName] string name = "")
{
// Setup the host context.
TestHostContext hc = new TestHostContext(this, name);
// Create a random work path.
var configStore = new Mock<IConfigurationStore>();
_workFolder = Path.Combine(
Path.GetDirectoryName(Assembly.GetEntryAssembly().Location),
$"_work_{Path.GetRandomFileName()}");
var settings = new AgentSettings()
{
WorkFolder = _workFolder,
};
configStore.Setup(x => x.GetSettings()).Returns(settings);
hc.SetSingleton<IConfigurationStore>(configStore.Object);
// Setup the execution context.
_ec = new Mock<IExecutionContext>();
List<string> warnings;
_variables = new Variables(hc, new Dictionary<string, string>(), new List<MaskHint>(), out warnings);
_variables.Set(Constants.Variables.System.CollectionId, CollectionId);
_variables.Set(WellKnownDistributedTaskVariables.TFCollectionUrl, CollectionUrl);
_variables.Set(Constants.Variables.System.DefinitionId, DefinitionId);
_variables.Set(Constants.Variables.Build.DefinitionName, DefinitionName);
_ec.Setup(x => x.Variables).Returns(_variables);
// Setup the endpoint.
_endpoint = new ServiceEndpoint() { Url = new Uri(EndpointUrl) };
// Setup the tracking manager.
_trackingManager = new TrackingManager();
_trackingManager.Initialize(hc);
return hc;
}
示例2: SetupMocks
private void SetupMocks([CallerMemberName] string name = "")
{
_hc = new TestHostContext(this, name);
_ec = new Mock<IExecutionContext>();
_warnings = new List<string>();
_errors = new List<string>();
List<string> warnings;
var variables = new Variables(_hc, new Dictionary<string, string>(), new List<MaskHint>(), out warnings);
variables.Set("build.sourcesdirectory", _sourceDirectory);
_ec.Setup(x => x.Variables).Returns(variables);
_ec.Setup(x => x.AddIssue(It.IsAny<Issue>()))
.Callback<Issue>
((issue) =>
{
if (issue.Type == IssueType.Warning)
{
_warnings.Add(issue.Message);
}
else if (issue.Type == IssueType.Error)
{
_errors.Add(issue.Message);
}
});
}
示例3: Setup
// TODO: Updates legacy config.
private TestHostContext Setup(
[CallerMemberName] string name = "",
BuildCleanOption? cleanOption = null,
ExistingConfigKind existingConfigKind = ExistingConfigKind.None)
{
// Setup the host context.
TestHostContext hc = new TestHostContext(this, name);
// Create a random work path.
var configStore = new Mock<IConfigurationStore>();
_workFolder = Path.Combine(
Path.GetDirectoryName(Assembly.GetEntryAssembly().Location),
$"_work_{Path.GetRandomFileName()}");
var settings = new AgentSettings() { WorkFolder = _workFolder };
configStore.Setup(x => x.GetSettings()).Returns(settings);
hc.SetSingleton<IConfigurationStore>(configStore.Object);
// Setup the execution context.
_ec = new Mock<IExecutionContext>();
List<string> warnings;
_variables = new Variables(hc, new Dictionary<string, string>(), new List<MaskHint>(), out warnings);
_variables.Set(Constants.Variables.System.CollectionId, CollectionId);
_variables.Set(Constants.Variables.System.DefinitionId, DefinitionId);
_variables.Set(Constants.Variables.Build.Clean, $"{cleanOption}");
_ec.Setup(x => x.Variables).Returns(_variables);
// Store the expected tracking file path.
_trackingFile = Path.Combine(
_workFolder,
Constants.Build.Path.SourceRootMappingDirectory,
_ec.Object.Variables.System_CollectionId,
_ec.Object.Variables.System_DefinitionId,
Constants.Build.Path.TrackingConfigFile);
// Setup the endpoint.
_endpoint = new ServiceEndpoint()
{
Name = "Some endpoint name",
Url = new Uri("http://contoso.visualstudio.com"),
};
// Setup the source provider.
_sourceProvider = new Mock<ISourceProvider>();
_sourceProvider
.Setup(x => x.GetBuildDirectoryHashKey(_ec.Object, _endpoint))
.Returns(HashKey);
hc.SetSingleton<ISourceProvider>(_sourceProvider.Object);
// Store the existing config object.
switch (existingConfigKind)
{
case ExistingConfigKind.Matching:
_existingConfig = new TrackingConfig(_ec.Object, _endpoint, 1, HashKey);
Assert.Equal("1", _existingConfig.BuildDirectory);
break;
case ExistingConfigKind.Nonmatching:
_existingConfig = new TrackingConfig(_ec.Object, _endpoint, 2, NonmatchingHashKey);
Assert.Equal("2", _existingConfig.BuildDirectory);
break;
case ExistingConfigKind.None:
break;
default:
throw new NotSupportedException();
}
// Store the new config object.
if (existingConfigKind == ExistingConfigKind.Matching)
{
_newConfig = _existingConfig;
}
else
{
_newConfig = new TrackingConfig(_ec.Object, _endpoint, 3, HashKey);
Assert.Equal("3", _newConfig.BuildDirectory);
}
// Setup the tracking manager.
_trackingManager = new Mock<ITrackingManager>();
_trackingManager
.Setup(x => x.LoadIfExists(_ec.Object, _trackingFile))
.Returns(_existingConfig);
if (existingConfigKind == ExistingConfigKind.None || existingConfigKind == ExistingConfigKind.Nonmatching)
{
_trackingManager
.Setup(x => x.Create(_ec.Object, _endpoint, HashKey, _trackingFile))
.Returns(_newConfig);
if (existingConfigKind == ExistingConfigKind.Nonmatching)
{
_trackingManager
.Setup(x => x.MarkForGarbageCollection(_ec.Object, _existingConfig));
}
}
else if (existingConfigKind == ExistingConfigKind.Matching)
{
_trackingManager
.Setup(x => x.UpdateJobRunProperties(_ec.Object, _existingConfig, _trackingFile));
}
else
//.........这里部分代码省略.........
示例4: SetupMocks
private void SetupMocks([CallerMemberName] string name = "")
{
_hc = new TestHostContext(this, name);
_codeCoverageStatistics = new List<CodeCoverageStatistics> { new CodeCoverageStatistics { Label = "label", Covered = 10, Total = 10, Position = 1 } };
_mocksummaryReader = new Mock<ICodeCoverageSummaryReader>();
_mocksummaryReader.Setup(x => x.Name).Returns("mockCCTool");
_mocksummaryReader.Setup(x => x.GetCodeCoverageSummary(It.IsAny<IExecutionContext>(), It.IsAny<string>()))
.Returns(_codeCoverageStatistics);
_hc.SetSingleton(_mocksummaryReader.Object);
_mockCodeCoverageEnabler = new Mock<ICodeCoverageEnabler>();
_mockCodeCoverageEnabler.Setup(x => x.Name).Returns("mockCCTool_mockBuildTool");
_mockCodeCoverageEnabler.Setup(x => x.EnableCodeCoverage(It.IsAny<IExecutionContext>(), It.IsAny<CodeCoverageEnablerInputs>()));
_hc.SetSingleton(_mockCodeCoverageEnabler.Object);
_mockExtensionManager = new Mock<IExtensionManager>();
_mockExtensionManager.Setup(x => x.GetExtensions<ICodeCoverageSummaryReader>()).Returns(new List<ICodeCoverageSummaryReader> { _mocksummaryReader.Object });
_mockExtensionManager.Setup(x => x.GetExtensions<ICodeCoverageEnabler>()).Returns(new List<ICodeCoverageEnabler> { _mockCodeCoverageEnabler.Object });
_hc.SetSingleton(_mockExtensionManager.Object);
_mockCodeCoveragePublisher = new Mock<ICodeCoveragePublisher>();
_hc.SetSingleton(_mockCodeCoveragePublisher.Object);
_mockCommandContext = new Mock<IAsyncCommandContext>();
_hc.EnqueueInstance(_mockCommandContext.Object);
var endpointAuthorization = new EndpointAuthorization()
{
Scheme = EndpointAuthorizationSchemes.OAuth
};
List<string> warnings;
_variables = new Variables(_hc, new Dictionary<string, string>(), new List<MaskHint>(), out warnings);
_variables.Set("build.buildId", "1");
_variables.Set("build.containerId", "1");
_variables.Set("system.teamProjectId", "46075F24-A6B9-447E-BEF0-E1D5592D9E39");
_variables.Set("system.hostType", "build");
endpointAuthorization.Parameters[EndpointAuthorizationParameters.AccessToken] = "accesstoken";
_ec = new Mock<IExecutionContext>();
_ec.Setup(x => x.Endpoints).Returns(new List<ServiceEndpoint> { new ServiceEndpoint { Url = new Uri("http://dummyurl"), Name = ServiceEndpoints.SystemVssConnection, Authorization = endpointAuthorization } });
_ec.Setup(x => x.Variables).Returns(_variables);
var asyncCommands = new List<IAsyncCommandContext>();
_ec.Setup(x => x.AsyncCommands).Returns(asyncCommands);
_ec.Setup(x => x.AddIssue(It.IsAny<Issue>()))
.Callback<Issue>
((issue) =>
{
if (issue.Type == IssueType.Warning)
{
_warnings.Add(issue.Message);
}
else if (issue.Type == IssueType.Error)
{
_errors.Add(issue.Message);
}
});
}
示例5: Set_StoresNullAsEmpty
public void Set_StoresNullAsEmpty()
{
using (TestHostContext hc = new TestHostContext(this))
{
// Arrange.
List<string> warnings;
var variables = new Variables(hc, new Dictionary<string, string>(), new List<MaskHint>(), out warnings);
// Act.
variables.Set("variable1", null);
// Assert.
Assert.Equal(0, warnings.Count);
Assert.Equal(string.Empty, variables.Get("variable1"));
}
}
示例6: Set_StoresValue
public void Set_StoresValue()
{
using (TestHostContext hc = new TestHostContext(this))
{
// Arrange.
List<string> warnings;
var variables = new Variables(hc, new Dictionary<string, string>(), new List<MaskHint>(), out warnings);
// Act.
variables.Set("foo", "bar");
// Assert.
Assert.Equal("bar", variables.Get("foo"));
}
}
示例7: Set_CanUpdateASecret
public void Set_CanUpdateASecret()
{
using (TestHostContext hc = new TestHostContext(this))
{
// Arrange.
List<string> warnings;
var variables = new Variables(hc, new Dictionary<string, string>(), new List<MaskHint>(), out warnings);
// Act.
variables.Set("foo", "bar", secret: true);
variables.Set("foo", "baz", secret: true);
// Assert.
Assert.Equal(0, variables.Public.Count());
Assert.Equal("baz", variables.Get("foo"));
}
}
示例8: RecalculateExpanded_RetainsUpdatedSecretness
public void RecalculateExpanded_RetainsUpdatedSecretness()
{
using (TestHostContext hc = new TestHostContext(this))
{
// Arrange.
List<string> warnings;
var variables = new Variables(hc, new Dictionary<string, string>(), new List<MaskHint>(), out warnings);
Assert.Equal(0, warnings.Count);
variables.Set("foo", "bar");
Assert.Equal(1, variables.Public.Count());
// Act.
variables.Set("foo", "baz", secret: true);
variables.RecalculateExpanded(out warnings);
// Assert.
Assert.Equal(0, warnings.Count);
Assert.Equal(0, variables.Public.Count());
Assert.Equal("baz", variables.Get("foo"));
}
}
示例9: RecalculateExpanded_PerformsRecalculation
public void RecalculateExpanded_PerformsRecalculation()
{
using (TestHostContext hc = new TestHostContext(this))
{
// Arrange.
List<string> warnings;
var original = new Dictionary<string, string>
{
{ "topLevelVariable", "$(nestedVariable1) $(nestedVariable2)" },
{ "nestedVariable1", "Some nested value 1" },
};
var variables = new Variables(hc, original, new List<MaskHint>(), out warnings);
Assert.Equal(0, warnings.Count);
Assert.Equal(2, variables.Public.Count());
Assert.Equal("Some nested value 1 $(nestedVariable2)", variables.Get("topLevelVariable"));
Assert.Equal("Some nested value 1", variables.Get("nestedVariable1"));
// Act.
variables.Set("nestedVariable2", "Some nested value 2", secret: false);
variables.RecalculateExpanded(out warnings);
// Assert.
Assert.Equal(0, warnings.Count);
Assert.Equal(3, variables.Public.Count());
Assert.Equal("Some nested value 1 Some nested value 2", variables.Get("topLevelVariable"));
Assert.Equal("Some nested value 1", variables.Get("nestedVariable1"));
Assert.Equal("Some nested value 2", variables.Get("nestedVariable2"));
}
}
示例10: ExpandValues_DoesNotRecurse
public void ExpandValues_DoesNotRecurse()
{
using (TestHostContext hc = new TestHostContext(this))
{
// Arrange: Setup the variables. The value of the variable1 variable
// should not get expanded since variable2 does not exist when the
// variables class is initialized (and therefore would never get expanded).
List<string> warnings;
var variableDictionary = new Dictionary<string, string>
{
{ "variable1", "$(variable2)" },
};
var variables = new Variables(hc, variableDictionary, new List<MaskHint>(), out warnings);
variables.Set("variable2", "some variable 2 value");
// Arrange: Setup the target dictionary.
var targetDictionary = new Dictionary<string, string>();
targetDictionary["some target key"] = "before $(variable1) after";
// Act.
variables.ExpandValues(target: targetDictionary);
// Assert: The variable should only have been expanded one level.
Assert.Equal("before $(variable2) after", targetDictionary["some target key"]);
}
}
示例11: SetupMocks
private void SetupMocks([CallerMemberName] string name = "")
{
_hc = new TestHostContext(this, name);
_hc.SetSingleton(_mockResultReader.Object);
_mockExtensionManager = new Mock<IExtensionManager>();
_mockExtensionManager.Setup(x => x.GetExtensions<IResultReader>()).Returns(new List<IResultReader> { _mockResultReader.Object, new JUnitResultReader(), new NUnitResultReader() });
_hc.SetSingleton(_mockExtensionManager.Object);
_hc.SetSingleton(_mockTestRunPublisher.Object);
_mockCommandContext = new Mock<IAsyncCommandContext>();
_hc.EnqueueInstance(_mockCommandContext.Object);
var endpointAuthorization = new EndpointAuthorization()
{
Scheme = EndpointAuthorizationSchemes.OAuth
};
List<string> warnings;
_variables = new Variables(_hc, new Dictionary<string, string>(), new List<MaskHint>(), out warnings);
_variables.Set("build.buildId", "1");
endpointAuthorization.Parameters[EndpointAuthorizationParameters.AccessToken] = "accesstoken";
_ec = new Mock<IExecutionContext>();
_ec.Setup(x => x.Endpoints).Returns(new List<ServiceEndpoint> { new ServiceEndpoint { Url = new Uri("http://dummyurl"), Name = ServiceEndpoints.SystemVssConnection, Authorization = endpointAuthorization } });
_ec.Setup(x => x.Variables).Returns(_variables);
var asyncCommands = new List<IAsyncCommandContext>();
_ec.Setup(x => x.AsyncCommands).Returns(asyncCommands);
_ec.Setup(x => x.AddIssue(It.IsAny<Issue>()))
.Callback<Issue>
((issue) =>
{
if (issue.Type == IssueType.Warning)
{
_warnings.Add(issue.Message);
}
else if (issue.Type == IssueType.Error)
{
_errors.Add(issue.Message);
}
});
}