当前位置: 首页>>代码示例>>C#>>正文


C# TestEnvironment类代码示例

本文整理汇总了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);
            }
        }
开发者ID:xyh413,项目名称:roslyn,代码行数:29,代码来源:AnalyzersTests.cs

示例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;
        }
开发者ID:aldass,项目名称:mycouch,代码行数:27,代码来源:ShowsFixture.cs

示例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"}));
 }
开发者ID:sillsdev,项目名称:cog,代码行数:7,代码来源:BlairCognateIdentifierTests.cs

示例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();
            }
        }
开发者ID:xyh413,项目名称:roslyn,代码行数:25,代码来源:CSharpReferencesTests.cs

示例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);
            }
        }
开发者ID:XieShuquan,项目名称:roslyn,代码行数:27,代码来源:AnalyzersTests.cs

示例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);
        }
开发者ID:vorou,项目名称:shouldly,代码行数:29,代码来源:ShouldBeIgnoringOrderMessageGenerator.cs

示例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());
            }
        }
开发者ID:Rickinio,项目名称:roslyn,代码行数:29,代码来源:CSharpCompilerOptionsTests.cs

示例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");
            }
        }
开发者ID:jmkelly,项目名称:shouldly,代码行数:26,代码来源:DictionaryShouldContainKeyAndValueMessageGenerator.cs

示例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;
        }
开发者ID:jmkelly,项目名称:shouldly,代码行数:29,代码来源:ShouldBeWithinRangeMessageGenerator.cs

示例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;
        }
开发者ID:sluu99,项目名称:mycouch,代码行数:31,代码来源:ViewsFixture.cs

示例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);
            }
        }
开发者ID:xyh413,项目名称:roslyn,代码行数:28,代码来源:AnalyzersTests.cs

示例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);
            }
        }
开发者ID:nileshjagtap,项目名称:roslyn,代码行数:30,代码来源:AnalyzersTests.cs

示例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()));
            }
        }
开发者ID:rmunn,项目名称:cog,代码行数:28,代码来源:VarietyPairsViewModelTests.cs

示例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));
        }
开发者ID:freezy,项目名称:vpdb-agent,代码行数:27,代码来源:MenuManager.Test.cs

示例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);
        }
开发者ID:XieShuquan,项目名称:roslyn,代码行数:7,代码来源:CSharpHelpers.cs


注:本文中的TestEnvironment类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。