public void GetClassLevelDeploymentItemsShouldReturnMoreThanOneDeploymentItems() { var deploymentItemAttributes = new[] { new KeyValuePair <string, string>( this.defaultDeploymentItemPath, this.defaultDeploymentItemOutputDirectory), new KeyValuePair <string, string>( this.defaultDeploymentItemPath + "\\temp2", this.defaultDeploymentItemOutputDirectory) }; this.SetupDeploymentItems(typeof(DeploymentItemUtilityTests), deploymentItemAttributes); var deploymentItems = this.deploymentItemUtility.GetClassLevelDeploymentItems( typeof(DeploymentItemUtilityTests), this.warnings); var expectedDeploymentItems = new DeploymentItem[] { new DeploymentItem( deploymentItemAttributes[0].Key, deploymentItemAttributes[0].Value), new DeploymentItem( deploymentItemAttributes[1].Key, deploymentItemAttributes[1].Value) }; CollectionAssert.AreEqual(expectedDeploymentItems, deploymentItems.ToArray()); }
public void EnumerateAssemblyShouldReturnTestElementsForAType() { var mockAssembly = new Mock <TestableAssembly>(); var testableAssemblyEnumerator = new TestableAssemblyEnumerator(); var unitTestElement = new UnitTestElement(new TestMethod("DummyMethod", "DummyClass", "DummyAssembly", false)); // Setup mocks mockAssembly.Setup(a => a.DefinedTypes) .Returns(new List <TypeInfo>() { typeof(DummyTestClass).GetTypeInfo() }); this.testablePlatformServiceProvider.MockFileOperations.Setup(fo => fo.LoadAssembly("DummyAssembly", false)) .Returns(mockAssembly.Object); testableAssemblyEnumerator.MockTypeEnumerator.Setup(te => te.Enumerate(out this.warnings)) .Returns(new Collection <UnitTestElement> { unitTestElement }); var testElements = testableAssemblyEnumerator.EnumerateAssembly("DummyAssembly", out this.warnings); CollectionAssert.AreEqual(new Collection <UnitTestElement> { unitTestElement }, testElements.ToList()); }
public void RunTestsForTestWithFilterShouldSendResultsForFilteredTests() { var testCase = this.GetTestCase(typeof(DummyTestClass), "PassingTest"); var failingTestCase = this.GetTestCase(typeof(DummyTestClass), "FailingTest"); TestCase[] tests = new[] { testCase, failingTestCase }; this.runContext = new TestableRunContextTestExecutionTests(() => new TestableTestCaseFilterExpression((p) => (p.DisplayName == "PassingTest"))); this.TestExecutionManager.RunTests(tests, this.runContext, this.frameworkHandle, this.cancellationToken); // FailingTest should be skipped because it does not match the filter criteria. List <string> expectedTestCaseStartList = new List <string>() { "PassingTest" }; List <string> expectedTestCaseEndList = new List <string>() { "PassingTest:Passed" }; List <string> expectedResultList = new List <string>() { "PassingTest Passed" }; CollectionAssert.AreEqual(expectedTestCaseStartList, this.frameworkHandle.TestCaseStartList); CollectionAssert.AreEqual(expectedTestCaseEndList, this.frameworkHandle.TestCaseEndList); CollectionAssert.AreEqual(expectedResultList, this.frameworkHandle.ResultsList); }
public void GetClassLevelDeploymentItemsShouldNotReturnDuplicateDeploymentItemEntries() { var deploymentItemAttributes = new[] { new KeyValuePair <string, string>( this.defaultDeploymentItemPath, this.defaultDeploymentItemOutputDirectory), new KeyValuePair <string, string>( this.defaultDeploymentItemPath, this.defaultDeploymentItemOutputDirectory) }; this.SetupDeploymentItems(typeof(DeploymentItemUtilityTests), deploymentItemAttributes); var deploymentItems = this.deploymentItemUtility.GetClassLevelDeploymentItems( typeof(DeploymentItemUtilityTests), this.warnings); var expectedDeploymentItems = new[] { new DeploymentItem( this.defaultDeploymentItemPath, this.defaultDeploymentItemOutputDirectory) }; CollectionAssert.AreEqual(expectedDeploymentItems, deploymentItems.ToArray()); }
public void RunTestsForMultipleTestShouldSendMultipleResults() { var testCase = this.GetTestCase(typeof(DummyTestClass), "PassingTest"); var failingTestCase = this.GetTestCase(typeof(DummyTestClass), "FailingTest"); TestCase[] tests = new[] { testCase, failingTestCase }; this.TestExecutionManager.RunTests(tests, this.runContext, this.frameworkHandle, this.cancellationToken); List <string> expectedTestCaseStartList = new List <string>() { "PassingTest", "FailingTest" }; List <string> expectedTestCaseEndList = new List <string>() { "PassingTest:Passed", "FailingTest:Failed" }; List <string> expectedResultList = new List <string>() { "PassingTest Passed", "FailingTest Failed\r\n Message: (null)" }; CollectionAssert.AreEqual(expectedTestCaseStartList, this.frameworkHandle.TestCaseStartList); CollectionAssert.AreEqual(expectedTestCaseEndList, this.frameworkHandle.TestCaseEndList); Assert.AreEqual("PassingTest Passed", this.frameworkHandle.ResultsList[0]); StringAssert.Contains( this.frameworkHandle.ResultsList[1], "FailingTest Failed\r\n Message: Assert.Fail failed. \r\n StackTrace:\r\n at Microsoft.VisualStudio.TestPlatform.MSTestAdapter.UnitTests.Execution.TestExecutionManagerTests.DummyTestClass.FailingTest()"); }
public void RunTestsForASingleTestShouldSendSingleResult() { var testCase = this.GetTestCase(typeof(DummyTestClass), "PassingTest"); TestCase[] tests = new[] { testCase }; this.TestExecutionManager.RunTests(tests, this.runContext, this.frameworkHandle, new TestRunCancellationToken()); List <string> expectedTestCaseStartList = new List <string>() { "PassingTest" }; List <string> expectedTestCaseEndList = new List <string>() { "PassingTest:Passed" }; List <string> expectedResultList = new List <string>() { "PassingTest Passed" }; CollectionAssert.AreEqual(expectedTestCaseStartList, this.frameworkHandle.TestCaseStartList); CollectionAssert.AreEqual(expectedTestCaseEndList, this.frameworkHandle.TestCaseEndList); CollectionAssert.AreEqual(expectedResultList, this.frameworkHandle.ResultsList); }
public void GetDeploymentItemsShouldReturnClassLevelDeploymentItemsOnly() { // Arrange. var classLevelDeploymentItems = new DeploymentItem[] { new DeploymentItem( this.defaultDeploymentItemPath, this.defaultDeploymentItemOutputDirectory), new DeploymentItem( this.defaultDeploymentItemPath + "\\temp2", this.defaultDeploymentItemOutputDirectory) }; // Act. var deploymentItems = this.deploymentItemUtility.GetDeploymentItems( typeof(DeploymentItemUtilityTests).GetMethod("GetDeploymentItemsShouldReturnNullOnNoDeploymentItems"), classLevelDeploymentItems, this.warnings); // Assert. var expectedDeploymentItems = new[] { new KeyValuePair <string, string>( this.defaultDeploymentItemPath, this.defaultDeploymentItemOutputDirectory), new KeyValuePair <string, string>( this.defaultDeploymentItemPath + "\\temp2", this.defaultDeploymentItemOutputDirectory) }; CollectionAssert.AreEqual(expectedDeploymentItems, deploymentItems.ToArray()); }
public void GetClassLevelDeploymentItemsShouldReportWarningsForInvalidDeploymentItems() { var deploymentItemAttributes = new[] { new KeyValuePair <string, string>( this.defaultDeploymentItemPath, this.defaultDeploymentItemOutputDirectory), new KeyValuePair <string, string>( null, this.defaultDeploymentItemOutputDirectory) }; this.SetupDeploymentItems(typeof(DeploymentItemUtilityTests), deploymentItemAttributes); var deploymentItems = this.deploymentItemUtility.GetClassLevelDeploymentItems(typeof(DeploymentItemUtilityTests), this.warnings); var expectedDeploymentItems = new DeploymentItem[] { new DeploymentItem( this.defaultDeploymentItemPath, this.defaultDeploymentItemOutputDirectory) }; CollectionAssert.AreEqual(expectedDeploymentItems, deploymentItems.ToArray()); Assert.AreEqual(1, this.warnings.Count); TestFrameworkV2.StringAssert.Contains(this.warnings.ToArray()[0], Resource.DeploymentItemPathCannotBeNullOrEmpty); }
public void AddAssemblyRedirectionShouldAddRedirectionToAConfigWithARuntimeSectionOnly() { this.testableXmlUtilities.ConfigXml = @"<?xml version=""1.0"" encoding=""utf-8"" ?> <configuration> <runtime> </runtime> </configuration>"; var assemblyName = Assembly.GetExecutingAssembly().GetName(); var configBytes = this.testableXmlUtilities.AddAssemblyRedirection( "foo.xml", assemblyName, "99.99.99.99", assemblyName.Version.ToString()); // Assert. var expectedXml = "<?xml version=\"1.0\" encoding=\"utf-8\"?><configuration><runtime><assemblyBinding xmlns=\"urn:schemas-microsoft-com:asm.v1\"><dependentAssembly><assemblyIdentity name=\"MSTestAdapter.PlatformServices.Desktop.UnitTests\" publicKeyToken=\"b03f5f7f11d50a3a\" culture=\"neutral\" /><bindingRedirect oldVersion=\"99.99.99.99\" newVersion=\"14.0.0.0\" /></dependentAssembly></assemblyBinding></runtime></configuration>"; var doc = new XmlDocument(); doc.LoadXml(expectedXml); byte[] expectedConfigBytes = null; using (var ms = new MemoryStream()) { doc.Save(ms); expectedConfigBytes = ms.ToArray(); } CollectionAssert.AreEqual(expectedConfigBytes, configBytes); }
public void GetTestCategoryAttributeShouldIncludeTestCategoriesAtClassLevel() { this.reflectHelper.SetCustomAttribute(typeof(UTF.TestCategoryBaseAttribute), new[] { new UTF.TestCategoryAttribute("ClassLevel") }, MemberTypes.TypeInfo); string[] expected = new[] { "ClassLevel" }; var actual = this.reflectHelper.GetCategories(this.method.Object).ToArray(); CollectionAssert.AreEqual(expected, actual); }
public void GetTestCategoryAttributeShouldIncludeMultipleTestCategoriesAtAssemblyLevel() { this.reflectHelper.SetCustomAttribute(typeof(UTF.TestCategoryBaseAttribute), new[] { new UTF.TestCategoryAttribute("AsmLevel"), new UTF.TestCategoryAttribute("AsmLevel1") }, MemberTypes.All); string[] expected = new[] { "AsmLevel", "AsmLevel1" }; var actual = this.reflectHelper.GetCategories(this.method.Object, typeof(ReflectHelperTests)).ToArray(); CollectionAssert.AreEqual(expected, actual); }
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 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 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 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 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 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 GetTestCategoryAttributeShouldIncludeTestCategoriesAtAllLevels() { this.reflectHelper.SetCustomAttribute(typeof(UTF.TestCategoryBaseAttribute), new[] { new UTF.TestCategoryAttribute("AsmLevel1"), new UTF.TestCategoryAttribute("AsmLevel2") }, MemberTypes.All); this.reflectHelper.SetCustomAttribute(typeof(UTF.TestCategoryBaseAttribute), new[] { new UTF.TestCategoryAttribute("AsmLevel3") }, MemberTypes.All); this.reflectHelper.SetCustomAttribute(typeof(UTF.TestCategoryBaseAttribute), new[] { new UTF.TestCategoryAttribute("ClassLevel") }, MemberTypes.TypeInfo); this.reflectHelper.SetCustomAttribute(typeof(UTF.TestCategoryBaseAttribute), new[] { new UTF.TestCategoryAttribute("MethodLevel") }, MemberTypes.Method); var actual = this.reflectHelper.GetCategories(this.method.Object, typeof(ReflectHelperTests)).ToArray(); string[] expected = new[] { "MethodLevel", "ClassLevel", "AsmLevel1", "AsmLevel2", "AsmLevel3" }; CollectionAssert.AreEqual(expected, actual); }
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 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 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 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 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 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 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 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 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 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[]); }