public void GetTestCategoryAttributeShouldIncludeTestCategoriesAtMethodLevel() { this.reflectHelper.SetCustomAttribute(typeof(UTF.TestCategoryBaseAttribute), new[] { new UTF.TestCategoryAttribute("MethodLevel") }, MemberTypes.Method); string[] expected = new[] { "MethodLevel" }; var actual = this.reflectHelper.GetCategories(this.method.Object, typeof(ReflectHelperTests)).ToArray(); CollectionAssert.AreEqual(expected, actual); }
public void GetTestCategoryAttributeShouldIncludeMultipleTestCategoriesAtClassLevel() { this.reflectHelper.SetCustomAttribute(typeof(UTF.TestCategoryBaseAttribute), new[] { new UTF.TestCategoryAttribute("ClassLevel"), new UTF.TestCategoryAttribute("ClassLevel1") }, MemberTypes.TypeInfo); string[] expected = new[] { "ClassLevel", "ClassLevel1" }; var actual = this.reflectHelper.GetCategories(this.method.Object).ToArray(); CollectionAssert.AreEqual(expected, actual); }
public void AddPropertyShouldAddPropertiesToThePropertyBag() { this.testContextImplementation = new TestContextImplementation(this.testMethod.Object, new ThreadSafeStringWriter(null, "test"), this.properties); this.testContextImplementation.AddProperty("SomeNewProperty", "SomeValue"); CollectionAssert.Contains( this.testContextImplementation.Properties, new KeyValuePair <string, object>("SomeNewProperty", "SomeValue")); }
public void AddResultFileShouldAddFiletoResultsFiles() { this.testContextImplementation = new TestContextImplementation(this.testMethod.Object, new System.IO.StringWriter(), this.properties); this.testContextImplementation.AddResultFile("C:\\temp.txt"); var resultsFiles = this.testContextImplementation.GetResultFiles(); CollectionAssert.Contains(resultsFiles.ToList(), "C:\\temp.txt"); }
public void AddPropertyShouldAddPropertiesToThePropertyBag() { this.testContextImplementation = new TestContextImplementation(this.testMethod.Object, new System.IO.StringWriter(), this.properties); this.testContextImplementation.AddProperty("SomeNewProperty", "SomeValue"); CollectionAssert.Contains( this.testContextImplementation.Properties.ToList(), new KeyValuePair <string, object>("SomeNewProperty", "SomeValue")); }
public void AddFilesInADirectoryShouldReturnAllTopLevelFilesInADirectory() { var topLevelFiles = new string[] { "tick.txt", "tock.tick.txt" }; this.fileUtility.Setup(fu => fu.GetFilesInADirectory(It.IsAny <string>())).Returns(topLevelFiles); this.fileUtility.Setup(fu => fu.GetDirectoriesInADirectory(It.IsAny <string>())).Returns(new string[] { }); var files = this.fileUtility.Object.AddFilesFromDirectory("C:\\randomclock", false); CollectionAssert.AreEqual(topLevelFiles, files); }
public void IsValidTestMethodShouldReportWarningsForGenericTestMethodDefinitions() { this.SetupTestMethod(); this.mockMethodInfo.Setup(mi => mi.IsGenericMethodDefinition).Returns(true); this.mockMethodInfo.Setup(mi => mi.DeclaringType.FullName).Returns("DummyTestClass"); this.mockMethodInfo.Setup(mi => mi.Name).Returns("DummyTestMethod"); this.testMethodValidator.IsValidTestMethod(this.mockMethodInfo.Object, this.type, this.warnings); Assert.AreEqual(1, this.warnings.Count); CollectionAssert.Contains(this.warnings, string.Format(CultureInfo.CurrentCulture, Resource.UTA_ErrorGenericTestMethod, "DummyTestClass", "DummyTestMethod")); }
public void RunTestsForSourceShouldRunTestsInASource() { var sources = new List <string> { Assembly.GetExecutingAssembly().Location }; this.TestExecutionManager.RunTests(sources, this.runContext, this.frameworkHandle, this.cancellationToken); CollectionAssert.Contains(this.frameworkHandle.TestCaseStartList, "PassingTest"); CollectionAssert.Contains(this.frameworkHandle.TestCaseEndList, "PassingTest:Passed"); CollectionAssert.Contains(this.frameworkHandle.ResultsList, "PassingTest Passed"); }
public void AddResultFileShouldAddMultipleFilestoResultsFiles() { this.testContextImplementation = new TestContextImplementation(this.testMethod.Object, new ThreadSafeStringWriter(null, "test"), this.properties); this.testContextImplementation.AddResultFile("C:\\temp.txt"); this.testContextImplementation.AddResultFile("C:\\temp2.txt"); var resultsFiles = this.testContextImplementation.GetResultFiles(); CollectionAssert.Contains(resultsFiles.ToList(), "C:\\temp.txt"); CollectionAssert.Contains(resultsFiles.ToList(), "C:\\temp2.txt"); }
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); }
public void GetCustomAttributesShouldReturnAllAttributesIgnoringBaseInheritance() { var minfo = this.testAsset.GetType("TestProjectForDiscovery.AttributeTestClass").GetMethod("DummyVTestMethod1"); var attribs = this.reflectionUtility.GetCustomAttributes(minfo, false); Assert.IsNotNull(attribs); Assert.AreEqual(2, attribs.Length); var expectedAttribs = new string[] { "TestCategory : derived", "Owner : derived" }; CollectionAssert.AreEqual(expectedAttribs, this.GetAttributeValuePairs(attribs)); }
public void GetSpecificCustomAttributesOnAssemblyShouldReturnAllAttributes() { var asm = this.testAsset.GetType("TestProjectForDiscovery.AttributeTestClass").Assembly; var attribs = this.reflectionUtility.GetCustomAttributes(asm, typeof(TestCategoryV2)); Assert.IsNotNull(attribs); Assert.AreEqual(2, attribs.Length); var expectedAttribs = new string[] { "TestCategory : a1", "TestCategory : a2" }; CollectionAssert.AreEqual(expectedAttribs, this.GetAttributeValuePairs(attribs)); }
public void GetSpecificCustomAttributesOnTypeShouldReturnAllAttributesWithBaseInheritance() { var minfo = this.testAsset.GetType("TestProjectForDiscovery.AttributeTestClass").GetTypeInfo(); var attribs = this.reflectionUtility.GetCustomAttributes(minfo, typeof(TestCategoryV2), true); Assert.IsNotNull(attribs); Assert.AreEqual(2, attribs.Length); var expectedAttribs = new string[] { "TestCategory : a", "TestCategory : ba" }; CollectionAssert.AreEqual(expectedAttribs, this.GetAttributeValuePairs(attribs)); }
public void GetSpecificCustomAttributesShouldReturnArrayAttributesAsWell() { var minfo = this.testAsset.GetType("TestProjectForDiscovery.AttributeTestClassWithCustomAttributes").GetMethod("DummyTestMethod2"); var attribs = this.reflectionUtility.GetCustomAttributes(minfo, typeof(CategoryArrayAttribute), true); Assert.IsNotNull(attribs); Assert.AreEqual(1, attribs.Length); var expectedAttribs = new string[] { "CategoryAttribute : foo,foo2" }; CollectionAssert.AreEqual(expectedAttribs, this.GetAttributeValuePairs(attribs)); }
public void GetSpecificCustomAttributesShouldReturnAllAttributesIncludingUserDefinedAttributes() { var minfo = this.testAsset.GetType("TestProjectForDiscovery.AttributeTestClassWithCustomAttributes").GetMethod("DummyVTestMethod1"); var attribs = this.reflectionUtility.GetCustomAttributes(minfo, typeof(TestPropertyV2), true); Assert.IsNotNull(attribs); Assert.AreEqual(1, attribs.Length); var expectedAttribs = new string[] { "Duration : superfast" }; CollectionAssert.AreEqual(expectedAttribs, this.GetAttributeValuePairs(attribs)); }
public void GetSpecificCustomAttributesShouldReturnAllAttributesWithBaseInheritance() { var minfo = typeof(DummyTestClass).GetMethod("DummyVTestMethod1"); var attribs = this.reflectionOperations.GetCustomAttributes(minfo, typeof(DummyAAttribute), true); Assert.IsNotNull(attribs); Assert.AreEqual(2, attribs.Length); var expectedAttribs = new string[] { "DummyA : derived", "DummyA : base", }; CollectionAssert.AreEqual(expectedAttribs, this.GetAttributeValuePairs(attribs)); }
public void GetSpecificCustomAttributesOnTypeShouldReturnAllAttributes() { var tinfo = typeof(DummyBaseTestClass).GetTypeInfo(); var attribs = this.reflectionOperations.GetCustomAttributes(tinfo, typeof(DummyAAttribute), false); Assert.IsNotNull(attribs); Assert.AreEqual(1, attribs.Length); var expectedAttribs = new string[] { "DummyA : ba" }; CollectionAssert.AreEqual(expectedAttribs, this.GetAttributeValuePairs(attribs)); }
public void PropertiesShouldReturnPropertiesPassedToTestContext() { var property1 = new KeyValuePair <string, object>("IntProperty", 1); var property2 = new KeyValuePair <string, object>("DoubleProperty", 2.023); this.properties.Add(property1); this.properties.Add(property2); this.testContextImplementation = new TestContextImplementation(this.testMethod.Object, new System.IO.StringWriter(), this.properties); CollectionAssert.Contains(this.testContextImplementation.Properties, property1); CollectionAssert.Contains(this.testContextImplementation.Properties, property2); }
public void GetCustomAttributesOnTypeShouldReturnAllAttributesIgnoringBaseInheritance() { var tinfo = this.testAsset.GetType("TestProjectForDiscovery.AttributeTestClass").GetTypeInfo(); var attribs = this.reflectionUtility.GetCustomAttributes(tinfo, false); Assert.IsNotNull(attribs); Assert.AreEqual(1, attribs.Length); var expectedAttribs = new string[] { "TestCategory : a" }; CollectionAssert.AreEqual(expectedAttribs, this.GetAttributeValuePairs(attribs)); }
public void GetTypesShouldReturnReflectionTypeLoadExceptionTypesOnException() { Mock <TestableAssembly> mockAssembly = new Mock <TestableAssembly>(); var reflectedTypes = new Type[] { typeof(DummyTestClass) }; // Setup mocks mockAssembly.Setup(a => a.DefinedTypes).Throws(new ReflectionTypeLoadException(reflectedTypes, null)); var types = this.assemblyEnumerator.GetTypes(mockAssembly.Object, string.Empty, this.warnings); Assert.IsNotNull(types); CollectionAssert.AreEqual(reflectedTypes, types); }
public void GetSpecificCustomAttributesOnAssemblyShouldReturnAllAttributes() { var asm = typeof(DummyTestClass).GetTypeInfo().Assembly; var attribs = this.reflectionUtility.GetCustomAttributes(asm, typeof(DummyAAttribute)); Assert.IsNotNull(attribs); Assert.AreEqual(2, attribs.Length); var expectedAttribs = new string[] { "DummyA : a1", "DummyA : a2" }; CollectionAssert.AreEqual(expectedAttribs, GetAttributeValuePairs(attribs)); }
public void GetCustomAttributesShouldReturnAllAttributesIgnoringBaseInheritance() { var minfo = typeof(DummyTestClass).GetMethod("DummyVTestMethod1"); var attribs = this.reflectionUtility.GetCustomAttributes(minfo, false); Assert.IsNotNull(attribs); Assert.AreEqual(2, attribs.Length); var expectedAttribs = new string[] { "DummyA : derived", "DummySingleA : derived" }; CollectionAssert.AreEqual(expectedAttribs, GetAttributeValuePairs(attribs)); }
public void GetCustomAttributesOnTypeShouldReturnAllAttributesIgnoringBaseInheritance() { var tinfo = typeof(DummyTestClass).GetTypeInfo(); var attribs = this.reflectionUtility.GetCustomAttributes(tinfo, false); Assert.IsNotNull(attribs); Assert.AreEqual(1, attribs.Length); var expectedAttribs = new string[] { "DummyA : a" }; CollectionAssert.AreEqual(expectedAttribs, GetAttributeValuePairs(attribs)); }
public void GetSpecificCustomAttributesOnTypeShouldReturnAllAttributesWithBaseInheritance() { var minfo = typeof(DummyTestClass).GetTypeInfo(); var attribs = this.reflectionUtility.GetCustomAttributes(minfo, typeof(DummyAAttribute), true); Assert.IsNotNull(attribs); Assert.AreEqual(2, attribs.Length); var expectedAttribs = new string[] { "DummyA : a", "DummyA : ba" }; CollectionAssert.AreEqual(expectedAttribs, GetAttributeValuePairs(attribs)); }
public void GetSpecificCustomAttributesShouldReturnAllAttributes() { var minfo = typeof(DummyBaseTestClass).GetMethod("DummyVTestMethod1"); var attribs = this.reflectionUtility.GetCustomAttributes(minfo, typeof(DummyAAttribute), false); Assert.IsNotNull(attribs); Assert.AreEqual(1, attribs.Length); var expectedAttribs = new string[] { "DummyA : base" }; CollectionAssert.AreEqual(expectedAttribs, GetAttributeValuePairs(attribs)); }
public void GetSpecificCustomAttributesShouldReturnAllAttributes() { var minfo = this.testAsset.GetType("TestProjectForDiscovery.AttributeTestBaseClass").GetMethod("DummyVTestMethod1"); var attribs = this.reflectionUtility.GetCustomAttributes(minfo, typeof(TestCategoryV2), false); Assert.IsNotNull(attribs); Assert.AreEqual(1, attribs.Length); var expectedAttribs = new string[] { "TestCategory : base" }; CollectionAssert.AreEqual(expectedAttribs, this.GetAttributeValuePairs(attribs)); }
public void GetDeploymentItemsShouldReturnClassAndMethodLevelDeploymentItemsWithoutDuplicates() { // Arrange. var deploymentItemAttributes = new[] { new KeyValuePair <string, string>( this.defaultDeploymentItemPath, this.defaultDeploymentItemOutputDirectory), new KeyValuePair <string, string>( this.defaultDeploymentItemPath + "\\temp2", this.defaultDeploymentItemOutputDirectory) }; var memberInfo = typeof(DeploymentItemUtilityTests).GetMethod( "GetDeploymentItemsShouldReturnClassAndMethodLevelDeploymentItems"); this.SetupDeploymentItems(memberInfo, deploymentItemAttributes); var classLevelDeploymentItems = new DeploymentItem[] { new DeploymentItem( this.defaultDeploymentItemPath, this.defaultDeploymentItemOutputDirectory), new DeploymentItem( this.defaultDeploymentItemPath + "\\temp1", this.defaultDeploymentItemOutputDirectory) }; // Act. var deploymentItems = this.deploymentItemUtility.GetDeploymentItems( memberInfo, classLevelDeploymentItems, this.warnings); // Assert. var expectedDeploymentItems = new KeyValuePair <string, string>[] { new KeyValuePair <string, string>( this.defaultDeploymentItemPath, this.defaultDeploymentItemOutputDirectory), new KeyValuePair <string, string>( this.defaultDeploymentItemPath + "\\temp2", this.defaultDeploymentItemOutputDirectory), new KeyValuePair <string, string>( this.defaultDeploymentItemPath + "\\temp1", this.defaultDeploymentItemOutputDirectory) }; CollectionAssert.AreEqual(expectedDeploymentItems, deploymentItems.ToArray()); }
public void ToTestCaseShouldSetPropertiesIfPresent() { this.unitTestElement.CssIteration = "12"; this.unitTestElement.CssProjectStructure = "ProjectStructure"; this.unitTestElement.Description = "I am a dummy test"; this.unitTestElement.WorkItemIds = new string[] { "2312", "22332" }; var testCase = this.unitTestElement.ToTestCase(); Assert.AreEqual("12", testCase.GetPropertyValue(Constants.CssIterationProperty)); Assert.AreEqual("ProjectStructure", testCase.GetPropertyValue(Constants.CssProjectStructureProperty)); Assert.AreEqual("I am a dummy test", testCase.GetPropertyValue(Constants.DescriptionProperty)); CollectionAssert.AreEqual(new string[] { "2312", "22332" }, testCase.GetPropertyValue(Constants.WorkItemIdsProperty) as string[]); }
public void GetCustomAttributesShouldReturnAllAttributesWithBaseInheritance() { var minfo = typeof(DummyTestClass).GetMethod("DummyVTestMethod1"); var attribs = this.reflectionUtility.GetCustomAttributes(minfo, true); Assert.IsNotNull(attribs); Assert.AreEqual(3, attribs.Length); // Notice that the DummySingleA on the base method does not show up since it can only be defined once. var expectedAttribs = new string[] { "DummyA : derived", "DummySingleA : derived", "DummyA : base", }; CollectionAssert.AreEqual(expectedAttribs, GetAttributeValuePairs(attribs)); }
public void GetCustomAttributesShouldReturnAllAttributesWithBaseInheritance() { var minfo = this.testAsset.GetType("TestProjectForDiscovery.AttributeTestClass").GetMethod("DummyVTestMethod1"); var attribs = this.reflectionUtility.GetCustomAttributes(minfo, true); Assert.IsNotNull(attribs); Assert.AreEqual(3, attribs.Length); // Notice that the Owner on the base method does not show up since it can only be defined once. var expectedAttribs = new string[] { "TestCategory : derived", "TestCategory : base", "Owner : derived" }; CollectionAssert.AreEqual(expectedAttribs, this.GetAttributeValuePairs(attribs)); }