예제 #1
0
        private static void AddDeploymentItem(IAttributeInfo attributeInfo, MSTest test)
        {
            string path = GetAttributePropertyValue(attributeInfo, "Path");
            string outputDirectory = GetAttributePropertyValue(attributeInfo, "OutputDirectory");

            if (string.IsNullOrEmpty(path) || string.IsNullOrEmpty(outputDirectory))
                return;

            test.Metadata.Add(MSTestMetadataKeys.DeploymentItem, "Path=\"" + path + "\", OutputDirectory=\"" + outputDirectory + "\"");
            test.AddDeploymentItem(new MSTestDeploymentItem(path, outputDirectory));
        }
예제 #2
0
 private static void AddTestProperty(IAttributeInfo attributeInfo, MSTest methodTest)
 {
     string name = GetAttributePropertyValue(attributeInfo, "Name");
     string value = GetAttributePropertyValue(attributeInfo, "Value");
     methodTest.Metadata.Add(name, value);
 }
예제 #3
0
 private static void PopulateTestMethodMetadata(IMethodInfo methodInfo, MSTest methodTest)
 {
     IEnumerable<IAttributeInfo> attributes = methodInfo.GetAttributeInfos(null, true);
     foreach (IAttributeInfo attribute in attributes)
     {
         switch (attribute.Type.FullName)
         {
             case MSTestAttributes.AspNetDevelopmentServerAttribute:
                 methodTest.Metadata.Add(MSTestMetadataKeys.AspNetDevelopmentServer, GetAspNetDevelopmentServer(attribute));
                 break;
             case MSTestAttributes.AspNetDevelopmentServerHostAttribute:
                 methodTest.Metadata.Add(MSTestMetadataKeys.AspNetDevelopmentServerHost, GetAspNetDevelopmentServerHost(attribute));
                 break;
             case MSTestAttributes.CredentialAttribute:
                 methodTest.Metadata.Add(MSTestMetadataKeys.Credential, GetCredential(attribute));
                 break;
             case MSTestAttributes.CssIterationAttribute:
                 methodTest.Metadata.Add(MSTestMetadataKeys.CssIteration, GetAttributePropertyValue(attribute, MSTestMetadataKeys.CssIteration));
                 break;
             case MSTestAttributes.CssProjectStructureAttribute:
                 methodTest.Metadata.Add(MSTestMetadataKeys.CssProjectStructure, GetAttributePropertyValue(attribute, MSTestMetadataKeys.CssProjectStructure));
                 break;
             case MSTestAttributes.DeploymentItemAttribute:
                 AddDeploymentItem(attribute, methodTest);
                 break;
             case MSTestAttributes.DataSourceAttribute:
                 methodTest.Metadata.Add(MSTestMetadataKeys.DataSource, GetDatasource(attribute));
                 break;
             case MSTestAttributes.DescriptionAttribute:
                 methodTest.Metadata.Add(MetadataKeys.Description, GetAttributePropertyValue(attribute, MetadataKeys.Description));
                 break;
             case MSTestAttributes.HostTypeAttribute:
                 methodTest.Metadata.Add(MSTestMetadataKeys.HostType, GetHostType(attribute));
                 break;
             case MSTestAttributes.IgnoreAttribute:
                 methodTest.Metadata.Add(MetadataKeys.IgnoreReason, Resources.MSTestExplorer_IgnoreAttributeWasAppliedToTest);
                 break;
             case MSTestAttributes.OwnerAttribute:
                 methodTest.Metadata.Add(MSTestMetadataKeys.Owner, GetAttributePropertyValue(attribute, MSTestMetadataKeys.Owner));
                 break;
             case MSTestAttributes.PriorityAttribute:
                 methodTest.Metadata.Add(MSTestMetadataKeys.Priority, GetAttributePropertyValue(attribute, MSTestMetadataKeys.Priority));
                 break;
             case MSTestAttributes.TestPropertyAttribute:
                 AddTestProperty(attribute, methodTest);
                 break;
             case MSTestAttributes.TimeoutAttribute:
                 methodTest.Metadata.Add(MSTestMetadataKeys.Timeout, GetAttributePropertyValue(attribute, MSTestMetadataKeys.Timeout));
                 break;
             case MSTestAttributes.UrlToTestAttribute:
                 methodTest.Metadata.Add(MSTestMetadataKeys.UrlToTest, GetAttributePropertyValue(attribute, MSTestMetadataKeys.UrlToTest));
                 break;
             case MSTestAttributes.WorkItemAttribute:
                 methodTest.Metadata.Add(MSTestMetadataKeys.WorkItem, GetAttributePropertyValue(attribute, "Id"));
                 break;
             default:
                 break;
         }
     }
 }
예제 #4
0
        private static MSTest CreateMethodTest(ITypeInfo typeInfo, IMethodInfo methodInfo)
        {
            MSTest methodTest = new MSTest(methodInfo.Name, methodInfo);
            methodTest.Kind = TestKinds.Test;
            methodTest.IsTestCase = true;

            PopulateTestMethodMetadata(methodInfo, methodTest);

            // Add XML documentation.
            string xmlDocumentation = methodInfo.GetXmlDocumentation();
            if (xmlDocumentation != null)
                methodTest.Metadata.SetValue(MetadataKeys.XmlDocumentation, xmlDocumentation);

            return methodTest;
        }
예제 #5
0
 private static void PopulateTestClassMetadata(ITypeInfo typeInfo, MSTest typeTest)
 {
     IEnumerable<IAttributeInfo> attributes = typeInfo.GetAttributeInfos(null, true);
     foreach (IAttributeInfo attribute in attributes)
     {
         switch (attribute.Type.FullName)
         {
             case MSTestAttributes.DeploymentItemAttribute:
                 AddDeploymentItem(attribute, typeTest);
                 break;
             case MSTestAttributes.IgnoreAttribute:
                 typeTest.Metadata.Add(MetadataKeys.IgnoreReason, Resources.MSTestExplorer_IgnoreAttributeWasAppliedToClass);
                 break;
             default:
                 break;
         }
     }
 }
예제 #6
0
        private MSTest CreateTypeTest(ITypeInfo typeInfo)
        {
            MSTest typeTest = new MSTest(typeInfo.Name, typeInfo);
            typeTest.Kind = TestKinds.Fixture;

            foreach (IMethodInfo method in typeInfo.GetMethods(BindingFlags.Public | BindingFlags.Instance))
            {
                IEnumerable<IAttributeInfo> methodAttributes = method.GetAttributeInfos(null, true);
                foreach (IAttributeInfo methodAttribute in methodAttributes)
                {
                    if (methodAttribute.Type.FullName.CompareTo(MSTestAttributes.TestMethodAttribute) == 0)
                    {
                        try
                        {
                            MSTest testMethod = CreateMethodTest(typeInfo, method);
                            typeTest.AddChild(testMethod);
                        }
                        catch (Exception ex)
                        {
                            TestModel.AddAnnotation(new Annotation(AnnotationType.Error, method, "An exception was thrown while exploring an MSTest test method.", ex));
                        }
                        break;
                    }
                }
            }

            PopulateTestClassMetadata(typeInfo, typeTest);

            // Add XML documentation.
            string xmlDocumentation = typeInfo.GetXmlDocumentation();
            if (xmlDocumentation != null)
                typeTest.Metadata.SetValue(MetadataKeys.XmlDocumentation, xmlDocumentation);

            return typeTest;
        }
예제 #7
0
            private TestStepState GetOrCreateTestStepStateByTest(MSTest test)
            {
                TestStepState testStepState = GetTestStepStateByTest(test);
                if (testStepState == null)
                {
                    TestStepState parentTestStepState = GetOrCreateTestStepStateByTest((MSTest) test.Parent);
                    Guid testId = test.Guid;
                    ITestCommand testCommand = GetTestCommandByTestId(testId);

                    TestStep testStep = new TestStep(test, parentTestStepState.TestContext.TestStep,
                        test.Name, test.CodeElement, true);
                    if (test.IsDataDriven)
                        testStep.IsTestCase = false;

                    ITestContext testContext = SafeStartCommandStep(parentTestStepState.TestContext, testCommand, testStep);
                    testStepState = new TestStepState(parentTestStepState, testContext);

                    testStepStatesByTest.Add(test, testStepState);
                    testsExecuted.Add(test);
                }

                return testStepState;
            }