Ejemplo n.º 1
0
        private static string TestCommand(TestCommandRequest request, string assemblyName, string typeName, string methodName)
        {
            var    testCommands = ConfigurationLoader.Config.TestCommands;
            string testCommand  = testCommands.All;

            switch (request.Type)
            {
            case TestCommandRequest.TestCommandType.All:
                testCommand = testCommands.All;
                break;

            case TestCommandRequest.TestCommandType.Fixture:
                testCommand = testCommands.Fixture;
                break;

            case TestCommandRequest.TestCommandType.Single:
                testCommand = testCommands.Single;
                break;
            }

            testCommand = testCommand.Replace("{{AssemblyPath}}", assemblyName)
                          .Replace("{{TypeName}}", typeName)
                          .Replace("{{MethodName}}", methodName);

            return(testCommand);
        }
Ejemplo n.º 2
0
        public GetTestContextResponse GetTestContextResponse(TestCommandRequest request)
        {
            var contextInfo = GetContextResponse(request);
            var testCommand = TestCommand(request, contextInfo.AssemblyName, contextInfo.TypeName, contextInfo.MethodName);

            return(new GetTestContextResponse
            {
                TestCommand = testCommand
            });
        }
        public GetTestContextResponse GetTestContextResponse(TestCommandRequest request)
        {

            var contextInfo = GetContextResponse(request);
            var testCommand = TestCommand(request, contextInfo.AssemblyName, contextInfo.TypeName, contextInfo.MethodName);

            return new GetTestContextResponse
                {
                    TestCommand = testCommand
                };
        }
Ejemplo n.º 4
0
        public GetContextResponse GetContextResponse(TestCommandRequest request)
        {
            string methodName = null;

            var bufferContext = new BufferContext(request, _parser);
            var node          = bufferContext.NodeCurrentlyUnderCursor;

            TypeDeclaration      type = null;
            NamespaceDeclaration namespaceDeclaration = null;

            if (node != null)
            {
                var method = (MethodDeclaration)node.AncestorsAndSelf.FirstOrDefault(n => n is MethodDeclaration);
                if (method != null)
                {
                    methodName = method.Name;
                }
                type = (TypeDeclaration)node.AncestorsAndSelf.FirstOrDefault(n => n is TypeDeclaration);
                namespaceDeclaration = (NamespaceDeclaration)node.AncestorsAndSelf.FirstOrDefault(n => n is NamespaceDeclaration);
            }

            if (type == null)
            {
                var tree = bufferContext.ParsedContent.SyntaxTree;
                type = (TypeDeclaration)tree.DescendantsAndSelf.FirstOrDefault(n => n is TypeDeclaration);
                namespaceDeclaration = (NamespaceDeclaration)tree.DescendantsAndSelf.FirstOrDefault(n => n is NamespaceDeclaration);
            }

            string typeName = type.Name;

            if (namespaceDeclaration != null)
            {
                typeName = namespaceDeclaration.FullName + "." + typeName;
            }

            var project   = _solution.ProjectContainingFile(request.FileName);
            var directory = new FileInfo(project.FileName).Directory.FullName;

            var assemblyName = "\"" +
                               Path.Combine(directory, "bin", "Debug", project.ProjectContent.FullAssemblyName + ".dll")
                               + "\"";

            return(new GetContextResponse
            {
                AssemblyName = assemblyName,
                TypeName = typeName,
                MethodName = methodName
            });
        }
        public GetContextResponse GetContextResponse(TestCommandRequest request)
        {
            string methodName = null;

            var bufferContext = new BufferContext(request, _parser);
			var node = bufferContext.NodeCurrentlyUnderCursor;

            TypeDeclaration type = null;
			NamespaceDeclaration namespaceDeclaration = null;
			if(node != null)
			{
				var method = (MethodDeclaration) node.AncestorsAndSelf.FirstOrDefault(n => n is MethodDeclaration);
				if (method != null)
					methodName = method.Name;
				type = (TypeDeclaration)node.AncestorsAndSelf.FirstOrDefault(n => n is TypeDeclaration);
				namespaceDeclaration = (NamespaceDeclaration)node.AncestorsAndSelf.FirstOrDefault(n => n is NamespaceDeclaration);
			}

            if (type == null)
			{
				var tree = bufferContext.ParsedContent.SyntaxTree;
				type = (TypeDeclaration)tree.DescendantsAndSelf.FirstOrDefault(n => n is TypeDeclaration);
				namespaceDeclaration = (NamespaceDeclaration)tree.DescendantsAndSelf.FirstOrDefault(n => n is NamespaceDeclaration);
			}

			string typeName = type.Name;

            if (namespaceDeclaration != null)
                typeName = namespaceDeclaration.FullName + "." + typeName;

            var project = _solution.ProjectContainingFile(request.FileName);
            var directory = new FileInfo(project.FileName).Directory.FullName;

            var assemblyName = "\"" +
                               Path.Combine(directory, "bin", "Debug", project.ProjectContent.FullAssemblyName + ".dll")
                               + "\"";

            return new GetContextResponse
            {
                AssemblyName = assemblyName,
                TypeName = typeName,
                MethodName = methodName
            };

        }
Ejemplo n.º 6
0
        public static GetContextResponse GetContextInformation(this string editorText)
        {
            var cursorPosition = TestHelpers.GetLineAndColumnFromDollar(editorText);
            editorText = editorText.Replace("$", "");

            var solution = new FakeSolution();
            var project = new FakeProject();
            project.AddFile(editorText);
            solution.Projects.Add(project);

            var handler = new GetTestContextHandler(solution, new BufferParser(solution));
            var request = new TestCommandRequest
            {
                Buffer = editorText,
                FileName = "myfile",
                Line = cursorPosition.Line,
                Column = cursorPosition.Column,
            };

            return handler.GetContextResponse(request);
        }
        private static string TestCommand(TestCommandRequest request, string assemblyName, string typeName, string methodName)
        {
            var testCommands = ConfigurationLoader.Config.TestCommands;
            string testCommand = testCommands.All;
            switch (request.Type)
            {
                case TestCommandRequest.TestCommandType.All:
                    testCommand = testCommands.All;
                    break;
                case TestCommandRequest.TestCommandType.Fixture:
                    testCommand = testCommands.Fixture;
                    break;
                case TestCommandRequest.TestCommandType.Single:
                    testCommand = testCommands.Single;
                    break;
            }

            testCommand = testCommand.Replace("{{AssemblyPath}}", assemblyName)
                .Replace("{{TypeName}}", typeName)
                .Replace("{{MethodName}}", methodName);
            
            return testCommand;
        }