• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C# TestCase类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C#中TestCase的典型用法代码示例。如果您正苦于以下问题:C# TestCase类的具体用法?C# TestCase怎么用?C# TestCase使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



TestCase类属于命名空间,在下文中一共展示了TestCase类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。

示例1: DoTest

        private void DoTest(TestCase test)
        {
            if (animation.IsStarted)
                animation.Stop();

            Graphics g = ctResults.Panel1.CreateGraphics();
            //this.CreateGraphics();
            g.Clear(Color.White);
            var bmp = new Bitmap((int) g.VisibleClipBounds.Width, (int) g.VisibleClipBounds.Height);
            Graphics tmp = Graphics.FromImage(bmp);
            var ctx = new CanvasRenderingContext2D(tmp, bmp, new Pen(Color.Black, 1), new Fill(Color.Black), false);
            string url = test(ctx);
            g.DrawImage(bmp, 0, 0);
            var di = new DirectoryInfo(Application.StartupPath);
            url = di.Parent.Parent.Parent.FullName + "\\SharpCanvas.Tests\\" + url;
            if (File.Exists(url))
            {
                pctOriginal.Load(url);
                pctOriginal.Show();
            }
            else
            {
                pctOriginal.Hide();
            }
        }
开发者ID:podlipensky,项目名称:sharpcanvas,代码行数:25,代码来源:TestEngine.cs


示例2: RunTest

        private void RunTest(ITestExecutionRecorder frameworkHandle, string source, string spec = null)
        {
            var results = appDomainRunner.ExecuteSpecifications(source, spec);
            var query = from result in results
                        from @group in result.Examples
                        from example in @group.Examples
                        select example;

            foreach (var example in query) {
                var testCase = new TestCase(example.Reason, ExecutorUri, source) {
                    CodeFilePath = source
                };

                frameworkHandle.RecordStart(testCase);
                var testResult = new TestResult(testCase) {
                    DisplayName = example.Reason,
                    Duration = new TimeSpan(example.ElapsedTime),
                };

                if (example.Status == ResultStatus.Error) {
                    testResult.Outcome = TestOutcome.Failed;
                    testResult.ErrorMessage = example.Message;
                    testResult.ErrorStackTrace = example.StackTrace;
                }

                if (example.Status == ResultStatus.Success) {
                    testResult.Outcome = TestOutcome.Passed;
                }

                frameworkHandle.RecordEnd(testCase, testResult.Outcome);
                frameworkHandle.RecordResult(testResult);
            }
        }
开发者ID:alexfalkowski,项目名称:System.Spec,代码行数:33,代码来源:DefaultTestExecutor.cs


示例3: RunAllTestsInDocument_ShouldExtractAllProjectReferences_And_PassItTo_TestSandbox

        public void RunAllTestsInDocument_ShouldExtractAllProjectReferences_And_PassItTo_TestSandbox()
        {
            // arrange
            var project = CreateProject("SampleTestsProject");
            string[] allProjectReferences = { "A" };

            _solutionExplorerMock.GetAllProjectReferences(project.Name).Returns(allProjectReferences);
            var testNode = CSharpSyntaxTree.ParseText("[TestFixture]class HelloWorldTests{" +
                                             " [Test] public void TestMethod()" +
                                             "{}" +
                                             "}");

            var testClass = testNode.GetRoot().GetClassDeclarationSyntax();
            var fixtureDetails = new TestFixtureDetails();
            var testCase = new TestCase(fixtureDetails) { SyntaxNode = testClass.GetPublicMethods().Single() };
            fixtureDetails.Cases.Add(testCase);

            _testExtractorMock.GetTestClasses(Arg.Any<CSharpSyntaxNode>())
                .Returns(new[] { testClass });
            _testExtractorMock.GetTestFixtureDetails(testClass, Arg.Any<ISemanticModel>()).Returns(fixtureDetails);

            var rewrittenDocument = new RewrittenDocument(testNode, null, false);

            // act
            _sut.RunAllTestsInDocument(rewrittenDocument, null, project, new string[0]);

            // assert
            _testExecutorEngineMock.Received(1).
                RunTestFixture(Arg.Is<string[]>(x => x[0] == allProjectReferences[0]), Arg.Any<TestFixtureExecutionScriptParameters>());
        }
开发者ID:pzielinski86,项目名称:RuntimeTestCoverage,代码行数:30,代码来源:TestRunnerTests.cs


示例4: GetTests

        internal static IList<TestCase> GetTests(IEnumerable<string> sources, ITestCaseDiscoverySink discoverySink = null, ITestContainer testContainer = null)
        {
            IList<TestCase> tests = new List<TestCase>();

            foreach (var assemblyFileName in sources)
            {
                Assembly assembly = Assembly.LoadFrom(assemblyFileName);

                var methodsWithMoyaAttributes = assembly.GetTypes()
                      .SelectMany(t => t.GetMethods())
                      .Where(Reflection.MethodInfoHasMoyaAttribute)
                      .ToArray();

                foreach (MethodInfo methodWithMoyaAttributes in methodsWithMoyaAttributes)
                {
                    var testCase = new TestCase(methodWithMoyaAttributes.Name, Constants.ExecutorUri, assemblyFileName)
                    {
                        Id = Guid.NewGuid()
                    };

                    tests.Add(testCase);
                    if (discoverySink != null)
                    {
                        discoverySink.SendTestCase(testCase);
                    }
                    if (testContainer != null)
                    {
                        testContainer.AddTestCaseAndMethod(testCase, methodWithMoyaAttributes);
                    }
                }
            }

            return tests;
        }
开发者ID:Hammerstad,项目名称:Moya,代码行数:34,代码来源:MoyaTestDiscoverer.cs


示例5: GetTests

        public static IEnumerable<TestCase> GetTests(IEnumerable<string> sourceFiles, ITestCaseDiscoverySink discoverySink)
        {
            var tests = new List<TestCase>();

            Parallel.ForEach(sourceFiles, s =>
            {
                var sourceCode = File.ReadAllText(s);

                var matches = TestFinderRegex.Matches(sourceCode);
                foreach (Match m in matches)
                {
                    var methodParts = m.Groups["Method"].Value.Split(new string[] { ".prototype." }, System.StringSplitOptions.None);
                    var testClass = methodParts[0];
                    var testMethod = methodParts[1];
                    var testName = m.Groups["Name"].Value;
                    var testDescription = m.Groups["Description"].Value;
                    var testCase = new TestCase(String.Join(".", methodParts), TSTestExecutor.ExecutorUri, s)
                    {
                        CodeFilePath = s,
                        DisplayName = testName,
                    };

                    if (discoverySink != null)
                    {
                        discoverySink.SendTestCase(testCase);
                    }
                    tests.Add(testCase);
                }
            });

            return tests;
        }
开发者ID:midwinterfs,项目名称:TSTestExtension,代码行数:32,代码来源:TSTestDiscoverer.cs


示例6: GetTests

internal static IEnumerable<TestCase> GetTests(IEnumerable<string> sources, ITestCaseDiscoverySink discoverySink)
        {
            //if(!Debugger.IsAttached)
            //        Debugger.Launch();
            var tests = new List<TestCase>();

               
                foreach (string source in sources)
                {
                    var TestNames = GetTestNameFromFile(source);
                    foreach (var testName in TestNames)
                    {
                        var normalizedSource = source.ToLowerInvariant();
                        var testCase = new TestCase(testName.Key, ProtractorTestExecutor.ExecutorUri, normalizedSource);
                        tests.Add(testCase);
                        testCase.CodeFilePath = source;
                        testCase.LineNumber = testName.Value;

                        if (discoverySink != null)
                        {

                            discoverySink.SendTestCase(testCase);
                        }
                    }
                }
                        return tests;
        }
开发者ID:XpiritBV,项目名称:ProtractorAdapter,代码行数:27,代码来源:ProtractorTestDiscoverer.cs


示例7: AddAll

    public override void AddAll(TestCase test)
    {
        // Do like super's
        base.AddAll(test);

        // If test invalid
        if (null == test) {
            // Error
            throw new Exception("Invalid test case encountered.");
        }

        // For each method in the test case
        Type type = test.GetType();
        foreach (MethodInfo method in type.GetMethods()) {
            // For each unit test attribute
            foreach (System.Object obj in method.GetCustomAttributes(typeof(CoroutineUnitTest), false)) {
                // If attribute is valid
                Attribute testAtt = obj as Attribute;
                if (null != testAtt) {
                    // If type has constructors
                    ConstructorInfo[] ci = type.GetConstructors();
                    if (0 < ci.Length) {
                        // Add the test
                        TestCase tmp = ci[0].Invoke(null) as TestCase;
                        tmp.SetTestMethod(method.Name);
                        coroutineTests.Add(tmp);
                    }
                }
            }
        }
    }
开发者ID:eckyputrady,项目名称:SharpUnit,代码行数:31,代码来源:Unity3D_TestSuite.cs


示例8: Main

        static void Main(string[] args)
        {
            var endOfRec = DateTime.Now.Add(TimeSpan.FromSeconds(30));
            using (var writer = new AviWriter("test.avi")
            {
                FramesPerSecond = 15,
                EmitIndex1 = true
            })
            {
                var stream = writer.AddVideoStream();

                stream.Width = Screen.PrimaryScreen.WorkingArea.Width;
                stream.Height = Screen.PrimaryScreen.WorkingArea.Height;
                stream.Codec = KnownFourCCs.Codecs.Uncompressed;
                stream.BitsPerPixel = BitsPerPixel.Bpp32;

                var googleChrome = new TestCase();

                Task.Factory.StartNew(() =>
                {
                    googleChrome.Scenario("http://www.google.com", "что посмотреть сегодня?");
                });

                var buffer = new byte[Screen.PrimaryScreen.WorkingArea.Width * Screen.PrimaryScreen.WorkingArea.Height * 4];
                while (!TestCase.isFinished)
                {
                    GetScreenshot(buffer);
                    stream.WriteFrame(true, buffer, 0, buffer.Length);
                }
            }

            Console.WriteLine("Execution Done");
        }
开发者ID:JevgenijsSaveljevs,项目名称:SeleniumMag,代码行数:33,代码来源:Program.cs


示例9: WriteTestCase

        private void WriteTestCase(string outputDirectory, TestCase currentTestCase)
        {
            EnsureDirectoryExists(outputDirectory);

            File.WriteAllText(Path.Combine(outputDirectory, currentTestCase.Name + ".txt"), currentTestCase.Content);
            File.WriteAllText(Path.Combine(outputDirectory, currentTestCase.Name + ".json"), currentTestCase.Json);
        }
开发者ID:LogHash,项目名称:loghash-testgen,代码行数:7,代码来源:TestGen.cs


示例10: Apply

        public IEnumerable<Violation> Apply(TestCase testCase)
        {
            var calledAssertingMethods = testCase.GetCalledAssertingMethods();
            var tracker = new MethodValueTracker(testCase.TestMethod);

            // For each asserting method with >= 1 parameters:
            foreach (var cm in calledAssertingMethods)
            {
                var methodRef = cm.MethodReference;
                var parameterPurposes = testCase.Framework.GetParameterPurposes(methodRef);
                if (!IsSingleTruthCheckingMethod(methodRef, parameterPurposes))
                    continue;

                foreach (var valueGraph in tracker.ValueGraphs)
                {
                    IList<MethodValueTracker.Value> consumedValues =
                        tracker.GetConsumedValues(valueGraph, cm.Instruction).ToList();
                    if (consumedValues.Count == 0)
                        continue; // not part of value graph
                    var interestingValue = consumedValues[0];
                    var producers = UltimateProducers(interestingValue);
                    if (producers.Count > 1)
                    {
                        yield return new Violation(this, testCase, cm.Instruction, string.Format("{0}.{1} performs a boolean test on a composite boolean value",
                            cm.MethodReference.DeclaringType.Name,
                            cm.MethodReference.Name));
                    }
                }
            }
        }
开发者ID:provegard,项目名称:testness,代码行数:30,代码来源:AvoidAssertBooleanRule.cs


示例11: CreateTest

        private ObjectModel.TestResult CreateTest(TestData test, TestStepRun stepRun, TestCase testCase)
        {
            ObjectModel.TestResult testResult = new ObjectModel.TestResult(testCase);
            testResult.DisplayName = test.Name;
            testResult.ErrorLineNumber = test.CodeLocation.Line;
            //testResult.ErrorStackTrace
            testResult.StartTime = stepRun.StartTime;
            if (stepRun.TestLog.Streams.Count > 0)
            {
                testResult.ErrorMessage = stepRun.TestLog.Streams[0].ToString();
            }
            testResult.EndTime = stepRun.EndTime;

            testResult.Duration = stepRun.Result.Duration;

            var testStatus = stepRun.Result.Outcome.Status;
            switch (testStatus)
            {
                case TestStatus.Passed:
                    testResult.Outcome = ObjectModel.TestOutcome.Passed;
                    break;
                case TestStatus.Failed:
                    testResult.Outcome = ObjectModel.TestOutcome.Failed;
                    break;
                case TestStatus.Skipped:
                    testResult.Outcome = ObjectModel.TestOutcome.Skipped;
                    break;
                case TestStatus.Inconclusive:
                    testResult.Outcome = ObjectModel.TestOutcome.NotFound;
                    break;
            }

            return testResult;
        }
开发者ID:poobah,项目名称:Gallio-VS2011-Integration,代码行数:34,代码来源:VSTestWindowExtension.cs


示例12: TestFailed

 public TestFailed(Exception ex)
 {
     TestCase = new TestCase();
     ExceptionType = ex.GetType().FullName;
     Message = ExceptionUtility.GetMessage(ex);
     StackTrace = ExceptionUtility.GetStackTrace(ex);
 }
开发者ID:johnkg,项目名称:xunit,代码行数:7,代码来源:TestFailed.cs


示例13: TestCaseFull

 /// <summary>
 /// Initializes a new instance of the <see cref="TestCaseFull" /> class.
 /// </summary>
 /// <param name="testCase">The test case.</param>
 /// <param name="testSteps">The test steps.</param>
 /// <param name="mostRecentResult">The most recent result.</param>
 /// <param name="executionComment">The execution comment.</param>
 public TestCaseFull(TestCase testCase, List<TestStep> testSteps, string mostRecentResult, string executionComment)
 {
     this.TestCase = testCase;
     this.TestSteps = testSteps;
     this.MostRecentResult = mostRecentResult;
     this.ExecutionComment = executionComment;
 }
开发者ID:ypupo2002,项目名称:tfs-testcasemanager,代码行数:14,代码来源:TestCaseFull.cs


示例14: DoTest

        private void DoTest(TestCase test)
        {
            var canvas = new Canvas();
            canvas.Width = 300;
            canvas.Height = 700;
            ICanvasRenderingContext2D ctx = new CanvasRenderingContext2D(canvas, this, true);
            string url = test(ctx);
            ctx.commit();
            string location = Application.ResourceAssembly.Location;
            string path = location.Remove(location.LastIndexOf("\\"));

            var di = new DirectoryInfo(path);
            url = di.Parent.Parent.Parent.FullName + "\\SharpCanvas.Tests\\" + url;
            if (File.Exists(url))
            {
                pctOriginal.Source = new BitmapImage(new Uri(url));
                pctOriginal.Visibility = Visibility.Visible;
            }
            else
            {
                pctOriginal.Visibility = Visibility.Hidden;
            }
            ctResults.Children.Clear();
            ctResults.Children.Add(canvas);
        }
开发者ID:podlipensky,项目名称:sharpcanvas,代码行数:25,代码来源:TestEngine.xaml.cs


示例15: GetTestCase

        public TestCase GetTestCase(TestData testData)
        {
            string displayName;

            var fullName = testData.FullName;

            var pos = fullName.LastIndexOf('/');

            if (pos == -1)
            {
                displayName = testData.CodeReference.MemberName;
            }
            else
            {
                displayName = fullName.Substring(pos + 1);
            }

            var testCase = new TestCase(fullName, new Uri(GallioAdapter.ExecutorUri), GetSource(testData))
            {
                CodeFilePath = testData.CodeLocation.Path,
                LineNumber = testData.CodeLocation.Line,
                DisplayName = displayName
            };

            testCase.SetPropertyValue(testIdProperty, testData.Id);

            return testCase;
        }
开发者ID:pawelpabich,项目名称:Gallio-VS2011-Integration,代码行数:28,代码来源:TestCaseFactory.cs


示例16: DelayTestCaseTest

        public void DelayTestCaseTest()
        {
            DeleteFiles();
            int stepDelayDuration = 500;
            var step = new DelayStep();
            step.DelayMilliSeconds = stepDelayDuration;

            var sw = new Stopwatch();
            sw.Start();

            step.Execute(new Context());

            var actualDuration = sw.ElapsedMilliseconds;
            Console.WriteLine("Observed delay: {0}", actualDuration);
            Assert.AreEqual(stepDelayDuration, actualDuration, 20);

            stepDelayDuration = 5;
            step.DelayMilliSeconds = stepDelayDuration;

            var tc = new TestCase();
            tc.ExecutionSteps.Add(step);

            TestCase.SaveToFile(tc, "DelayTestCaseTest.xaml");
            var bu = new BizUnit(TestCase.LoadFromFile("DelayTestCaseTest.xaml"));

            sw = new Stopwatch();
            sw.Start();

            bu.RunTest();

            actualDuration = sw.ElapsedMilliseconds;
            Console.WriteLine("Observed delay: {0}", actualDuration);
            Assert.AreEqual(actualDuration, stepDelayDuration, 20);
        }
开发者ID:RobBowman,项目名称:BizUnit,代码行数:34,代码来源:DelayTests.cs


示例17: btnAdd_Click

        private void btnAdd_Click(object sender, RoutedEventArgs e)
        {
            string newTestName;
            for (int testId = 1; ; ++testId)
            {
                newTestName = "case" + testId;
                if (!TestCases.Any(t => StringComparer.CurrentCultureIgnoreCase.Equals(newTestName, t.Name)))
                {
                    break;
                }
            }

            var newTestCase = new TestCase
            {
                Name = newTestName,
                Input = "",
                Output = "",
                IsSkipped = false,
                OutputIsKnown = true,
            };

            TestCases.Add(newTestCase);
            lstTestCases.Items.Add(newTestCase);
            lstTestCases.SelectedItem = newTestCase;
        }
开发者ID:saint1729,项目名称:caide,代码行数:25,代码来源:EditTestsWindow.xaml.cs


示例18: RunAllTestsInDocument_ShouldExtractAllTestCases

        public void RunAllTestsInDocument_ShouldExtractAllTestCases()
        {
            // arrange
            var project = CreateProject("SampleTestsProject");
            var semanticModel = Substitute.For<ISemanticModel>();

            var testNode = CSharpSyntaxTree.ParseText("[TestFixture]class HelloWorldTests{" +
                                             " [Test] public void TestMethod()" +
                                             "{}" +
                                             "}");

            var testClass = testNode.GetRoot().GetClassDeclarationSyntax();
            var fixtureDetails = new TestFixtureDetails();
            var testCase = new TestCase(fixtureDetails) { SyntaxNode = testClass.GetPublicMethods().Single() };
            fixtureDetails.Cases.Add(testCase);

            _testExtractorMock.GetTestClasses(Arg.Any<CSharpSyntaxNode>())
                .Returns(new[] { testClass });

            _testExtractorMock.GetTestFixtureDetails(Arg.Any<ClassDeclarationSyntax>(), Arg.Any<ISemanticModel>()).Returns(fixtureDetails);
            var rewrittenDocument = new RewrittenDocument(testNode, null, false);

            // act
            _sut.RunAllTestsInDocument(rewrittenDocument, semanticModel, project, new string[0]);

            // assert
            _testExtractorMock.Received(1).GetTestFixtureDetails(testClass, semanticModel);
        }
开发者ID:pzielinski86,项目名称:RuntimeTestCoverage,代码行数:28,代码来源:TestRunnerTests.cs


示例19: StreamReader

        static TextWriter tw; //= new StreamReader("A-small-attempt3.in");

        #endregion Fields

        #region Methods

        static void Main(string[] args)
        {
            tr = new StreamReader("C-large-1.in");

            int n = Convert.ToInt16(tr.ReadLine());
            List<TestCase> testCases = new List<TestCase>();

            for (; i < n; i++)
            {
                TestCase t = new TestCase();
                string[] temp2 = tr.ReadLine().Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
                //string[] temp2 = temp.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
                t.lowLimit = Convert.ToInt64(temp2[0]);
                t.upperLimit = Convert.ToInt64(temp2[1]);
                testCases.Add(t.processInput());

            }
            tw = new StreamWriter("output.txt");
            i = 0;
            for (; i < testCases.Count-1; i++)
            {
                tw.WriteLine("Case #{0}: {1}", (i + 1), testCases[i].output);
            }
            tw.Write("Case #{0}: {1}", (i + 1), testCases[i].output);
            tr.Close();
            tw.Close();
            //Console.ReadLine();
        }
开发者ID:VigneshPT,项目名称:CodeJamQRoundPalindrome,代码行数:34,代码来源:Program.cs


示例20: AddChildToTestCase

        public void AddChildToTestCase()
        {
            TestSuite master = new TestSuite("master", null);
            TestCase test = new TestCase("test", master);

            test.AddChild(new TestCase());
        }
开发者ID:ETAS-Eder,项目名称:vs-boost-unit-test-adapter,代码行数:7,代码来源:BoostTestTest.cs



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# TestClass类代码示例发布时间:2022-05-24
下一篇:
C# TestCSSNode类代码示例发布时间:2022-05-24
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap