本文整理汇总了C#中TestEnvironment类的典型用法代码示例。如果您正苦于以下问题:C# TestEnvironment类的具体用法?C# TestEnvironment怎么用?C# TestEnvironment使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
TestEnvironment类属于命名空间,在下文中一共展示了TestEnvironment类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: RuleSet_ProjectNoWarnOverridesOtherSettings
public void RuleSet_ProjectNoWarnOverridesOtherSettings()
{
string ruleSetSource = @"<?xml version=""1.0"" encoding=""utf-8""?>
<RuleSet Name=""Ruleset1"" Description=""Test"" ToolsVersion=""12.0"">
<IncludeAll Action=""Warning"" />
<Rules AnalyzerId=""Microsoft.Analyzers.ManagedCodeAnalysis"" RuleNamespace=""Microsoft.Rules.Managed"">
<Rule Id=""CS1014"" Action=""Info"" />
</Rules>
</RuleSet>
";
using (var ruleSetFile = new DisposableFile())
using (var environment = new TestEnvironment())
{
File.WriteAllText(ruleSetFile.Path, ruleSetSource);
var project = CSharpHelpers.CreateCSharpProject(environment, "Test");
project.SetRuleSetFile(ruleSetFile.Path);
project.SetOptionWithMarshaledValue(CompilerOptions.OPTID_NOWARNLIST, "1014");
project.SetOptionWithMarshaledValue(CompilerOptions.OPTID_WARNASERRORLIST, "1014");
var workspaceProject = environment.Workspace.CurrentSolution.Projects.Single();
var options = (CSharpCompilationOptions)workspaceProject.CompilationOptions;
var ca1014DiagnosticOption = options.SpecificDiagnosticOptions["CS1014"];
Assert.Equal(expected: ReportDiagnostic.Suppress, actual: ca1014DiagnosticOption);
}
}
示例2: Init
public Artist[] Init(TestEnvironment environment)
{
if(_artists != null && _artists.Any())
return _artists;
IntegrationTestsRuntime.EnsureCleanEnvironment();
_artists = ClientTestData.Artists.CreateArtists(2);
using (var client = IntegrationTestsRuntime.CreateDbClient())
{
var bulk = new BulkRequest();
bulk.Include(_artists.Select(i => client.Entities.Serializer.Serialize(i)).ToArray());
var bulkResponse = client.Documents.BulkAsync(bulk).Result;
foreach (var row in bulkResponse.Rows)
{
var artist = _artists.Single(i => i.ArtistId == row.Id);
client.Entities.Reflector.RevMember.SetValueTo(artist, row.Rev);
}
client.Documents.PostAsync(ClientTestData.Shows.ArtistsShows).Wait();
}
return _artists;
}
示例3: UpdateCognacy_NoSimilarSegments
public void UpdateCognacy_NoSimilarSegments()
{
var env = new TestEnvironment("hɛ.lo", "he.ɬa");
env.UpdateCognacy();
Assert.That(env.WordPair.PredictedCognacy, Is.False);
Assert.That(env.WordPair.AlignmentNotes, Is.EqualTo(new[] {"1", "2", "3", "2"}));
}
示例4: AddCyclicProjectReferencesDeep
public void AddCyclicProjectReferencesDeep()
{
using (var environment = new TestEnvironment())
{
var project1 = CreateCSharpProject(environment, "project1");
var project2 = CreateCSharpProject(environment, "project2");
var project3 = CreateCSharpProject(environment, "project3");
var project4 = CreateCSharpProject(environment, "project4");
project1.AddProjectReference(new ProjectReference(project2.Id));
project2.AddProjectReference(new ProjectReference(project3.Id));
project3.AddProjectReference(new ProjectReference(project4.Id));
project4.AddProjectReference(new ProjectReference(project1.Id));
Assert.Equal(true, project1.GetCurrentProjectReferences().Any(pr => pr.ProjectId == project2.Id));
Assert.Equal(true, project2.GetCurrentProjectReferences().Any(pr => pr.ProjectId == project3.Id));
Assert.Equal(true, project3.GetCurrentProjectReferences().Any(pr => pr.ProjectId == project4.Id));
Assert.Equal(false, project4.GetCurrentProjectReferences().Any(pr => pr.ProjectId == project1.Id));
project4.Disconnect();
project3.Disconnect();
project2.Disconnect();
project1.Disconnect();
}
}
示例5: RuleSet_GeneralOption_CPS
public void RuleSet_GeneralOption_CPS()
{
string ruleSetSource = @"<?xml version=""1.0"" encoding=""utf-8""?>
<RuleSet Name=""Ruleset1"" Description=""Test"" ToolsVersion=""12.0"">
<IncludeAll Action=""Error"" />
</RuleSet>
";
using (var ruleSetFile = new DisposableFile())
using (var environment = new TestEnvironment())
using (var project = CSharpHelpers.CreateCSharpCPSProject(environment, "Test"))
{
File.WriteAllText(ruleSetFile.Path, ruleSetSource);
var workspaceProject = environment.Workspace.CurrentSolution.Projects.Single();
var options = (CSharpCompilationOptions)workspaceProject.CompilationOptions;
Assert.Equal(expected: ReportDiagnostic.Default, actual: options.GeneralDiagnosticOption);
project.SetRuleSetFile(ruleSetFile.Path);
project.SetOptions($"/ruleset:{ruleSetFile.Path}");
workspaceProject = environment.Workspace.CurrentSolution.Projects.Single();
options = (CSharpCompilationOptions)workspaceProject.CompilationOptions;
Assert.Equal(expected: ReportDiagnostic.Error, actual: options.GeneralDiagnosticOption);
}
}
示例6: GenerateErrorMessage
public override string GenerateErrorMessage(TestEnvironment environment)
{
var expected = ((IEnumerable)environment.Expected).Cast<object>().ToArray();
var actual = ((IEnumerable)environment.Actual).Cast<object>().ToArray();
var codePart = environment.GetCodePart();
var expectedFormattedValue = expected.Inspect();
var missingFromExpected = actual.Where(a => !expected.Any(e => Is.Equal(e, a))).ToArray();
var missingFromActual = expected.Where(e => !actual.Any(a => Is.Equal(e, a))).ToArray();
var actualMissingMessage = missingFromActual.Any() ? string.Format("{0} is missing {1}", codePart,
missingFromActual.Inspect()) : string.Empty;
var expectedMissingMessage = missingFromExpected.Any() ? string.Format("{0} is missing {1}", expectedFormattedValue,
missingFromExpected.Inspect()) : string.Empty;
//"first should be second (ignoring order) but first is missing [4] and second is missing [2]"
const string format = @"
{0}
{1}
{2} (ignoring order)
but
{3}";
string missingMessage = !string.IsNullOrEmpty(actualMissingMessage) && !string.IsNullOrEmpty(expectedMissingMessage)
? string.Format("{0} and {1}", actualMissingMessage, expectedMissingMessage)
: string.Format("{0}{1}", actualMissingMessage, expectedMissingMessage);
return string.Format(format, codePart, environment.ShouldMethod.PascalToSpaced(), expectedFormattedValue, missingMessage);
}
示例7: ProjectOutputBinPathChange_CPS
public void ProjectOutputBinPathChange_CPS()
{
var initialBinPath = @"C:\test.dll";
using (var environment = new TestEnvironment())
using (var project = CSharpHelpers.CreateCSharpCPSProject(environment, "Test", $"/out:{initialBinPath}"))
{
Assert.Equal(initialBinPath, project.TryGetBinOutputPath());
Assert.Equal(initialBinPath, project.TryGetObjOutputPath());
// Change output folder.
var newBinPath = @"C:\NewFolder\test.dll";
project.SetCommandLineArguments($"/out:{newBinPath}");
Assert.Equal(newBinPath, project.TryGetBinOutputPath());
Assert.Equal(newBinPath, project.TryGetObjOutputPath());
// Change output file name.
newBinPath = @"C:\NewFolder\test2.dll";
project.SetCommandLineArguments($"/out:{newBinPath}");
Assert.Equal(newBinPath, project.TryGetBinOutputPath());
Assert.Equal(newBinPath, project.TryGetObjOutputPath());
// Change output file name and folder.
newBinPath = @"C:\NewFolder3\test3.dll";
project.SetCommandLineArguments($"/out:{newBinPath}");
Assert.Equal(newBinPath, project.TryGetBinOutputPath());
Assert.Equal(newBinPath, project.TryGetObjOutputPath());
}
}
示例8: GenerateErrorMessage
public override string GenerateErrorMessage(TestEnvironment environment)
{
const string format = @"
Dictionary
""{0}""
should contain key
""{1}""
with value
""{2}""
{3}";
var codePart = environment.GetCodePart();
var expectedValue = environment.Expected.Inspect();
var actualValue = environment.Actual.Inspect();
var keyValue = environment.Key.Inspect();
if (environment.HasKey)
{
var valueString = string.Format("but value was \"{0}\"", actualValue.Trim('"'));
return String.Format(format, codePart, keyValue.Trim('"'), expectedValue.Trim('"'), valueString);
}
else
{
return String.Format(format, codePart, actualValue.Trim('"'), expectedValue.Trim('"'), "but the key does not exist");
}
}
示例9: GenerateErrorMessage
public override string GenerateErrorMessage(TestEnvironment environment)
{
const string format = @"
{0}
should {1}be within
{2}
of
{3}
but was
{4}";
var codePart = environment.GetCodePart();
var tolerance = environment.Tolerance.Inspect();
var expectedValue = environment.Expected.Inspect();
var actualValue = environment.Actual.Inspect();
var negated = environment.ShouldMethod.Contains("Not") ? "not " : string.Empty;
var message = string.Format(format, codePart, negated, tolerance, expectedValue, actualValue);
if (environment.Actual.CanGenerateDifferencesBetween(environment.Expected))
{
message += string.Format(@"
difference
{0}",
environment.Actual.HighlightDifferencesBetween(environment.Expected));
}
return message;
}
示例10: Init
public Artist[] Init(TestEnvironment environment)
{
if(_artists != null && _artists.Any())
return _artists;
IntegrationTestsRuntime.EnsureCleanEnvironment();
_artists = ClientTestData.Artists.CreateArtists(10);
using (var client = IntegrationTestsRuntime.CreateDbClient())
{
var bulk = new BulkRequest();
bulk.Include(_artists.Select(i => client.Entities.Serializer.Serialize(i)).ToArray());
var bulkResponse = client.Documents.BulkAsync(bulk).Result;
foreach (var row in bulkResponse.Rows)
{
var artist = _artists.Single(i => i.ArtistId == row.Id);
client.Entities.Reflector.RevMember.SetValueTo(artist, row.Rev);
}
client.Documents.PostAsync(ClientTestData.Views.ArtistsViews).Wait();
var queryRequests = ClientTestData.Views.AllViewIds.Select(id => new QueryViewRequest(id).Configure(q => q.Stale(Stale.UpdateAfter)));
var queries = queryRequests.Select(q => client.Views.QueryAsync(q) as Task).ToArray();
Task.WaitAll(queries);
}
return _artists;
}
示例11: RuleSet_SpecificOptions_CPS
public void RuleSet_SpecificOptions_CPS()
{
string ruleSetSource = @"<?xml version=""1.0"" encoding=""utf-8""?>
<RuleSet Name=""Ruleset1"" Description=""Test"" ToolsVersion=""12.0"">
<IncludeAll Action=""Warning"" />
<Rules AnalyzerId=""Microsoft.Analyzers.ManagedCodeAnalysis"" RuleNamespace=""Microsoft.Rules.Managed"">
<Rule Id=""CA1012"" Action=""Error"" />
</Rules>
</RuleSet>
";
using (var ruleSetFile = new DisposableFile())
using (var environment = new TestEnvironment())
{
File.WriteAllText(ruleSetFile.Path, ruleSetSource);
var project = CSharpHelpers.CreateCSharpCPSProject(environment, "Test");
project.SetRuleSetFile(ruleSetFile.Path);
CSharpHelpers.SetCommandLineArguments(project, commandLineArguments: $"/ruleset:{ruleSetFile.Path}");
var workspaceProject = environment.Workspace.CurrentSolution.Projects.Single();
var options = (CSharpCompilationOptions)workspaceProject.CompilationOptions;
var ca1012DiagnosticOption = options.SpecificDiagnosticOptions["CA1012"];
Assert.Equal(expected: ReportDiagnostic.Error, actual: ca1012DiagnosticOption);
}
}
示例12: RuleSet_ProjectSettingOverridesGeneralOption
public void RuleSet_ProjectSettingOverridesGeneralOption()
{
string ruleSetSource = @"<?xml version=""1.0"" encoding=""utf-8""?>
<RuleSet Name=""Ruleset1"" Description=""Test"" ToolsVersion=""12.0"">
<IncludeAll Action=""Warning"" />
</RuleSet>
";
using (var ruleSetFile = new DisposableFile())
using (var environment = new TestEnvironment())
{
File.WriteAllText(ruleSetFile.Path, ruleSetSource);
var project = CSharpHelpers.CreateCSharpProject(environment, "Test");
project.SetRuleSetFile(ruleSetFile.Path);
var workspaceProject = environment.Workspace.CurrentSolution.Projects.Single();
var options = (CSharpCompilationOptions)workspaceProject.CompilationOptions;
Assert.Equal(expected: ReportDiagnostic.Warn, actual: options.GeneralDiagnosticOption);
project.SetOptionWithMarshaledValue(CompilerOptions.OPTID_WARNINGSAREERRORS, true);
workspaceProject = environment.Workspace.CurrentSolution.Projects.Single();
options = (CSharpCompilationOptions)workspaceProject.CompilationOptions;
Assert.Equal(expected: ReportDiagnostic.Error, actual: options.GeneralDiagnosticOption);
}
}
示例13: FindCommand_FormFirstWordSelectedMatches_CorrectWordPairsSelected
public void FindCommand_FormFirstWordSelectedMatches_CorrectWordPairsSelected()
{
using (var env = new TestEnvironment())
{
SetupFindCommandTests(env);
WordPairViewModel[] cognatesArray = env.Cognates.WordPairsView.Cast<WordPairViewModel>().ToArray();
WordPairViewModel[] noncognatesArray = env.Noncognates.WordPairsView.Cast<WordPairViewModel>().ToArray();
env.Noncognates.SelectedWordPairs.Clear();
env.Cognates.SelectedWordPairs.Add(cognatesArray[0]);
env.FindViewModel.Field = FindField.Form;
env.FindViewModel.String = "ʊ";
env.FindViewModel.FindNextCommand.Execute(null);
Assert.That(env.Cognates.SelectedWordPairs, Is.Empty);
Assert.That(env.Noncognates.SelectedWordPairs, Is.EquivalentTo(noncognatesArray[0].ToEnumerable()));
env.FindViewModel.FindNextCommand.Execute(null);
Assert.That(env.Cognates.SelectedWordPairs, Is.EquivalentTo(cognatesArray[0].ToEnumerable()));
Assert.That(env.Noncognates.SelectedWordPairs, Is.Empty);
env.FindViewModel.FindNextCommand.Execute(null);
Assert.That(env.Cognates.SelectedWordPairs, Is.EquivalentTo(cognatesArray[0].ToEnumerable()));
Assert.That(env.Noncognates.SelectedWordPairs, Is.Empty);
// start over
env.FindViewModel.FindNextCommand.Execute(null);
Assert.That(env.Cognates.SelectedWordPairs, Is.Empty);
Assert.That(env.Noncognates.SelectedWordPairs, Is.EquivalentTo(noncognatesArray[0].ToEnumerable()));
}
}
示例14: ShouldParseGames
public void ShouldParseGames()
{
// setup
var env = new TestEnvironment(Logger);
var menu = new PinballXMenu();
menu.Games.Add(new PinballXGame() {
Filename = "Test_Game",
Description = "Test Game (Test 2016)"
});
env.Directory.Setup(d => d.Exists(TestEnvironment.VisualPinballDatabasePath)).Returns(true);
env.Directory.Setup(d => d.GetFiles(TestEnvironment.VisualPinballDatabasePath)).Returns(new []{ Path.GetFileName(TestEnvironment.VisualPinballDatabaseXmlPath) });
env.MarshallManager.Setup(m => m.UnmarshallXml("Visual Pinball.xml")).Returns(menu);
var menuManager = env.Locator.GetService<IMenuManager>();
// test
menuManager.Initialize();
// assert
menuManager.Systems.ToList().Should().NotBeEmpty().And.HaveCount(1);
var system = menuManager.Systems[0];
system.Games.Should().NotBeEmpty().And.HaveCount(1);
system.Games[0].Filename.Should().Be("Test_Game");
system.Games[0].Description.Should().Be("Test Game (Test 2016)");
system.Games[0].DatabaseFile.Should().Be(Path.GetFileName(TestEnvironment.VisualPinballDatabaseXmlPath));
}
示例15: CreateCSharpCPSProject
public static CPSProject CreateCSharpCPSProject(TestEnvironment environment, string projectName, Guid projectGuid, params string[] commandLineArguments)
{
var projectFilePath = Path.GetTempPath();
var binOutputPath = GetOutputPathFromArguments(commandLineArguments) ?? Path.Combine(projectFilePath, projectName + ".dll");
return CreateCSharpCPSProject(environment, projectName, projectFilePath, binOutputPath, projectGuid, commandLineArguments);
}