Example #1
0
        public void GetTestFromMethodShouldSetCssProjectStructure()
        {
            this.SetupTestClassAndTestMethods(isValidTestClass: true, isValidTestMethod: true, isMethodFromSameAssembly: true);
            TypeEnumerator typeEnumerator = this.GetTypeEnumeratorInstance(typeof(DummyTestClass), "DummyAssemblyName");
            var            methodInfo     = typeof(DummyTestClass).GetMethod("MethodWithVoidReturnType");

            this.mockReflectHelper.Setup(rh => rh.GetCustomAttribute(methodInfo, typeof(UTF.CssProjectStructureAttribute))).Returns(new UTF.CssProjectStructureAttribute("ProjectStructure123"));

            var testElement = typeEnumerator.GetTestFromMethod(methodInfo, true, this.warnings);

            Assert.AreEqual("ProjectStructure123", testElement.CssProjectStructure);
        }
Example #2
0
        public void GetTestFromMethodShouldSetWorkItemIds()
        {
            this.SetupTestClassAndTestMethods(isValidTestClass: true, isValidTestMethod: true, isMethodFromSameAssembly: true);
            TypeEnumerator typeEnumerator = this.GetTypeEnumeratorInstance(typeof(DummyTestClass), "DummyAssemblyName");
            var            methodInfo     = typeof(DummyTestClass).GetMethod("MethodWithVoidReturnType");

            this.mockReflectHelper.Setup(rh => rh.GetCustomAttributes(methodInfo, typeof(UTF.WorkItemAttribute))).Returns(new Attribute[] { new UTF.WorkItemAttribute(123), new UTF.WorkItemAttribute(345) });

            var testElement = typeEnumerator.GetTestFromMethod(methodInfo, true, this.warnings);

            CollectionAssert.AreEqual(new string[] { "123", "345" }, testElement.WorkItemIds);
        }
Example #3
0
        public void GetTestFromMethodShouldSetWorkItemIdsToNullIfNotAny()
        {
            this.SetupTestClassAndTestMethods(isValidTestClass: true, isValidTestMethod: true, isMethodFromSameAssembly: true);
            TypeEnumerator typeEnumerator = this.GetTypeEnumeratorInstance(typeof(DummyTestClass), "DummyAssemblyName");
            var            methodInfo     = typeof(DummyTestClass).GetMethod("MethodWithVoidReturnType");

            this.mockReflectHelper.Setup(rh => rh.GetCustomAttributes(methodInfo, typeof(UTF.WorkItemAttribute))).Returns(new Attribute[0]);

            var testElement = typeEnumerator.GetTestFromMethod(methodInfo, true, this.warnings);

            Assert.IsNull(testElement.WorkItemIds);
        }
Example #4
0
        public void GetTestFromMethodShouldInitiateTestMethodWithCorrectParameters()
        {
            this.SetupTestClassAndTestMethods(isValidTestClass: true, isValidTestMethod: true, isMethodFromSameAssembly: true);
            TypeEnumerator typeEnumerator = this.GetTypeEnumeratorInstance(typeof(DummyTestClass), "DummyAssemblyName");

            var testElement = typeEnumerator.GetTestFromMethod(typeof(DummyTestClass).GetMethod("MethodWithVoidReturnType"), true, this.warnings);

            Assert.IsNotNull(testElement);
            Assert.AreEqual("MethodWithVoidReturnType", testElement.TestMethod.Name);
            Assert.AreEqual(typeof(DummyTestClass).FullName, testElement.TestMethod.FullClassName);
            Assert.AreEqual("DummyAssemblyName", testElement.TestMethod.AssemblyName);
            Assert.IsFalse(testElement.TestMethod.IsAsync);
        }
Example #5
0
        public void GetTestFromMethodShouldSetPriority()
        {
            this.SetupTestClassAndTestMethods(isValidTestClass: true, isValidTestMethod: true, isMethodFromSameAssembly: true);
            TypeEnumerator typeEnumerator = this.GetTypeEnumeratorInstance(typeof(DummyTestClass), "DummyAssemblyName");
            var            methodInfo     = typeof(DummyTestClass).GetMethod("MethodWithVoidReturnType");

            // Setup mocks
            this.mockReflectHelper.Setup(rh => rh.GetPriority(methodInfo)).Returns(1);

            var testElement = typeEnumerator.GetTestFromMethod(methodInfo, true, this.warnings);

            Assert.IsNotNull(testElement);
            Assert.AreEqual(1, testElement.Priority);
        }
Example #6
0
        public void GetTestFromMethodShouldSetDoNotParallelize()
        {
            this.SetupTestClassAndTestMethods(isValidTestClass: true, isValidTestMethod: true, isMethodFromSameAssembly: true);
            TypeEnumerator typeEnumerator = this.GetTypeEnumeratorInstance(typeof(DummyTestClass), "DummyAssemblyName");
            var            methodInfo     = typeof(DummyTestClass).GetMethod("MethodWithVoidReturnType");

            // Setup mocks
            this.mockReflectHelper.Setup(rh => rh.GetCustomAttributes(It.IsAny <MemberInfo>(), typeof(UTF.DoNotParallelizeAttribute))).Returns(new[] { new UTF.DoNotParallelizeAttribute() });

            var testElement = typeEnumerator.GetTestFromMethod(methodInfo, true, this.warnings);

            Assert.IsNotNull(testElement);
            Assert.IsTrue(testElement.DoNotParallelize);
        }
Example #7
0
        public void GetTestFromMethodShouldSetDisplayNameFromAttribute()
        {
            this.SetupTestClassAndTestMethods(isValidTestClass: true, isValidTestMethod: true, isMethodFromSameAssembly: true);
            TypeEnumerator typeEnumerator = this.GetTypeEnumeratorInstance(typeof(DummyTestClass), "DummyAssemblyName");
            var            methodInfo     = typeof(DummyTestClass).GetMethod(nameof(DummyTestClass.MethodWithVoidReturnType));

            // Setup mocks to behave like we have [TestMethod("Test method display name.")] attribute on the method
            this.mockReflectHelper.Setup(
                rh => rh.GetCustomAttribute(methodInfo, typeof(TestMethodV2))).Returns(new TestMethodV2("Test method display name."));

            var testElement = typeEnumerator.GetTestFromMethod(methodInfo, true, this.warnings);

            Assert.IsNotNull(testElement);
            Assert.AreEqual("Test method display name.", testElement.DisplayName);
        }
Example #8
0
        public void GetTestFromMethodShouldSetTestCategory()
        {
            this.SetupTestClassAndTestMethods(isValidTestClass: true, isValidTestMethod: true, isMethodFromSameAssembly: true);
            TypeEnumerator typeEnumerator = this.GetTypeEnumeratorInstance(typeof(DummyTestClass), "DummyAssemblyName");
            var            methodInfo     = typeof(DummyTestClass).GetMethod("MethodWithVoidReturnType");
            var            testCategories = new string[] { "foo", "bar" };

            // Setup mocks
            this.mockReflectHelper.Setup(rh => rh.GetCategories(methodInfo, typeof(DummyTestClass))).Returns(testCategories);

            var testElement = typeEnumerator.GetTestFromMethod(methodInfo, true, this.warnings);

            Assert.IsNotNull(testElement);
            CollectionAssert.AreEqual(testCategories, testElement.TestCategory);
        }
Example #9
0
        public void GetTestFromMethodShouldInitializeAsyncTypeNameCorrectly()
        {
            this.SetupTestClassAndTestMethods(isValidTestClass: true, isValidTestMethod: true, isMethodFromSameAssembly: true);
            TypeEnumerator typeEnumerator = this.GetTypeEnumeratorInstance(typeof(DummyTestClass), "DummyAssemblyName");
            var            methodInfo     = typeof(DummyTestClass).GetMethod("AsyncMethodWithTaskReturnType");

            var testElement = typeEnumerator.GetTestFromMethod(methodInfo, true, this.warnings);

            var expectedAsyncTaskName =
                (methodInfo.GetCustomAttribute(typeof(AsyncStateMachineAttribute)) as AsyncStateMachineAttribute)
                .StateMachineType.FullName;

            Assert.IsNotNull(testElement);
            Assert.AreEqual(expectedAsyncTaskName, testElement.AsyncTypeName);
        }
Example #10
0
        public void GetTestFromMethodShouldSetDeploymentItemsToNullIfNotPresent()
        {
            this.SetupTestClassAndTestMethods(isValidTestClass: true, isValidTestMethod: true, isMethodFromSameAssembly: true);
            TypeEnumerator typeEnumerator = this.GetTypeEnumeratorInstance(typeof(DummyTestClass), "DummyAssemblyName");
            var            methodInfo     = typeof(DummyTestClass).GetMethod("MethodWithVoidReturnType");

            // Setup mocks
            this.testablePlatformServiceProvider.MockTestDeployment.Setup(
                td => td.GetDeploymentItems(It.IsAny <MethodInfo>(), It.IsAny <Type>(), this.warnings))
            .Returns((KeyValuePair <string, string>[])null);

            var testElement = typeEnumerator.GetTestFromMethod(methodInfo, true, this.warnings);

            Assert.IsNotNull(testElement);
            Assert.IsNull(testElement.DeploymentItems);
        }
Example #11
0
        public void GetTestFromMethodShouldSetDeploymentItems()
        {
            this.SetupTestClassAndTestMethods(isValidTestClass: true, isValidTestMethod: true, isMethodFromSameAssembly: true);
            TypeEnumerator typeEnumerator  = this.GetTypeEnumeratorInstance(typeof(DummyTestClass), "DummyAssemblyName");
            var            methodInfo      = typeof(DummyTestClass).GetMethod("MethodWithVoidReturnType");
            var            deploymentItems = new[] { new KeyValuePair <string, string>("C:\\temp", string.Empty) };

            // Setup mocks
            this.testablePlatformServiceProvider.MockTestDeployment.Setup(
                td => td.GetDeploymentItems(methodInfo, typeof(DummyTestClass), this.warnings)).Returns(deploymentItems);

            var testElement = typeEnumerator.GetTestFromMethod(methodInfo, true, this.warnings);

            Assert.IsNotNull(testElement);
            Assert.IsNotNull(testElement.DeploymentItems);
            CollectionAssert.AreEqual(deploymentItems, testElement.DeploymentItems.ToArray());
        }
Example #12
0
        public void GetTestFromMethodShouldFillTraitsWithTestProperties()
        {
            this.SetupTestClassAndTestMethods(isValidTestClass: true, isValidTestMethod: true, isMethodFromSameAssembly: true);
            TypeEnumerator typeEnumerator = this.GetTypeEnumeratorInstance(typeof(DummyTestClass), "DummyAssemblyName");
            var            methodInfo     = typeof(DummyTestClass).GetMethod("MethodWithVoidReturnType");
            var            testProperties = new List <Trait> {
                new Trait("foo", "bar"), new Trait("fooprime", "barprime")
            };

            // Setup mocks
            this.mockReflectHelper.Setup(rh => rh.GetTestPropertiesAsTraits(methodInfo)).Returns(testProperties);

            var testElement = typeEnumerator.GetTestFromMethod(methodInfo, true, this.warnings);

            Assert.IsNotNull(testElement);
            CollectionAssert.AreEqual(testProperties, testElement.Traits);
        }
Example #13
0
        public void GetTestFromMethodShouldSetIgnoredPropertyToFalseIfNotSetOnTestClassAndTestMethod()
        {
            this.SetupTestClassAndTestMethods(isValidTestClass: true, isValidTestMethod: true, isMethodFromSameAssembly: true);
            TypeEnumerator typeEnumerator = this.GetTypeEnumeratorInstance(typeof(DummyTestClass), "DummyAssemblyName");
            var            methodInfo     = typeof(DummyTestClass).GetMethod("MethodWithVoidReturnType");

            // Setup mocks
            this.mockReflectHelper.Setup(
                rh => rh.IsAttributeDefined(typeof(DummyTestClass), typeof(UTF.IgnoreAttribute), false)).Returns(false);
            this.mockReflectHelper.Setup(
                rh => rh.IsAttributeDefined(methodInfo, typeof(UTF.IgnoreAttribute), false)).Returns(false);

            var testElement = typeEnumerator.GetTestFromMethod(methodInfo, true, this.warnings);

            Assert.IsNotNull(testElement);
            Assert.IsFalse(testElement.Ignored);
        }
Example #14
0
        public void GetTestFromMethodShouldSetDeclaringAssemblyName()
        {
            const bool isMethodFromSameAssemly = false;

            TypeEnumerator typeEnumerator = this.GetTypeEnumeratorInstance(typeof(DummyTestClass), "DummyAssemblyName");
            var            methodInfo     = typeof(DummyTestClass).GetMethod("MethodWithVoidReturnType");

            // Setup mocks
            string otherAssemblyName = "ADifferentAssembly";

            this.testablePlatformServiceProvider.MockFileOperations.Setup(fo => fo.GetAssemblyPath(It.IsAny <Assembly>()))
            .Returns(otherAssemblyName);

            var testElement = typeEnumerator.GetTestFromMethod(methodInfo, isMethodFromSameAssemly, this.warnings);

            Assert.IsNotNull(testElement);
            Assert.AreEqual(otherAssemblyName, testElement.TestMethod.DeclaringAssemblyName);
        }