public void Init()
		{
			IProject project = new MockCSharpProject();
			project.Name = "TestProject";
			ReferenceProjectItem nunitFrameworkReferenceItem = new ReferenceProjectItem(project);
			nunitFrameworkReferenceItem.Include = "NUnit.Framework";
			ProjectService.AddProjectItem(project, nunitFrameworkReferenceItem);

			MockProjectContent projectContent = new MockProjectContent();
			projectContent.Language = LanguageProperties.None;
			
			mockClass = new MockClass("RootNamespace.Tests.MyTestFixture");
			mockClass.Namespace = "RootNamespace.Tests";
			mockClass.ProjectContent = projectContent;
			mockClass.Attributes.Add(new MockAttribute("TestFixture"));
			projectContent.Classes.Add(mockClass);
			
			// Add a method to the test class
			MockMethod mockMethod = new MockMethod("TestMethod1");
			mockMethod.DeclaringType = mockClass;
			mockMethod.Attributes.Add(new MockAttribute("Test"));
			mockClass.Methods.Add(mockMethod);
			
			mockMethod = new MockMethod("TestMethod2");
			mockMethod.DeclaringType = mockClass;
			mockMethod.Attributes.Add(new MockAttribute("Test"));
			mockClass.Methods.Add(mockMethod);
			
			testProject = new TestProject(project, projectContent);
			testClass = testProject.TestClasses[0];
			testMethod1 = testClass.TestMethods[0];
			testMethod2 = testClass.TestMethods[1];
		}
		public void Init()
		{
			resultChangedCalled = false;
			IProject project = new MockCSharpProject();
			project.Name = "TestProject";
			ReferenceProjectItem nunitFrameworkReferenceItem = new ReferenceProjectItem(project);
			nunitFrameworkReferenceItem.Include = "NUnit.Framework";
			ProjectService.AddProjectItem(project, nunitFrameworkReferenceItem);
			
			projectContent = new MockProjectContent();
			projectContent.Language = LanguageProperties.None;
			
			MockClass mockClass = new MockClass(projectContent, "RootNamespace.Tests.MyTestFixture");
			mockClass.Attributes.Add(new MockAttribute("TestFixture"));
			projectContent.Classes.Add(mockClass);
			
			// Add a method to the test class
			MockMethod mockMethod = new MockMethod(mockClass, "TestMethod");
			mockMethod.Attributes.Add(new MockAttribute("Test"));
			mockClass.Methods.Add(mockMethod);
			
			testFrameworks = new MockTestFrameworksWithNUnitFrameworkSupport();
			testProject = new TestProject(project, projectContent, testFrameworks);
			testClass = testProject.TestClasses[0];
			testMethod = testClass.TestMethods[0];
		}
예제 #3
0
		public TestMethodTreeNode(TestProject project, TestMethod testMethod) 
			: base(project, testMethod.Name)
		{
			this.testMethod = testMethod;
			testMethod.ResultChanged += TestMethodResultChanged;
			UpdateImageListIndex(testMethod.Result);
		}
		public void Init()
		{
			base.InitBase();
			
			project = new MockCSharpProject();
			context.MockUnitTestsPad.AddProject(project);
			
			string[] methodNames = new string[] { "FirstTest", "SecondTest", "ThirdTest" };
			
			testProject = 
				TestProjectHelper.CreateTestProjectWithTestClassTestMethods(project,
					"MyTests.MyTestClass",
					methodNames);
			
			TestClass testClass = testProject.TestClasses[0];
			firstTestMethod = testClass.TestMethods[0];
			secondTestMethod = testClass.TestMethods[1];
			thirdTestMethod = testClass.TestMethods[2];
			
			context.MockUnitTestsPad.AddTestProject(testProject);
			
			MockBuildProjectBeforeTestRun buildProjectBeforeTestRun = new MockBuildProjectBeforeTestRun();
			context.MockBuildProjectFactory.AddBuildProjectBeforeTestRun(buildProjectBeforeTestRun);
			
			context.UnitTestingOptions.NoThread = true;
			context.UnitTestingOptions.NoShadow = true;
			context.UnitTestingOptions.NoLogo = true;
			context.UnitTestingOptions.NoDots = true;
			context.UnitTestingOptions.Labels = true;
			context.UnitTestingOptions.CreateXmlOutputFile = true;
			
			testFramework = new MockTestFramework();
			context.MockRegisteredTestFrameworks.AddTestFrameworkForProject(project, testFramework);
			
			runTestCommand.Run();
			
			buildProjectBeforeTestRun.FireBuildCompleteEvent();
			
			errorTestResult = new TestResult("MyTests.MyTestClass.FirstTest");
			errorTestResult.ResultType = TestResultType.Failure;
			
			warningTestResult = new TestResult("MyTests.MyTestClass.SecondTest");
			warningTestResult.ResultType = TestResultType.Ignored;
			
			successTestResult = new TestResult("MyTests.MyTestClass.ThirdTest");
			successTestResult.ResultType = TestResultType.Success;
			
			context.MockUnitTestWorkbench.MakeSafeThreadAsyncMethodCallsWithArguments = true;
			MockTestRunner testRunner = runTestCommand.TestRunnersCreated[0];
			testRunner.FireTestFinishedEvent(errorTestResult);
			testRunner.FireTestFinishedEvent(warningTestResult);
			testRunner.FireTestFinishedEvent(successTestResult);
			
			context.MockUnitTestsPad.IsUpdateToolbarMethodCalled = false;
			runningTestsBeforeTestsFinishedCalled = AbstractRunTestCommand.IsRunningTest;
			runTestCommand.CallTestsCompleted();
		}
		public void Init()
		{
			testProject = 
				TestProjectHelper.CreateTestProjectWithTestClassAndSingleTestMethod("MyNamespace.MyClass", "MyTestMethod");
			
			if (testProject.TestClasses.Count > 0) {
				testClass = testProject.TestClasses[0];
				if (testClass.TestMethods.Count > 0) {
					testMethod = testClass.TestMethods[0];
				}
			}	
		}
		public void Init()
		{
			testMethodsResultChanged = false;
			testMethods = new TestMethodCollection();
			
			// TestMethod1.
			MockMethod mockMethod = new MockMethod("TestMethod1");
			testMethod1 = new TestMethod(mockMethod);
			testMethods.Add(testMethod1);
			
			// TestMethod2.
			mockMethod = new MockMethod("TestMethod2");
			testMethod2 = new TestMethod(mockMethod);
			testMethods.Add(testMethod2);
		
			// TestMethod3.
			mockMethod = new MockMethod("TestMethod3");
			testMethod3 = new TestMethod(mockMethod);
			testMethods.Add(testMethod3);
			
			testMethods.ResultChanged += TestMethodsResultChanged;
		}
		public void Init()
		{
			testMethodsResultChanged = false;
			testMethods = new TestMethodCollection();
			
			// TestMethod1.
			MockClass c = MockClass.CreateMockClassWithoutAnyAttributes();
			MockMethod mockMethod = new MockMethod(c, "TestMethod1");
			testMethod1 = new TestMethod(mockMethod);
			testMethods.Add(testMethod1);
			
			// TestMethod2.
			mockMethod = new MockMethod(c, "TestMethod2");
			testMethod2 = new TestMethod(mockMethod);
			testMethods.Add(testMethod2);
		
			// TestMethod3.
			mockMethod = new MockMethod(c, "TestMethod3");
			testMethod3 = new TestMethod(mockMethod);
			testMethods.Add(testMethod3);
			
			testMethods.ResultChanged += TestMethodsResultChanged;
		}
예제 #8
0
		public static TestProject CreateTestProjectWithTestClassTestMethods(IProject project, string className, string[] methodNames)
		{
			MockRegisteredTestFrameworks testFrameworks = new MockRegisteredTestFrameworks();
			MockClass c = MockClass.CreateMockClassWithoutAnyAttributes();
			c.MockProjectContent.Project = project;
			c.SetDotNetName(className);
			c.CompilationUnit.FileName = @"c:\projects\tests\MyTests.cs";
			TestClass testClass = new TestClass(c, testFrameworks);
			
			foreach (string methodName in methodNames) {
				MockMethod method = new MockMethod(c, methodName);
				method.Region = new DomRegion(4, 20);
				c.Methods.Add(method);
				
				TestMethod testMethod = new TestMethod(method);
				testClass.TestMethods.Add(testMethod);
			}
			
			c.Project.Name = "TestProject";
			TestProject testProject = new TestProject(c.Project, c.ProjectContent, testFrameworks);
			testProject.TestClasses.Add(testClass);
			
			return testProject;
		}
		public void AddTestFailureAfterAllTestsPassed()
		{
			AllTestMethodsPass();
			
			MockMethod mockMethod = new MockMethod("TestMethod4");
			TestMethod testMethod4 = new TestMethod(mockMethod);
			testMethod4.Result = TestResultType.Failure;
			testMethods.Add(testMethod4);

			Assert.AreEqual(TestResultType.Failure, testMethods.Result);
		}
		public void RemoveClass()
		{
			// Locate the class we are going to remove.
			TestProjectTreeNode projectNode = (TestProjectTreeNode)rootNode;
			TestClassTreeNode testClassNode = (TestClassTreeNode)projectNode.Nodes[0];
			testClassNode.Expanding();
			TestClass testClass = projectNode.TestProject.TestClasses["MyTestFixture"];
			projectNode.TestProject.TestClasses.Remove(testClass);
			
			ExtTreeNode testClassNodeAfterRemove = null;
			foreach (ExtTreeNode node in rootNode.Nodes) {
				if (node.Text == "MyTestFixture") {
					testClassNodeAfterRemove = node;
					break;
				}
			}
		
			Assert.IsNull(testClassNodeAfterRemove);
			Assert.AreEqual(0, projectNode.Nodes.Count);
			Assert.IsTrue(testClassNode.IsDisposed);
			
			// Make sure the TestClassTreeNode.Dispose removes all event
			// handlers.
			// It uses the events: 
			// TestClass.ResultChanged
			// TestClassCollection.TestMethodAdded
			// TestClassCollection.TestMethodRemoved
	
			// Make sure the test class result is not a failure already.
			testClass.Result = TestResultType.None;		
			testClass.Result = TestResultType.Failure;
			Assert.AreEqual(TestTreeViewImageListIndex.TestNotRun, 
				(TestTreeViewImageListIndex)testClassNode.ImageIndex,
				"Disposed TestClassTreeNode affected by test class result change.");
		
			// Add a new test method to the test class 
			// and make sure the disposed class node does
			// not add a new child node.
			Assert.AreEqual(0, testClassNode.Nodes.Count);
			MockMethod mockMethod = new MockMethod("Method");
			TestMethod testMethod = new TestMethod(mockMethod);
			testClass.TestMethods.Add(testMethod);
			
			Assert.AreEqual(0, testClassNode.Nodes.Count);
		}
예제 #11
0
 public TestMethodEventArgs(TestMethod testMethod)
 {
     this.testMethod = testMethod;
 }
예제 #12
0
        /// <summary>
        /// Adds a new TestMethodTreeNode to this node.
        /// </summary>
        void AddTestMethodTreeNode(TestMethod method)
        {
            TestMethodTreeNode node = new TestMethodTreeNode(TestProject, method);

            node.AddTo(this);
        }
예제 #13
0
		static FileLineReference FindTest(TestMethod testMethod)
		{
			MemberResolveResult resolveResult = new MemberResolveResult(null, null, testMethod.Method);
			FilePosition filePos = resolveResult.GetDefinitionPosition();
			return new FileLineReference(filePos.FileName, filePos.Line - 1, filePos.Column - 1);
		}
		public TestMethodEventArgs(TestMethod testMethod)
		{
			this.testMethod = testMethod;
		}
예제 #15
0
		/// <summary>
		/// Gets the test methods for the specified class.
		/// </summary>
		static TestMethodCollection GetTestMethods(IClass c)
		{
			TestMethodCollection testMethods = new TestMethodCollection();
			foreach (IMethod method in c.Methods) {
				if (TestMethod.IsTestMethod(method)) {
					if (!testMethods.Contains(method.Name)) {
						testMethods.Add(new TestMethod(method));
					}
				}
			}
			
			// Add base class test methods.
			IClass declaringType = c;
			while (c.BaseClass != null) {
				foreach (IMethod method in c.BaseClass.Methods) {
					if (TestMethod.IsTestMethod(method)) {
						BaseTestMethod baseTestMethod = new BaseTestMethod(declaringType, method);
						TestMethod testMethod = new TestMethod(c.BaseClass.Name, baseTestMethod);
						if (method.IsVirtual) {
							if (!testMethods.Contains(method.Name)) {
								testMethods.Add(testMethod);	
							}
						} else {
							if (!testMethods.Contains(testMethod.Name)) {
								testMethods.Add(testMethod);
							}
						}
					}
				}
				c = c.BaseClass;
			}
			return testMethods;
		}
		/// <summary>
		/// Adds a new TestMethodTreeNode to this node.
		/// </summary>
		void AddTestMethodTreeNode(TestMethod method)
		{
			TestMethodTreeNode node = new TestMethodTreeNode(TestProject, method);
			node.AddTo(this);
		}
		public void AddTestFailureAfterAllTestsPassed()
		{
			AllTestMethodsPass();
			
			MockClass c = MockClass.CreateMockClassWithoutAnyAttributes();
			MockMethod mockMethod = new MockMethod(c, "TestMethod4");
			TestMethod testMethod4 = new TestMethod(mockMethod);
			testMethod4.Result = TestResultType.Failure;
			testMethods.Add(testMethod4);

			Assert.AreEqual(TestResultType.Failure, testMethods.Result);
		}