public static UnitTestElementDisposition BuildDisposition(UnitTestElement element, ScenarioLocation location, IProjectFile projectFile) { var contents = File.ReadAllText(location.Path); var range = new TextRange(LineToOffset(contents, location.FromLine), LineToOffset(contents, location.ToLine)); return new UnitTestElementDisposition(element, projectFile, range, new TextRange(0)); }
private bool ProcessDataSourceTests(UnitTestElement test, TestMethodInfo testMethodInfo, ITestContext testContext, List <UnitTestElement> tests) { var dataRows = PlatformServiceProvider.Instance.TestDataSource.GetData(testMethodInfo, testContext); if (dataRows == null || !dataRows.Any()) { return(false); } try { int rowIndex = 0; foreach (var dataRow in dataRows) { // TODO: Test serialization rowIndex++; var displayName = string.Format(CultureInfo.CurrentCulture, Resource.DataDrivenResultDisplayName, test.DisplayName, rowIndex); var discoveredTest = test.Clone(); discoveredTest.DisplayName = displayName; discoveredTest.TestMethod.DataType = DynamicDataType.DataSourceAttribute; discoveredTest.TestMethod.SerializedData = DataSerializationHelper.Serialize(new[] { (object)rowIndex }); tests.Add(discoveredTest); } return(true); } finally { testContext.SetDataConnection(null); testContext.SetDataRow(null); } }
/// <summary> /// Gets a UnitTestElement from a MethodInfo object filling it up with appropriate values. /// </summary> /// <param name="method">The reflected method.</param> /// <param name="isDeclaredInTestTypeAssembly">True if the reflected method is declared in the same assembly as the current type.</param> /// <param name="warnings">Contains warnings if any, that need to be passed back to the caller.</param> /// <returns> Returns a UnitTestElement.</returns> internal UnitTestElement GetTestFromMethod(MethodInfo method, bool isDeclaredInTestTypeAssembly, ICollection <string> warnings) { Debug.Assert(this.type.AssemblyQualifiedName != null, "AssemblyQualifiedName for method is null."); // This allows void returning async test method to be valid test method. Though they will be executed similar to non-async test method. var isAsync = ReflectHelper.MatchReturnType(method, typeof(Task)); var testMethod = new TestMethod(method.Name, this.type.FullName, this.assemblyName, isAsync); if (!method.DeclaringType.FullName.Equals(this.type.FullName)) { testMethod.DeclaringClassFullName = method.DeclaringType.FullName; } if (!isDeclaredInTestTypeAssembly) { testMethod.DeclaringAssemblyName = PlatformServiceProvider.Instance.FileOperations.GetAssemblyPath( method.DeclaringType.GetTypeInfo().Assembly); } var testElement = new UnitTestElement(testMethod); // Get compiler generated type name for async test method (either void returning or task returning). var asyncTypeName = method.GetAsyncTypeName(); testElement.AsyncTypeName = asyncTypeName; testElement.TestCategory = this.reflectHelper.GetCategories(method); testElement.DoNotParallelize = this.reflectHelper.IsDoNotParallelizeSet(method); var traits = this.reflectHelper.GetTestPropertiesAsTraits(method); var ownerTrait = this.reflectHelper.GetTestOwnerAsTraits(method); if (ownerTrait != null) { traits = traits.Concat(new[] { ownerTrait }); } testElement.Priority = this.reflectHelper.GetPriority(method); var priorityTrait = this.reflectHelper.GetTestPriorityAsTraits(testElement.Priority); if (priorityTrait != null) { traits = traits.Concat(new[] { priorityTrait }); } testElement.Traits = traits.ToArray(); // Get Deployment items if any. testElement.DeploymentItems = PlatformServiceProvider.Instance.TestDeployment.GetDeploymentItems( method, this.type, warnings); return(testElement); }
public StorEvilProjectElement(StorEvilTestProvider provider, UnitTestElement parent, IProject project, string title, IEnumerable<string> assemblies) : base(provider, parent, project, title) { Assemblies = assemblies; _namespace = new UnitTestNamespace(project.Name + ": StorEvil specifications"); }
public bool IsElementOfKind(UnitTestElement element, UnitTestElementKind kind) { if (element == null) { throw new ArgumentNullException("element"); } GallioTestElement gallioTestElement = element as GallioTestElement; if (gallioTestElement == null) { return(false); } switch (kind) { case UnitTestElementKind.Unknown: case UnitTestElementKind.TestStuff: return(false); case UnitTestElementKind.Test: return(gallioTestElement.IsTestCase); case UnitTestElementKind.TestContainer: return(!gallioTestElement.IsTestCase); default: throw new ArgumentOutOfRangeException("kind"); } }
public IList<UnitTestTask> GetTasks(UnitTestElement element, IList<UnitTestElement> explicitElements) { //if (!(element is StorEvilScenarioElement)) // return new List<UnitTestTask>(); var tasks = new List<UnitTestTask>(); if (element is StorEvilProjectElement) { var projectEl = element as StorEvilProjectElement; tasks.Add(new UnitTestTask(null, new LoadContextAssemblyTask(typeof(Scenario).Assembly.Location))); foreach (string assembly in projectEl.Assemblies) { tasks.Add(new UnitTestTask(null, new LoadContextAssemblyTask(assembly))); } tasks.Add(GetProjectTask(projectEl, explicitElements)); } if (element is StorEvilStoryElement) { tasks.Add(GetProjectTask(element.Parent as StorEvilProjectElement, explicitElements)); tasks.Add(GetStoryTask(element as StorEvilStoryElement, explicitElements)); } if (element is StorEvilScenarioElement) { tasks.Add(GetProjectTask(element.Parent.Parent as StorEvilProjectElement, explicitElements)); tasks.Add(GetStoryTask(element.Parent as StorEvilStoryElement, explicitElements)); tasks.Add(GetScenarioTask(element, explicitElements)); } return tasks; }
public void EnumerateAssemblyShouldLoadExeContainersInReflectionOnlyContext() { var mockAssembly = CreateMockTestableAssembly(); var testableAssemblyEnumerator = new TestableAssemblyEnumerator(); var unitTestElement = new UnitTestElement(new TestMethod("DummyMethod", "DummyClass", "DummyAssembly", false)); // Setup mocks mockAssembly.Setup(a => a.DefinedTypes) .Returns(new List <TypeInfo>() { typeof(DummyTestClass).GetTypeInfo() }); this.testablePlatformServiceProvider.MockFileOperations.Setup(fo => fo.LoadAssembly("DummyAssembly.exe", true)) .Returns(mockAssembly.Object); testableAssemblyEnumerator.MockTypeEnumerator.Setup(te => te.Enumerate(out this.warnings)) .Returns(new Collection <UnitTestElement> { unitTestElement }); var testElements = testableAssemblyEnumerator.EnumerateAssembly("DummyAssembly.exe", out this.warnings); CollectionAssert.AreEqual(new Collection <UnitTestElement> { unitTestElement }, testElements.ToList()); }
public StorEvilScenarioOutlineElement(StorEvilTestProvider provider, UnitTestElement parent, IProject project, string title, ScenarioOutline scenarioOutline) : base(provider, parent, project, title) { _scenarioOutline = scenarioOutline; _namespace = new UnitTestNamespace(project.Name); }
/// <summary> /// The to unit test element. /// </summary> /// <param name="testCase"> The test case. </param> /// <param name="source"> The source. If deployed this is the full path of the source in the deployment directory. </param> /// <returns> The converted <see cref="UnitTestElement"/>. </returns> internal static UnitTestElement ToUnitTestElement(this TestCase testCase, string source) { var isAsync = (testCase.GetPropertyValue(Constants.AsyncTestProperty) as bool?) ?? false; var testClassName = testCase.GetPropertyValue(Constants.TestClassNameProperty) as string; var declaringClassName = testCase.GetPropertyValue(Constants.DeclaringClassNameProperty) as string; var parts = testCase.FullyQualifiedName.Split('.'); var name = parts[parts.Length - 1]; TestMethod testMethod = new TestMethod(name, testClassName, source, isAsync); if (declaringClassName != null && declaringClassName != testClassName) { testMethod.DeclaringClassFullName = declaringClassName; } UnitTestElement testElement = new UnitTestElement(testMethod) { IsAsync = isAsync, TestCategory = testCase.GetPropertyValue(Constants.TestCategoryProperty) as string[], Priority = testCase.GetPropertyValue(Constants.PriorityProperty) as int?, DisplayName = testCase.DisplayName }; return(testElement); }
/// <summary> /// The to unit test element. /// </summary> /// <param name="testCase"> The test case. </param> /// <param name="source"> The source. If deployed this is the full path of the source in the deployment directory. </param> /// <returns> The converted <see cref="UnitTestElement"/>. </returns> internal static UnitTestElement ToUnitTestElement(this TestCase testCase, string source) { var isAsync = (testCase.GetPropertyValue(Constants.AsyncTestProperty) as bool?) ?? false; var testClassName = testCase.GetPropertyValue(Constants.TestClassNameProperty) as string; var declaringClassName = testCase.GetPropertyValue(Constants.DeclaringClassNameProperty) as string; var fullyQualifiedName = testCase.FullyQualifiedName; // Not using Replace because there can be multiple instances of that string. var name = fullyQualifiedName.StartsWith($"{testClassName}.") ? fullyQualifiedName.Remove(0, $"{testClassName}.".Length) : fullyQualifiedName; TestMethod testMethod = new TestMethod(name, testClassName, source, isAsync); if (declaringClassName != null && declaringClassName != testClassName) { testMethod.DeclaringClassFullName = declaringClassName; } UnitTestElement testElement = new UnitTestElement(testMethod) { IsAsync = isAsync, TestCategory = testCase.GetPropertyValue(Constants.TestCategoryProperty) as string[], Priority = testCase.GetPropertyValue(Constants.PriorityProperty) as int?, DisplayName = testCase.DisplayName }; return(testElement); }
public StorEvilScenarioElement(StorEvilTestProvider provider, UnitTestElement parent, IProject project, string title, Scenario scenario) : base(provider, parent, project, title) { _namespace = new UnitTestNamespace(project.Name); Scenario = scenario; }
protected StorEvilUnitTestElement(IUnitTestProvider provider, UnitTestElement parent, IProject project, string title) : base(provider, parent) { Project = project; _title = title; }
public StorEvilStoryElement(StorEvilTestProvider provider, UnitTestElement parent, IProject project, string title, string path) : base(provider, parent, project, title) { _path = path; _namespace = new UnitTestNamespace(project.Name + " " + title); }
public void Cleanup() { this.test = null; this.testElements = null; PlatformServiceProvider.Instance = null; MSTestSettings.Reset(); }
public StorEvilProjectElement(StorEvilTestProvider provider, UnitTestElement parent, IProject project, string title, IEnumerable <string> assemblies) : base(provider, parent, project, title) { Assemblies = assemblies; _namespace = new UnitTestNamespace(project.Name + ": StorEvil specifications"); }
public IList <UnitTestTask> GetTaskSequence(UnitTestElement element, IList <UnitTestElement> explicitElements) { var testElement = element as MSTestElement; if (testElement != null) { MSTestFixtureElement parentFixture = testElement.Fixture; return(new[] { new UnitTestTask(null, new AssemblyLoadTask(parentFixture.AssemblyLocation)), new UnitTestTask(parentFixture, new MSTestFixtureTask(parentFixture.AssemblyLocation, parentFixture.GetTypeClrName(), explicitElements.Contains(parentFixture))), new UnitTestTask(testElement, new MSTestTask(parentFixture.GetTypeClrName(), testElement.MethodName, explicitElements.Contains(testElement))), }); } var fixture = element as MSTestFixtureElement; if (fixture != null) { return(EmptyArray <UnitTestTask> .Instance); } throw new ArgumentException(string.Format("element is not MSTest: '{0}'", element)); }
public int CompareUnitTestElements(UnitTestElement x, UnitTestElement y) { if (Equals(x, y)) { return(0); } int compare = StringComparer.CurrentCultureIgnoreCase.Compare(x.GetTypeClrName(), y.GetTypeClrName()); if (compare != 0) { return(compare); } if (x is MSTestElement && y is MSTestFixtureElement) { return(-1); } if (y is MSTestElement && x is MSTestFixtureElement) { return(1); } if (x is MSTestFixtureElement && y is MSTestFixtureElement) { return(0); // two different elements with same type name?? } var xe = (MSTestElement)x; var ye = (MSTestElement)y; return(xe.Order.CompareTo(ye.Order)); }
public StorEvilStoryElement(StorEvilTestProvider provider, UnitTestElement parent, IProject project, string title, ConfigSettings config, string id) : base(provider, parent, project, title) { Config = config; Id = id; _namespace = new UnitTestNamespace(project.Name + " " + title); }
private bool TryProcessDataSource(UnitTestElement test, TestMethodInfo testMethodInfo, ITestContext testContext, List <UnitTestElement> tests) { var dataSourceAttributes = ReflectHelper.GetAttributes <UTF.DataSourceAttribute>(testMethodInfo.MethodInfo, false); if (dataSourceAttributes == null) { return(false); } if (dataSourceAttributes.Length > 1) { var message = string.Format(CultureInfo.CurrentCulture, Resource.CannotEnumerateDataSourceAttribute_MoreThenOneDefined, test.TestMethod.ManagedTypeName, test.TestMethod.ManagedMethodName, dataSourceAttributes.Length); PlatformServiceProvider.Instance.AdapterTraceLogger.LogInfo($"DynamicDataEnumarator: {message}"); throw new InvalidOperationException(message); } // dataSourceAttributes.Length == 1 try { return(this.ProcessDataSourceTests(test, testMethodInfo, testContext, tests)); } catch (Exception ex) { var message = string.Format(CultureInfo.CurrentCulture, Resource.CannotEnumerateDataSourceAttribute, test.TestMethod.ManagedTypeName, test.TestMethod.ManagedMethodName, ex); PlatformServiceProvider.Instance.AdapterTraceLogger.LogInfo($"DynamicDataEnumarator: {message}"); return(false); } }
public static UnitTestElementDisposition BuildDisposition(UnitTestElement element, ScenarioLocation location, IProjectFile projectFile) { var contents = File.ReadAllText(location.Path); var range = new TextRange(LineToOffset(contents, location.FromLine), LineToOffset(contents, location.ToLine)); return(new UnitTestElementDisposition(element, projectFile, range, new TextRange(0))); }
protected Element(IUnitTestProvider provider, UnitTestElement parent, ProjectModelElementEnvoy projectEnvoy, string declaringTypeName, bool isIgnored) : base(provider, parent) { if (projectEnvoy == null && !Shell.Instance.IsTestShell) { throw new ArgumentNullException("projectEnvoy"); } if (declaringTypeName == null) { throw new ArgumentNullException("declaringTypeName"); } _projectEnvoy = projectEnvoy; _declaringTypeName = declaringTypeName; if (isIgnored) { SetExplicit("Ignored"); } }
public void EnumerateAssemblyShouldReturnMoreThanOneTestElementForMoreThanOneType() { var mockAssembly = CreateMockTestableAssembly(); var testableAssemblyEnumerator = new TestableAssemblyEnumerator(); var unitTestElement = new UnitTestElement(new TestMethod("DummyMethod", "DummyClass", "DummyAssembly", false)); var expectedTestElements = new Collection <UnitTestElement> { unitTestElement, unitTestElement }; // Setup mocks mockAssembly.Setup(a => a.DefinedTypes) .Returns(new List <TypeInfo>() { typeof(DummyTestClass).GetTypeInfo(), typeof(DummyTestClass).GetTypeInfo() }); this.testablePlatformServiceProvider.MockFileOperations.Setup(fo => fo.LoadAssembly("DummyAssembly", false)) .Returns(mockAssembly.Object); testableAssemblyEnumerator.MockTypeEnumerator.Setup(te => te.Enumerate(out this.warnings)) .Returns(expectedTestElements); var testElements = testableAssemblyEnumerator.EnumerateAssembly("DummyAssembly", out this.warnings); expectedTestElements.Add(unitTestElement); expectedTestElements.Add(unitTestElement); CollectionAssert.AreEqual(expectedTestElements, testElements.ToList()); }
public void SendTestCasesShouldUseNaigationSessionForDeclaredAssemblyName() { var source = "DummyAssembly.dll"; // Setup mocks. this.testablePlatformServiceProvider.MockFileOperations.Setup(fo => fo.CreateNavigationSession(source)) .Returns((object)null); var test = new UnitTestElement( new TestMethod("M", "C", "A", false) { DeclaringAssemblyName = "DummyAssembly2.dll" }); var testElements = new List <UnitTestElement> { test }; this.SetupNavigation(source, test, test.TestMethod.DeclaringClassFullName, test.TestMethod.Name); // Act this.unitTestDiscoverer.SendTestCases(source, testElements, this.mockTestCaseDiscoverySink.Object); // Assert this.testablePlatformServiceProvider.MockFileOperations.Verify(fo => fo.CreateNavigationSession("DummyAssembly2.dll"), Times.Once); }
private TestCase GetTestCase(Type typeOfClass, string testName, bool ignore = false) { var methodInfo = typeOfClass.GetMethod(testName); var testMethod = new TestMethod(methodInfo.Name, typeOfClass.FullName, Assembly.GetExecutingAssembly().FullName, isAsync: false); UnitTestElement element = new UnitTestElement(testMethod); element.Ignored = ignore; return(element.ToTestCase()); }
private void AddStoryElement(Story story, IProject project, UnitTestElementConsumer consumer, UnitTestElement parent) { var storyElement = GetStoryElement(parent, project, story); consumer(storyElement); foreach (IScenario scenario in story.Scenarios) AddScenarioElement(project, consumer, storyElement, scenario); }
/// <summary> /// Serializes element for persistence. /// </summary> public string Serialize(UnitTestElement element) { if (element == null) { throw new ArgumentNullException("element"); } return(null); }
public IList <UnitTestTask> GetTaskSequence(UnitTestElement element, IList <UnitTestElement> explicitElements) { if (element is ContextSpecificationElement) { var contextSpecification = element as ContextSpecificationElement; var context = contextSpecification.Context; return(new List <UnitTestTask> { _taskFactory.CreateAssemblyLoadTask(context), _taskFactory.CreateContextTask(context, explicitElements.Contains(context)), _taskFactory.CreateContextSpecificationTask(context, contextSpecification, explicitElements.Contains(contextSpecification)) }); } if (element is BehaviorElement) { var behavior = element as BehaviorElement; var context = behavior.Context; return(new List <UnitTestTask> { _taskFactory.CreateAssemblyLoadTask(context), _taskFactory.CreateContextTask(context, explicitElements.Contains(context)), _taskFactory.CreateBehaviorTask(context, behavior, explicitElements.Contains(behavior)) }); } if (element is BehaviorSpecificationElement) { var behaviorSpecification = element as BehaviorSpecificationElement; var behavior = behaviorSpecification.Behavior; var context = behavior.Context; return(new List <UnitTestTask> { _taskFactory.CreateAssemblyLoadTask(context), _taskFactory.CreateContextTask(context, explicitElements.Contains(context)), _taskFactory.CreateBehaviorTask(context, behavior, explicitElements.Contains(behavior)), _taskFactory.CreateBehaviorSpecificationTask(context, behaviorSpecification, explicitElements.Contains(behaviorSpecification)) }); } if (element is ContextElement) { return(EmptyArray <UnitTestTask> .Instance); } throw new ArgumentException(String.Format("Element is not a Machine.Specifications element: '{0}'", element)); }
public IList<UnitTestTask> GetTaskSequence(UnitTestElement element, IList<UnitTestElement> explicitElements) { if (element is ContextSpecificationElement) { var contextSpecification = element as ContextSpecificationElement; var context = contextSpecification.Context; return new List<UnitTestTask> { _taskFactory.CreateAssemblyLoadTask(context), _taskFactory.CreateContextTask(context, explicitElements.Contains(context)), _taskFactory.CreateContextSpecificationTask(context, contextSpecification, explicitElements.Contains(contextSpecification)) }; } if (element is BehaviorElement) { var behavior = element as BehaviorElement; var context = behavior.Context; return new List<UnitTestTask> { _taskFactory.CreateAssemblyLoadTask(context), _taskFactory.CreateContextTask(context, explicitElements.Contains(context)), _taskFactory.CreateBehaviorTask(context, behavior, explicitElements.Contains(behavior)) }; } if (element is BehaviorSpecificationElement) { var behaviorSpecification = element as BehaviorSpecificationElement; var behavior = behaviorSpecification.Behavior; var context = behavior.Context; return new List<UnitTestTask> { _taskFactory.CreateAssemblyLoadTask(context), _taskFactory.CreateContextTask(context, explicitElements.Contains(context)), _taskFactory.CreateBehaviorTask(context, behavior, explicitElements.Contains(behavior)), _taskFactory.CreateBehaviorSpecificationTask(context, behaviorSpecification, explicitElements.Contains(behaviorSpecification)) }; } if (element is ContextElement) { return EmptyArray<UnitTestTask>.Instance; } throw new ArgumentException(String.Format("Element is not a Machine.Specifications element: '{0}'", element)); }
/// <summary> /// Execute test method. Capture failures, handle async and return result. /// </summary> /// <param name="arguments"> /// Arguments to pass to test method. (E.g. For data driven) /// </param> /// <returns>Result of test method invocation.</returns> public virtual TestResult Invoke(object[] arguments) { Stopwatch watch = new Stopwatch(); TestResult result = null; // check if arguments are set for data driven tests if (arguments == null) { arguments = this.Arguments; } using (LogMessageListener listener = new LogMessageListener(this.TestMethodOptions.CaptureDebugTraces)) { var testElement = new UnitTestElement(new TestMethod(this)) { TestId = this.TestId }; watch.Start(); try { this.TestExecutionRecorder.RecordStart(testElement); if (this.IsTimeoutSet) { result = this.ExecuteInternalWithTimeout(arguments); } else { result = this.ExecuteInternal(arguments); } } finally { // Handle logs & debug traces. watch.Stop(); if (result != null) { result.Duration = watch.Elapsed; result.DebugTrace = listener.DebugTrace; result.LogOutput = listener.StandardOutput; result.LogError = listener.StandardError; result.TestContextMessages = this.TestMethodOptions.TestContext.GetAndClearDiagnosticMessages(); result.ResultFiles = this.TestMethodOptions.TestContext.GetResultFiles(); result.TestId = this.TestId; } this.TestExecutionRecorder.RecordEnd( testElement, result?.Outcome.ToUnitTestOutcome() ?? UnitTestOutcome.Error); } } return(result); }
protected FieldElement(IUnitTestProvider provider, UnitTestElement parent, ProjectModelElementEnvoy projectEnvoy, string declaringTypeName, string fieldName, bool isIgnored) : base(provider, parent, projectEnvoy, declaringTypeName, isIgnored || parent.IsExplicit) { _fieldName = fieldName; }
public StorEvilStoryElement(StorEvilTestProvider provider, UnitTestElement parent, IProject project, string title, string path) : base(provider, parent, project, title) { _path = path; var root = project.Location.ToDirectoryInfo().FullName; var pathPieces = PathHelper.GetRelativePathPieces(root, _path); var pathJoined = project.Name + " " + string.Join(" - ", pathPieces); _namespace = new UnitTestNamespace(pathJoined + title); }
protected FieldElement(IUnitTestProvider provider, UnitTestElement parent, IProjectModelElement project, string declaringTypeName, string fieldName, bool isIgnored) : base(provider, parent, project, declaringTypeName, isIgnored || parent.IsExplicit) { _fieldName = fieldName; }
public bool IsOfKind(UnitTestElement element, UnitTestElementKind elementKind) { if (element is StorEvilScenarioElement) return elementKind == UnitTestElementKind.Test; if (element is StorEvilStoryElement || element is StorEvilProjectElement) return elementKind == UnitTestElementKind.TestContainer; return false; }
protected FieldElement(IUnitTestProvider provider, UnitTestElement parent, IProjectModelElement project, string declaringTypeName, string fieldName, bool isIgnored) : base(provider, parent, project, declaringTypeName, isIgnored || parent.IsExplicit) { _fieldName = fieldName; AssignCategories(parent.GetCategories().Select(x => x.Name).ToList()); }
private void AddStoryElement(Story story, IProject project, UnitTestElementConsumer consumer, UnitTestElement parent) { var storyElement = GetStoryElement(parent, project, story); consumer(storyElement); foreach (IScenario scenario in story.Scenarios) { AddScenarioElement(project, consumer, storyElement, scenario); } }
public IList <UnitTestTask> GetTasks(UnitTestElement element, IList <UnitTestElement> explicitElements) { //if (!(element is StorEvilScenarioElement)) // return new List<UnitTestTask>(); var tasks = new List <UnitTestTask>(); if (element is StorEvilProjectElement) { var projectEl = element as StorEvilProjectElement; tasks.Add(new UnitTestTask(null, new LoadContextAssemblyTask(typeof(Scenario).Assembly.Location))); foreach (string assembly in projectEl.Assemblies) { tasks.Add(new UnitTestTask(null, new LoadContextAssemblyTask(assembly))); } tasks.Add(GetProjectTask(projectEl, explicitElements)); } if (element is StorEvilStoryElement) { tasks.Add(GetProjectTask(element.Parent as StorEvilProjectElement, explicitElements)); tasks.Add(GetStoryTask(element as StorEvilStoryElement, explicitElements)); } if (element is StorEvilScenarioElement) { if (element.Parent is StorEvilScenarioOutlineElement) { tasks.Add(GetProjectTask(element.Parent.Parent.Parent as StorEvilProjectElement, explicitElements)); tasks.Add(GetStoryTask(element.Parent.Parent as StorEvilStoryElement, explicitElements)); tasks.Add(GetScenarioOutlineTask(element.Parent, explicitElements)); tasks.Add(GetScenarioTask(element, explicitElements)); } else { tasks.Add(GetProjectTask(element.Parent.Parent as StorEvilProjectElement, explicitElements)); tasks.Add(GetStoryTask(element.Parent as StorEvilStoryElement, explicitElements)); tasks.Add(GetScenarioTask(element, explicitElements)); } } if (element is StorEvilScenarioOutlineElement) { tasks.Add(GetProjectTask(element.Parent.Parent as StorEvilProjectElement, explicitElements)); tasks.Add(GetStoryTask(element.Parent as StorEvilStoryElement, explicitElements)); tasks.Add(GetScenarioOutlineTask(element, explicitElements)); } return(tasks); }
public bool IsElementOfKind(UnitTestElement element, UnitTestElementKind elementKind) { switch (elementKind) { case UnitTestElementKind.Test: return(element is ContextSpecificationElement); case UnitTestElementKind.TestContainer: return(element is ContextElement || element is BehaviorElement); } return(false); }
public int CompareUnitTestElements(UnitTestElement x, UnitTestElement y) { if (x is StorEvilStoryElement && y is StorEvilStoryElement) return ((StorEvilStoryElement)x).Id == ((StorEvilStoryElement)y).Id ? 0 : -1; if (x is StorEvilScenarioElement && y is StorEvilScenarioElement) return ((StorEvilScenarioElement)x).Scenario.Id.CompareTo(((StorEvilScenarioElement)y).Scenario.Id); if (x is StorEvilProjectElement && y is StorEvilProjectElement) return x.GetNamespace().NamespaceName.CompareTo(y.GetNamespace().NamespaceName); return -1; }
public bool IsOfKind(UnitTestElement element, UnitTestElementKind elementKind) { if (element is StorEvilScenarioElement) { return(elementKind == UnitTestElementKind.Test); } if (element is StorEvilStoryElement || element is StorEvilProjectElement || element is StorEvilScenarioOutlineElement) { return(elementKind == UnitTestElementKind.TestContainer); } return(false); }
private void CreateContainerElements(IExampleContainer[] exampleContainers, UnitTestElement parent) { foreach (var exampleContainer in exampleContainers) { var element = new ExampleContainerElement(_provider, _project, parent, (ExampleContainer)exampleContainer); _consumer(element); CreateContainerElements(exampleContainer.ExampleContainers, element); foreach (var example in exampleContainer.Examples) _consumer(new ExampleElement(_provider, element, _project, (Example)example)); } }
public void TestInit() { this.testablePlatformServiceProvider = new TestablePlatformServiceProvider(); this.unitTestDiscoverer = new UnitTestDiscoverer(); this.mockMessageLogger = new Mock <IMessageLogger>(); this.mockTestCaseDiscoverySink = new Mock <ITestCaseDiscoverySink>(); this.mockRunSettings = new Mock <IRunSettings>(); this.test = new UnitTestElement(new TestMethod("M", "C", "A", false)); this.testElements = new List <UnitTestElement> { this.test }; PlatformServiceProvider.Instance = this.testablePlatformServiceProvider; }
public void Present(UnitTestElement element, IPresentableItem item, TreeModelNode node, PresentationState state) { item.RichText = element.GetTitle(); var standardImage = GetImage(element); var stateImage = UnitTestManager.GetStateImage(state); if (stateImage != null) { item.Images.Add(stateImage); } else if (standardImage != null) { item.Images.Add(standardImage); } }
/// <summary> /// The to unit test element. /// </summary> /// <param name="testCase"> The test case. </param> /// <param name="source"> The source. If deployed this is the full path of the source in the deployment directory. </param> /// <returns> The converted <see cref="UnitTestElement"/>. </returns> internal static UnitTestElement ToUnitTestElement(this TestCase testCase, string source) { var isAsync = (testCase.GetPropertyValue(Constants.AsyncTestProperty) as bool?) ?? false; var testClassName = testCase.GetPropertyValue(Constants.TestClassNameProperty) as string; TestMethod testMethod = new TestMethod(testCase.DisplayName, testClassName, source, isAsync); UnitTestElement testElement = new UnitTestElement(testMethod) { IsAsync = isAsync, TestCategory = testCase.GetPropertyValue(Constants.TestCategoryProperty) as string[], Priority = testCase.GetPropertyValue(Constants.PriorityProperty) as int? }; return(testElement); }
/// <summary> /// Compares unit tests elements to determine relative sort order. /// </summary> public int CompareUnitTestElements(UnitTestElement x, UnitTestElement y) { if (x == null) { throw new ArgumentNullException("x"); } if (y == null) { throw new ArgumentNullException("y"); } GallioTestElement xe = (GallioTestElement)x; GallioTestElement ye = (GallioTestElement)y; return(xe.CompareTo(ye)); }
public void Present(UnitTestElement element, IPresentableItem item, TreeModelNode node, PresentationState state) { var testElement = element as StorEvilUnitTestElement; if (testElement == null) return; item.RichText = element.ShortName; Image standardImage = UnitTestManager.GetStandardImage(UnitTestElementImage.Test); Image stateImage = UnitTestManager.GetStateImage(state); if (stateImage != null) { item.Images.Add(stateImage); } else if (standardImage != null) { item.Images.Add(standardImage); } }
/// <summary> /// Presents unit test. ///</summary> public void Present(UnitTestElement element, IPresentableItem item, TreeModelNode node, PresentationState state) { if (element == null) throw new ArgumentNullException("element"); if (item == null) throw new ArgumentNullException("item"); if (node == null) throw new ArgumentNullException("node"); if (state == null) throw new ArgumentNullException("state"); presenter.UpdateItem(element, node, item, state); }
public bool IsElementOfKind(UnitTestElement element, UnitTestElementKind kind) { if (element == null) throw new ArgumentNullException("element"); GallioTestElement gallioTestElement = element as GallioTestElement; if (gallioTestElement == null) return false; switch (kind) { case UnitTestElementKind.Unknown: case UnitTestElementKind.TestStuff: return false; case UnitTestElementKind.Test: return gallioTestElement.IsTestCase; case UnitTestElementKind.TestContainer: return ! gallioTestElement.IsTestCase; default: throw new ArgumentOutOfRangeException("kind"); } }
/// <summary> /// Gets task information for <see cref="T:JetBrains.ReSharper.TaskRunnerFramework.RemoteTaskRunner" /> from element. /// </summary> public IList<UnitTestTask> GetTaskSequence(UnitTestElement element, IList<UnitTestElement> explicitElements) { if (element == null) throw new ArgumentNullException("element"); if (explicitElements == null) throw new ArgumentNullException("explicitElements"); GallioTestElement topElement = (GallioTestElement)element; List<UnitTestTask> tasks = new List<UnitTestTask>(); // Add the run task. Must always be first. tasks.Add(new UnitTestTask(null, FacadeTaskFactory.CreateRootTask())); // Add the test case branch. AddTestTasksFromRootToLeaf(tasks, topElement); // Now that we're done with the critical parts of the task tree, we can add other // arbitrary elements. We don't care about the structure of the task tree beyond this depth. // Add the assembly location. tasks.Add(new UnitTestTask(null, FacadeTaskFactory.CreateAssemblyTaskFrom(topElement))); if (explicitElements.Count != 0) { // Add explicit element markers. foreach (GallioTestElement explicitElement in explicitElements) tasks.Add(new UnitTestTask(null, FacadeTaskFactory.CreateExplicitTestTaskFrom(explicitElement))); } else { // No explicit elements but we must have at least one to filter by, so we consider // the top test explicitly selected. tasks.Add(new UnitTestTask(null, FacadeTaskFactory.CreateExplicitTestTaskFrom(topElement))); } return tasks; }
/// <summary> /// Serializes element for persistence. /// </summary> public string Serialize(UnitTestElement element) { if (element == null) throw new ArgumentNullException("element"); return null; }
public void Present(UnitTestElement element, IPresentableItem item, TreeModelNode node, PresentationState state) { Presenter.UpdateItem(element, node, item, state); }
/// <summary> /// Compares unit tests elements to determine relative sort order. /// </summary> public int CompareUnitTestElements(UnitTestElement x, UnitTestElement y) { if (x == null) throw new ArgumentNullException("x"); if (y == null) throw new ArgumentNullException("y"); GallioTestElement xe = (GallioTestElement)x; GallioTestElement ye = (GallioTestElement)y; return xe.CompareTo(ye); }
public IList<UnitTestTask> GetTaskSequence(UnitTestElement element, IList<UnitTestElement> explicitElements) { return _taskFactory.GetTasks(element, explicitElements); }
public bool IsElementOfKind(UnitTestElement element, UnitTestElementKind elementKind) { return _comparer.IsOfKind(element, elementKind); }
public int CompareUnitTestElements(UnitTestElement x, UnitTestElement y) { return _comparer.CompareUnitTestElements(x, y); }
public string Serialize(UnitTestElement element) { return ""; }
public void Present(UnitTestElement element, IPresentableItem item, TreeModelNode node, PresentationState state) { _presenter.Present(element, item, node, state); }