本文整理汇总了C#中TestCase类的典型用法代码示例。如果您正苦于以下问题:C# TestCase类的具体用法?C# TestCase怎么用?C# TestCase使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
TestCase类属于命名空间,在下文中一共展示了TestCase类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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();
}
}
示例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);
}
}
示例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>());
}
示例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;
}
示例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;
}
示例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;
}
示例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);
}
}
}
}
}
示例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");
}
示例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);
}
示例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));
}
}
}
}
示例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;
}
示例12: TestFailed
public TestFailed(Exception ex)
{
TestCase = new TestCase();
ExceptionType = ex.GetType().FullName;
Message = ExceptionUtility.GetMessage(ex);
StackTrace = ExceptionUtility.GetStackTrace(ex);
}
示例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;
}
示例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);
}
示例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;
}