diff --git a/TestFx.sln b/TestFx.sln index a8ec4bb699..1d10ff71ea 100644 --- a/TestFx.sln +++ b/TestFx.sln @@ -216,6 +216,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "WinUI", "WinUI", "{35D010CC src\Adapter\Build\WinUI\MSTest.TestAdapter.targets = src\Adapter\Build\WinUI\MSTest.TestAdapter.targets EndProjectSection EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ReferencedProjectFromDataSourceTest", "test\E2ETests\TestAssets\ReferencedProjectFromDataSourceTest\ReferencedProjectFromDataSourceTest.csproj", "{6B4DE65C-4162-4C52-836A-8F9FA901814A}" +EndProject Global GlobalSection(SharedMSBuildProjectFiles) = preSolution src\Adapter\PlatformServices.Shared\PlatformServices.Shared.projitems*{2177c273-ae07-43b3-b87a-443e47a23c5a}*SharedItemsImports = 13 @@ -1270,6 +1272,30 @@ Global {F4E2876F-6E42-4DCF-B629-041A9DF7C579}.Release|x64.Build.0 = Release|x64 {F4E2876F-6E42-4DCF-B629-041A9DF7C579}.Release|x86.ActiveCfg = Release|x86 {F4E2876F-6E42-4DCF-B629-041A9DF7C579}.Release|x86.Build.0 = Release|x86 + {6B4DE65C-4162-4C52-836A-8F9FA901814A}.Code Analysis Debug|Any CPU.ActiveCfg = Debug|Any CPU + {6B4DE65C-4162-4C52-836A-8F9FA901814A}.Code Analysis Debug|Any CPU.Build.0 = Debug|Any CPU + {6B4DE65C-4162-4C52-836A-8F9FA901814A}.Code Analysis Debug|ARM.ActiveCfg = Debug|Any CPU + {6B4DE65C-4162-4C52-836A-8F9FA901814A}.Code Analysis Debug|ARM.Build.0 = Debug|Any CPU + {6B4DE65C-4162-4C52-836A-8F9FA901814A}.Code Analysis Debug|x64.ActiveCfg = Debug|Any CPU + {6B4DE65C-4162-4C52-836A-8F9FA901814A}.Code Analysis Debug|x64.Build.0 = Debug|Any CPU + {6B4DE65C-4162-4C52-836A-8F9FA901814A}.Code Analysis Debug|x86.ActiveCfg = Debug|Any CPU + {6B4DE65C-4162-4C52-836A-8F9FA901814A}.Code Analysis Debug|x86.Build.0 = Debug|Any CPU + {6B4DE65C-4162-4C52-836A-8F9FA901814A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {6B4DE65C-4162-4C52-836A-8F9FA901814A}.Debug|Any CPU.Build.0 = Debug|Any CPU + {6B4DE65C-4162-4C52-836A-8F9FA901814A}.Debug|ARM.ActiveCfg = Debug|Any CPU + {6B4DE65C-4162-4C52-836A-8F9FA901814A}.Debug|ARM.Build.0 = Debug|Any CPU + {6B4DE65C-4162-4C52-836A-8F9FA901814A}.Debug|x64.ActiveCfg = Debug|Any CPU + {6B4DE65C-4162-4C52-836A-8F9FA901814A}.Debug|x64.Build.0 = Debug|Any CPU + {6B4DE65C-4162-4C52-836A-8F9FA901814A}.Debug|x86.ActiveCfg = Debug|Any CPU + {6B4DE65C-4162-4C52-836A-8F9FA901814A}.Debug|x86.Build.0 = Debug|Any CPU + {6B4DE65C-4162-4C52-836A-8F9FA901814A}.Release|Any CPU.ActiveCfg = Release|Any CPU + {6B4DE65C-4162-4C52-836A-8F9FA901814A}.Release|Any CPU.Build.0 = Release|Any CPU + {6B4DE65C-4162-4C52-836A-8F9FA901814A}.Release|ARM.ActiveCfg = Release|Any CPU + {6B4DE65C-4162-4C52-836A-8F9FA901814A}.Release|ARM.Build.0 = Release|Any CPU + {6B4DE65C-4162-4C52-836A-8F9FA901814A}.Release|x64.ActiveCfg = Release|Any CPU + {6B4DE65C-4162-4C52-836A-8F9FA901814A}.Release|x64.Build.0 = Release|Any CPU + {6B4DE65C-4162-4C52-836A-8F9FA901814A}.Release|x86.ActiveCfg = Release|Any CPU + {6B4DE65C-4162-4C52-836A-8F9FA901814A}.Release|x86.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -1339,6 +1365,7 @@ Global {D11C6664-1C4E-48F0-AA92-7F5BADC6F82C} = {CA01DAF5-8D9D-496E-9AD3-94BB7FBB2D34} {F4E2876F-6E42-4DCF-B629-041A9DF7C579} = {24088844-2107-4DB2-8F3F-CBCA94FC4B28} {35D010CC-CDF2-4115-BCFB-E2E3D21C1055} = {CA01DAF5-8D9D-496E-9AD3-94BB7FBB2D34} + {6B4DE65C-4162-4C52-836A-8F9FA901814A} = {D53BD452-F69F-4FB3-8B98-386EDA28A4C8} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {31E0F4D5-975A-41CC-933E-545B2201FAF9} diff --git a/src/Adapter/MSTest.CoreAdapter/Execution/TestMethodRunner.cs b/src/Adapter/MSTest.CoreAdapter/Execution/TestMethodRunner.cs index 368c7a30c6..8dfd82a85b 100644 --- a/src/Adapter/MSTest.CoreAdapter/Execution/TestMethodRunner.cs +++ b/src/Adapter/MSTest.CoreAdapter/Execution/TestMethodRunner.cs @@ -206,7 +206,7 @@ internal UnitTestResult[] RunTestMethod() { if (this.test.DataType == DynamicDataType.ITestDataSource) { - var data = DataSerializationHelper.Deserialize(this.test.SerializedData, this.testMethodInfo.Parent.Parent.Assembly); + var data = DataSerializationHelper.Deserialize(this.test.SerializedData); var testResults = this.ExecuteTestWithDataSource(null, data); results.AddRange(testResults); } diff --git a/src/Adapter/MSTest.CoreAdapter/Helpers/DataSerializationHelper.cs b/src/Adapter/MSTest.CoreAdapter/Helpers/DataSerializationHelper.cs index cd6937e806..9b7fb56685 100644 --- a/src/Adapter/MSTest.CoreAdapter/Helpers/DataSerializationHelper.cs +++ b/src/Adapter/MSTest.CoreAdapter/Helpers/DataSerializationHelper.cs @@ -44,11 +44,12 @@ public static string[] Serialize(object[] data) { serializedData[typeIndex] = null; serializedData[dataIndex] = null; + continue; } var type = data[i].GetType(); - var typeName = type.FullName; + var typeName = type.AssemblyQualifiedName; serializedData[typeIndex] = typeName; @@ -70,9 +71,8 @@ public static string[] Serialize(object[] data) /// Deserialzes the data serialzed by method. /// /// Serialized data array to deserialize. - /// Assemblies that serialized types defined in. /// Deserialized array. - public static object[] Deserialize(string[] serializedData, params Assembly[] assemblies) + public static object[] Deserialize(string[] serializedData) { if (serializedData == null || serializedData.Length % 2 != 0) { @@ -94,7 +94,7 @@ public static object[] Deserialize(string[] serializedData, params Assembly[] as continue; } - var serializer = GetSerializer(typeName, assemblies); + var serializer = GetSerializer(typeName); var serialzedDataBytes = Encoding.UTF8.GetBytes(serializedValue); using (var memoryStream = new MemoryStream(serialzedDataBytes)) @@ -106,7 +106,7 @@ public static object[] Deserialize(string[] serializedData, params Assembly[] as return data; } - private static DataContractJsonSerializer GetSerializer(string typeName, Assembly[] assemblies) + private static DataContractJsonSerializer GetSerializer(string typeName) { var serializer = SerializerCache.SingleOrDefault(i => i.Key.FullName == typeName); if (serializer.Value != null) @@ -120,18 +120,6 @@ private static DataContractJsonSerializer GetSerializer(string typeName, Assembl return GetSerializer(type); } - if (assemblies != null) - { - foreach (var assembly in assemblies) - { - type = assembly.GetType(typeName); - if (type != null) - { - return GetSerializer(type); - } - } - } - return GetSerializer(typeof(object)); } diff --git a/test/E2ETests/DiscoveryAndExecutionTests/TestDataSourceTests.cs b/test/E2ETests/DiscoveryAndExecutionTests/TestDataSourceTests.cs new file mode 100644 index 0000000000..69f334105b --- /dev/null +++ b/test/E2ETests/DiscoveryAndExecutionTests/TestDataSourceTests.cs @@ -0,0 +1,189 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. + +namespace Microsoft.MSTestV2.Smoke.DiscoveryAndExecutionTests +{ + using Microsoft.MSTestV2.CLIAutomation; + using Microsoft.VisualStudio.TestPlatform.MSTest.TestAdapter.ObjectModel; + using Microsoft.VisualStudio.TestTools.UnitTesting; + + using System.IO; + using System.Linq; + + [TestClass] + public class TestDataSourceTests : CLITestBase + { + private const string TestAssembly = "DataSourceTestProject.dll"; + + [TestMethod] + public void ExecuteCsvTestDataSourceTests() + { + // Arrange + var assemblyPath = Path.IsPathRooted(TestAssembly) ? TestAssembly : this.GetAssetFullPath(TestAssembly); + + // Act + var testCases = DiscoverTests(assemblyPath, "CsvTestMethod"); + var testResults = RunTests(assemblyPath, testCases); + + // Assert + Assert.That.ContainsTestsPassed(testResults, + "CsvTestMethod (Data Row 0)", + "CsvTestMethod (Data Row 2)" + ); + + Assert.That.ContainsTestsFailed(testResults, + "CsvTestMethod (Data Row 1)", + "CsvTestMethod (Data Row 3)" + ); + } + + [TestMethod] + public void ExecuteDynamicDataTests() + { + // Arrange + var assemblyPath = Path.IsPathRooted(TestAssembly) ? TestAssembly : this.GetAssetFullPath(TestAssembly); + + // Act + var testCases = DiscoverTests(assemblyPath, "DynamicDataTest"); + var testResults = RunTests(assemblyPath, testCases); + + // Assert + Assert.That.ContainsTestsPassed(testResults, + "DynamicDataTest (John;Doe,DataSourceTestProject.ITestDataSourceTests.User)" + ); + + Assert.That.FailedTestCount(testResults, 0); + } + + [TestMethod] + public void ExecuteDataRowTests_Enums() + { + // Arrange + var assemblyPath = Path.IsPathRooted(TestAssembly) ? TestAssembly : this.GetAssetFullPath(TestAssembly); + + // Act + var testCases = DiscoverTests(assemblyPath, "FullyQualifiedName~DataRowTests_Enums"); + var testResults = RunTests(assemblyPath, testCases); + + // Assert + Assert.That.TestsPassed(testResults, + "DataRowEnums_SByte (Alfa)", + "DataRowEnums_SByte (Beta)", + "DataRowEnums_SByte (Gamma)", + "DataRowEnums_Byte (Alfa)", + "DataRowEnums_Byte (Beta)", + "DataRowEnums_Byte (Gamma)", + "DataRowEnums_Short (Alfa)", + "DataRowEnums_Short (Beta)", + "DataRowEnums_Short (Gamma)", + "DataRowEnums_UShort (Alfa)", + "DataRowEnums_UShort (Beta)", + "DataRowEnums_UShort (Gamma)", + "DataRowEnums_Int (Alfa)", + "DataRowEnums_Int (Beta)", + "DataRowEnums_Int (Gamma)", + "DataRowEnums_UInt (Alfa)", + "DataRowEnums_UInt (Beta)", + "DataRowEnums_UInt (Gamma)", + "DataRowEnum_Long (Alfa)", + "DataRowEnum_Long (Beta)", + "DataRowEnum_Long (Gamma)", + "DataRowEnum_ULong (Alfa)", + "DataRowEnum_ULong (Beta)", + "DataRowEnum_ULong (Gamma)", + + "DataRowEnums_Nullable_SByte ()", + "DataRowEnums_Nullable_SByte (Alfa)", + "DataRowEnums_Nullable_SByte (Beta)", + "DataRowEnums_Nullable_SByte (Gamma)", + "DataRowEnums_Nullable_Byte ()", + "DataRowEnums_Nullable_Byte (Alfa)", + "DataRowEnums_Nullable_Byte (Beta)", + "DataRowEnums_Nullable_Byte (Gamma)", + "DataRowEnums_Nullable_Short ()", + "DataRowEnums_Nullable_Short (Alfa)", + "DataRowEnums_Nullable_Short (Beta)", + "DataRowEnums_Nullable_Short (Gamma)", + "DataRowEnums_Nullable_UShort ()", + "DataRowEnums_Nullable_UShort (Alfa)", + "DataRowEnums_Nullable_UShort (Beta)", + "DataRowEnums_Nullable_UShort (Gamma)", + "DataRowEnums_Nullable_Int ()", + "DataRowEnums_Nullable_Int (Alfa)", + "DataRowEnums_Nullable_Int (Beta)", + "DataRowEnums_Nullable_Int (Gamma)", + "DataRowEnums_Nullable_UInt ()", + "DataRowEnums_Nullable_UInt (Alfa)", + "DataRowEnums_Nullable_UInt (Beta)", + "DataRowEnums_Nullable_UInt (Gamma)", + "DataRowEnums_Nullable_Long ()", + "DataRowEnums_Nullable_Long (Alfa)", + "DataRowEnums_Nullable_Long (Beta)", + "DataRowEnums_Nullable_Long (Gamma)", + "DataRowEnums_Nullable_ULong ()", + "DataRowEnums_Nullable_ULong (Alfa)", + "DataRowEnums_Nullable_ULong (Beta)", + "DataRowEnums_Nullable_ULong (Gamma)", + + "DataRowEnums_MixedTypes_Byte (Alfa,True,1)", + "DataRowEnums_MixedTypes_Byte (Beta,False,2)", + "DataRowEnums_MixedTypes_Byte (Gamma,True,3)" + ); + + Assert.That.FailedTestCount(testResults, 0); + } + + [TestMethod] + public void ExecuteDataRowTests_NonSerializablePaths() + { + // Arrange + var assemblyPath = Path.IsPathRooted(TestAssembly) ? TestAssembly : this.GetAssetFullPath(TestAssembly); + + // Act + var testCases = DiscoverTests(assemblyPath, "FullyQualifiedName~DataRowTests_NonSerializablePaths"); + var testResults = RunTests(assemblyPath, testCases); + + // Assert + Assert.That.TestsPassed(testResults, + "DataRowNonSerializable (System.String)", + "DataRowNonSerializable (System.Int32)", + "DataRowNonSerializable (DataSourceTestProject.ITestDataSourceTests.DataRowTests_Enums)"); + Assert.That.FailedTestCount(testResults, 0); + } + + [TestMethod] + public void ExecuteRegular_DataRowTests() + { + // Arrange + var assemblyPath = Path.IsPathRooted(TestAssembly) ? TestAssembly : this.GetAssetFullPath(TestAssembly); + + // Act + var testCases = DiscoverTests(assemblyPath, "FullyQualifiedName~Regular_DataRowTests"); + var testResults = RunTests(assemblyPath, testCases); + + // Assert + Assert.That.TestsPassed(testResults, + "DataRow1 (10)", + "DataRow1 (20)", + "DataRow1 (30)", + "DataRow1 (40)", + "DataRow2 (10,String parameter,True,False)", + "DataRow2 (20,String parameter,True,False)", + "DataRow2 (30,String parameter,True,False)", + "DataRow2 (40,String parameter,True,False)", + "DataRowTestMethodFailsWithInvalidArguments ()", + "DataRowTestMethodFailsWithInvalidArguments (2)", + "DataRowTestMethodFailsWithInvalidArguments (2,DerivedRequiredArgument,DerivedOptionalArgument,DerivedExtraArgument)", + "DataRowTestDouble (10.01,20.01)", + "DataRowTestDouble (10.02,20.02)", + "DataRowTestMixed (1,10,10,10,10,10,10,10,10)", + "DataRowTestMixed (2,10,10,10,10,10,10,10,10)", + "DataRowTestMixed (3,10,10,10,10,10,10,10,10)", + "DataRowTestMixed (4,10,10,10,10,10,10,10,10)", + "NullValueInData (john.doe@example.com,abc123,)", + "NullValueInData (john.doe@example.com,abc123,/unit/test)"); + + Assert.That.FailedTestCount(testResults, 0); + } + } +} diff --git a/test/E2ETests/Smoke.E2E.Tests/DataSourceTests.cs b/test/E2ETests/Smoke.E2E.Tests/DataSourceTests.cs deleted file mode 100644 index bf23352a0e..0000000000 --- a/test/E2ETests/Smoke.E2E.Tests/DataSourceTests.cs +++ /dev/null @@ -1,30 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT license. See LICENSE file in the project root for full license information. - -namespace MSTestAdapter.Smoke.E2ETests -{ - using Microsoft.MSTestV2.CLIAutomation; - using Microsoft.VisualStudio.TestTools.UnitTesting; - - [TestClass] - public class DataSourceTests : CLITestBase - { - private const string TestAssembly = "DataSourceTestProject.dll"; - - [TestMethod] - public void ExecuteCsvTestDataSourceTests() - { - this.InvokeVsTestForExecution(new string[] { TestAssembly }); - - this.ValidatePassedTestsContain( - "CsvTestMethod (Data Row 0)", - "CsvTestMethod (Data Row 2)"); - - this.ValidateFailedTestsContain( - TestAssembly, - true, - "CsvTestMethod (Data Row 1)", - "CsvTestMethod (Data Row 3)"); - } - } -} diff --git a/test/E2ETests/Smoke.E2E.Tests/Smoke.E2E.Tests.csproj b/test/E2ETests/Smoke.E2E.Tests/Smoke.E2E.Tests.csproj index c04aff916a..efc75053b3 100644 --- a/test/E2ETests/Smoke.E2E.Tests/Smoke.E2E.Tests.csproj +++ b/test/E2ETests/Smoke.E2E.Tests/Smoke.E2E.Tests.csproj @@ -55,7 +55,7 @@ - + diff --git a/test/E2ETests/Smoke.E2E.Tests/TestDataSourceTests.cs b/test/E2ETests/Smoke.E2E.Tests/TestDataSourceTests.cs new file mode 100644 index 0000000000..3211e7f92b --- /dev/null +++ b/test/E2ETests/Smoke.E2E.Tests/TestDataSourceTests.cs @@ -0,0 +1,171 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. + +namespace MSTestAdapter.Smoke.E2ETests +{ + using Microsoft.MSTestV2.CLIAutomation; + using Microsoft.VisualStudio.TestTools.UnitTesting; + + [TestClass] + public class TestDataSourceTests : CLITestBase + { + private const string TestAssembly = "DataSourceTestProject.dll"; + + [TestMethod] + public void ExecuteCsvTestDataSourceTests() + { + // Arrange & Act + this.InvokeVsTestForExecution( + new string[] { TestAssembly }, + testCaseFilter: "CsvTestMethod"); + + // Assert + this.ValidatePassedTests( + "CsvTestMethod (Data Row 0)", + "CsvTestMethod (Data Row 2)"); + + this.ValidateFailedTests( + TestAssembly, + "CsvTestMethod (Data Row 1)", + "CsvTestMethod (Data Row 3)"); + } + + [TestMethod] + public void ExecuteDynamicDataTests() + { + // Arrange & Act + this.InvokeVsTestForExecution( + new string[] { TestAssembly }, + testCaseFilter: "DynamicDataTest"); + + // Assert + this.ValidatePassedTests( + "DynamicDataTest (John;Doe,DataSourceTestProject.ITestDataSourceTests.User)"); + + this.ValidateFailedTestsCount(0); + } + + [TestMethod] + public void ExecuteDataRowTests_Enums() + { + // Arrange & Act + this.InvokeVsTestForExecution( + new string[] { TestAssembly }, + testCaseFilter: "FullyQualifiedName~DataRowTests_Enums"); + + // Assert + this.ValidatePassedTests( + "DataRowEnums_SByte (Alfa)", + "DataRowEnums_SByte (Beta)", + "DataRowEnums_SByte (Gamma)", + "DataRowEnums_Byte (Alfa)", + "DataRowEnums_Byte (Beta)", + "DataRowEnums_Byte (Gamma)", + "DataRowEnums_Short (Alfa)", + "DataRowEnums_Short (Beta)", + "DataRowEnums_Short (Gamma)", + "DataRowEnums_UShort (Alfa)", + "DataRowEnums_UShort (Beta)", + "DataRowEnums_UShort (Gamma)", + "DataRowEnums_Int (Alfa)", + "DataRowEnums_Int (Beta)", + "DataRowEnums_Int (Gamma)", + "DataRowEnums_UInt (Alfa)", + "DataRowEnums_UInt (Beta)", + "DataRowEnums_UInt (Gamma)", + "DataRowEnum_Long (Alfa)", + "DataRowEnum_Long (Beta)", + "DataRowEnum_Long (Gamma)", + "DataRowEnum_ULong (Alfa)", + "DataRowEnum_ULong (Beta)", + "DataRowEnum_ULong (Gamma)", + "DataRowEnums_Nullable_SByte ()", + "DataRowEnums_Nullable_SByte (Alfa)", + "DataRowEnums_Nullable_SByte (Beta)", + "DataRowEnums_Nullable_SByte (Gamma)", + "DataRowEnums_Nullable_Byte ()", + "DataRowEnums_Nullable_Byte (Alfa)", + "DataRowEnums_Nullable_Byte (Beta)", + "DataRowEnums_Nullable_Byte (Gamma)", + "DataRowEnums_Nullable_Short ()", + "DataRowEnums_Nullable_Short (Alfa)", + "DataRowEnums_Nullable_Short (Beta)", + "DataRowEnums_Nullable_Short (Gamma)", + "DataRowEnums_Nullable_UShort ()", + "DataRowEnums_Nullable_UShort (Alfa)", + "DataRowEnums_Nullable_UShort (Beta)", + "DataRowEnums_Nullable_UShort (Gamma)", + "DataRowEnums_Nullable_Int ()", + "DataRowEnums_Nullable_Int (Alfa)", + "DataRowEnums_Nullable_Int (Beta)", + "DataRowEnums_Nullable_Int (Gamma)", + "DataRowEnums_Nullable_UInt ()", + "DataRowEnums_Nullable_UInt (Alfa)", + "DataRowEnums_Nullable_UInt (Beta)", + "DataRowEnums_Nullable_UInt (Gamma)", + "DataRowEnums_Nullable_Long ()", + "DataRowEnums_Nullable_Long (Alfa)", + "DataRowEnums_Nullable_Long (Beta)", + "DataRowEnums_Nullable_Long (Gamma)", + "DataRowEnums_Nullable_ULong ()", + "DataRowEnums_Nullable_ULong (Alfa)", + "DataRowEnums_Nullable_ULong (Beta)", + "DataRowEnums_Nullable_ULong (Gamma)", + "DataRowEnums_MixedTypes_Byte (Alfa,True,1)", + "DataRowEnums_MixedTypes_Byte (Beta,False,2)", + "DataRowEnums_MixedTypes_Byte (Gamma,True,3)"); + + this.ValidateFailedTestsCount(0); + } + + [TestMethod] + public void ExecuteDataRowTests_NonSerializablePaths() + { + // Arrange & Act + this.InvokeVsTestForExecution( + new string[] { TestAssembly }, + testCaseFilter: "FullyQualifiedName~DataRowTests_NonSerializablePaths"); + + // Assert + this.ValidatePassedTests( + "DataRowNonSerializable (System.String)", + "DataRowNonSerializable (System.Int32)", + "DataRowNonSerializable (DataSourceTestProject.ITestDataSourceTests.DataRowTests_Enums)"); + + this.ValidateFailedTestsCount(0); + } + + [TestMethod] + public void ExecuteRegular_DataRowTests() + { + // Arrange & Act + this.InvokeVsTestForExecution( + new string[] { TestAssembly }, + testCaseFilter: "FullyQualifiedName~Regular_DataRowTests"); + + // Assert + this.ValidatePassedTests( + "DataRow1 (10)", + "DataRow1 (20)", + "DataRow1 (30)", + "DataRow1 (40)", + "DataRow2 (10,String parameter,True,False)", + "DataRow2 (20,String parameter,True,False)", + "DataRow2 (30,String parameter,True,False)", + "DataRow2 (40,String parameter,True,False)", + "DataRowTestMethodFailsWithInvalidArguments ()", + "DataRowTestMethodFailsWithInvalidArguments (2)", + "DataRowTestMethodFailsWithInvalidArguments (2,DerivedRequiredArgument,DerivedOptionalArgument,DerivedExtraArgument)", + "DataRowTestDouble (10.01,20.01)", + "DataRowTestDouble (10.02,20.02)", + "DataRowTestMixed (1,10,10,10,10,10,10,10,10)", + "DataRowTestMixed (2,10,10,10,10,10,10,10,10)", + "DataRowTestMixed (3,10,10,10,10,10,10,10,10)", + "DataRowTestMixed (4,10,10,10,10,10,10,10,10)", + "NullValueInData (john.doe@example.com,abc123,)", + "NullValueInData (john.doe@example.com,abc123,/unit/test)"); + + this.ValidateFailedTestsCount(0); + } + } +} diff --git a/test/E2ETests/TestAssets/DataSourceTestProject/DataSourceTestProject.csproj b/test/E2ETests/TestAssets/DataSourceTestProject/DataSourceTestProject.csproj index 29e275bb8f..f52ff44cca 100644 --- a/test/E2ETests/TestAssets/DataSourceTestProject/DataSourceTestProject.csproj +++ b/test/E2ETests/TestAssets/DataSourceTestProject/DataSourceTestProject.csproj @@ -9,6 +9,7 @@ + diff --git a/test/E2ETests/TestAssets/DataSourceTestProject/ITestDataSourceTests/DataRowTests_Enums.cs b/test/E2ETests/TestAssets/DataSourceTestProject/ITestDataSourceTests/DataRowTests_Enums.cs new file mode 100644 index 0000000000..c80baa4e3e --- /dev/null +++ b/test/E2ETests/TestAssets/DataSourceTestProject/ITestDataSourceTests/DataRowTests_Enums.cs @@ -0,0 +1,189 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. + +namespace DataSourceTestProject.ITestDataSourceTests +{ + using Microsoft.VisualStudio.TestTools.UnitTesting; + + using System; + + [TestClass] + public class DataRowTests_Enums + { + #region Basic Tests + [TestMethod] + [DataRow(SByteEnum.Alfa)] + [DataRow(SByteEnum.Beta)] + [DataRow(SByteEnum.Gamma)] + public void DataRowEnums_SByte(SByteEnum testEnum) + { + Assert.IsTrue(true); + } + + [TestMethod] + [DataRow(ByteEnum.Alfa)] + [DataRow(ByteEnum.Beta)] + [DataRow(ByteEnum.Gamma)] + public void DataRowEnums_Byte(ByteEnum testEnum) + { + Assert.IsTrue(true); + } + + [TestMethod] + [DataRow(ShortEnum.Alfa)] + [DataRow(ShortEnum.Beta)] + [DataRow(ShortEnum.Gamma)] + public void DataRowEnums_Short(ShortEnum testEnum) + { + Assert.IsTrue(true); + } + + [TestMethod] + [DataRow(UShortEnum.Alfa)] + [DataRow(UShortEnum.Beta)] + [DataRow(UShortEnum.Gamma)] + public void DataRowEnums_UShort(UShortEnum testEnum) + { + Assert.IsTrue(true); + } + + [TestMethod] + [DataRow(IntEnum.Alfa)] + [DataRow(IntEnum.Beta)] + [DataRow(IntEnum.Gamma)] + public void DataRowEnums_Int(IntEnum testEnum) + { + Assert.IsTrue(true); + } + + [TestMethod] + [DataRow(UIntEnum.Alfa)] + [DataRow(UIntEnum.Beta)] + [DataRow(UIntEnum.Gamma)] + public void DataRowEnums_UInt(UIntEnum testEnum) + { + Assert.IsTrue(true); + } + + [TestMethod] + [DataRow(LongEnum.Alfa)] + [DataRow(LongEnum.Beta)] + [DataRow(LongEnum.Gamma)] + public void DataRowEnum_Long(LongEnum testEnum) + { + Assert.IsTrue(true); + } + + [TestMethod] + [DataRow(ULongEnum.Alfa)] + [DataRow(ULongEnum.Beta)] + [DataRow(ULongEnum.Gamma)] + public void DataRowEnum_ULong(ULongEnum testEnum) + { + Assert.IsTrue(true); + } + #endregion + + #region Basic Tests (Nullable) + [TestMethod] + [DataRow(null)] + [DataRow(SByteEnum.Alfa)] + [DataRow(SByteEnum.Beta)] + [DataRow(SByteEnum.Gamma)] + public void DataRowEnums_Nullable_SByte(SByteEnum? testEnum) + { + Assert.IsTrue(true); + } + + [TestMethod] + [DataRow(null)] + [DataRow(ByteEnum.Alfa)] + [DataRow(ByteEnum.Beta)] + [DataRow(ByteEnum.Gamma)] + public void DataRowEnums_Nullable_Byte(ByteEnum? testEnum) + { + Assert.IsTrue(true); + } + + [TestMethod] + [DataRow(null)] + [DataRow(ShortEnum.Alfa)] + [DataRow(ShortEnum.Beta)] + [DataRow(ShortEnum.Gamma)] + public void DataRowEnums_Nullable_Short(ShortEnum? testEnum) + { + Assert.IsTrue(true); + } + + [TestMethod] + [DataRow(null)] + [DataRow(UShortEnum.Alfa)] + [DataRow(UShortEnum.Beta)] + [DataRow(UShortEnum.Gamma)] + public void DataRowEnums_Nullable_UShort(UShortEnum? testEnum) + { + Assert.IsTrue(true); + } + + [TestMethod] + [DataRow(null)] + [DataRow(IntEnum.Alfa)] + [DataRow(IntEnum.Beta)] + [DataRow(IntEnum.Gamma)] + public void DataRowEnums_Nullable_Int(IntEnum? testEnum) + { + Assert.IsTrue(true); + } + + [TestMethod] + [DataRow(null)] + [DataRow(UIntEnum.Alfa)] + [DataRow(UIntEnum.Beta)] + [DataRow(UIntEnum.Gamma)] + public void DataRowEnums_Nullable_UInt(UIntEnum? testEnum) + { + Assert.IsTrue(true); + } + + [TestMethod] + [DataRow(null)] + [DataRow(LongEnum.Alfa)] + [DataRow(LongEnum.Beta)] + [DataRow(LongEnum.Gamma)] + public void DataRowEnums_Nullable_Long(LongEnum? testEnum) + { + Assert.IsTrue(true); + } + + [TestMethod] + [DataRow(null)] + [DataRow(ULongEnum.Alfa)] + [DataRow(ULongEnum.Beta)] + [DataRow(ULongEnum.Gamma)] + public void DataRowEnums_Nullable_ULong(ULongEnum? testEnum) + { + Assert.IsTrue(true); + } + #endregion + + #region Mixed Types + [TestMethod] + [DataRow(ByteEnum.Alfa, true, 1)] + [DataRow(ByteEnum.Beta, false, 2)] + [DataRow(ByteEnum.Gamma, true, 3)] + public void DataRowEnums_MixedTypes_Byte(ByteEnum testEnum, bool arg1, int arg2) + { + Assert.IsTrue(true); + } + #endregion + + public enum SByteEnum : sbyte { Alfa = sbyte.MinValue, Beta, Gamma, Delta, Epsilon } + public enum ByteEnum : byte { Alfa, Beta, Gamma, Delta, Epsilon } + public enum ShortEnum : short { Alfa = byte.MaxValue + 1, Beta, Gamma, Delta, Epsilon } + public enum UShortEnum : ushort { Alfa = short.MaxValue + 1, Beta, Gamma, Delta, Epsilon } + public enum IntEnum { Alfa = ushort.MaxValue + 1, Beta, Gamma, Delta, Epsilon } + public enum UIntEnum : uint { Alfa = ((uint)int.MaxValue) + 1, Beta, Gamma, Delta, Epsilon } + public enum LongEnum : long { Alfa = ((long)uint.MaxValue) + 1, Beta, Gamma, Delta, Epsilon } + public enum ULongEnum : ulong { Alfa = ((ulong)long.MaxValue) + 1, Beta, Gamma, Delta, Epsilon } + } +} diff --git a/test/E2ETests/TestAssets/DataSourceTestProject/ITestDataSourceTests/DataRowTests_NonSerializablePaths.cs b/test/E2ETests/TestAssets/DataSourceTestProject/ITestDataSourceTests/DataRowTests_NonSerializablePaths.cs new file mode 100644 index 0000000000..34e22fca3b --- /dev/null +++ b/test/E2ETests/TestAssets/DataSourceTestProject/ITestDataSourceTests/DataRowTests_NonSerializablePaths.cs @@ -0,0 +1,22 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. + +namespace DataSourceTestProject.ITestDataSourceTests +{ + using Microsoft.VisualStudio.TestTools.UnitTesting; + + using System; + + [TestClass] + public class DataRowTests_NonSerializablePaths + { + [TestMethod] + [DataRow(typeof(string))] + [DataRow(typeof(int))] + [DataRow(typeof(DataRowTests_Enums))] + public void DataRowNonSerializable(Type type) + { + Assert.IsTrue(true); + } + } +} diff --git a/test/E2ETests/TestAssets/DataSourceTestProject/ITestDataSourceTests/DataRowTests_Regular.cs b/test/E2ETests/TestAssets/DataSourceTestProject/ITestDataSourceTests/DataRowTests_Regular.cs new file mode 100644 index 0000000000..95c2851bcd --- /dev/null +++ b/test/E2ETests/TestAssets/DataSourceTestProject/ITestDataSourceTests/DataRowTests_Regular.cs @@ -0,0 +1,79 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. + +namespace DataSourceTestProject.ITestDataSourceTests +{ + using Microsoft.VisualStudio.TestTools.UnitTesting; + + using System; + + [TestClass] + public class Regular_DataRowTests + { + [TestMethod] + [DataRow(10)] + [DataRow(20)] + [DataRow(30)] + [DataRow(40)] + public void DataRow1(int i) + { + Assert.IsTrue(i != 0); + } + + [TestMethod] + [DataRow(10, "String parameter", true, false)] + [DataRow(20, "String parameter", true, false)] + [DataRow(30, "String parameter", true, false)] + [DataRow(40, "String parameter", true, false)] + public void DataRow2(int i, string s, bool b1, bool b2) + { + Assert.IsTrue(i != 200); + } + + [TestCategory("DataRowOptionalInvalidArguments")] + [TestMethod] + [ExpectedException(typeof(System.Reflection.TargetParameterCountException))] + [DataRow()] + [DataRow(2)] + [DataRow(2, "DerivedRequiredArgument", "DerivedOptionalArgument", "DerivedExtraArgument")] + public void DataRowTestMethodFailsWithInvalidArguments(int i1, string requiredString, string s1 = null) + { + Assert.Fail(); + } + + + [TestMethod] + [DataRow(10.01d, 20.01d)] + [DataRow(10.02d, 20.02d)] + public void DataRowTestDouble(double value1, double value2) + { + Assert.IsTrue(value1 > 10d); + Assert.IsTrue(value2 > 20d); + } + + [TestMethod] + [DataRow(1, (byte)10, 10, 10U, 10L, 10UL, 10F, 10D, "10")] + [DataRow(2, (byte)10, 10, 10U, 10L, 10UL, 10F, 10D, "10")] + [DataRow(3, (byte)10, 10, 10U, 10L, 10UL, 10F, 10D, "10")] + [DataRow(4, (byte)10, 10, 10U, 10L, 10UL, 10F, 10D, "10")] + public void DataRowTestMixed(int index, byte b, int i, uint u, long l, ulong ul, float f, double d, string s) + { + Assert.AreEqual(10, b); + Assert.AreEqual(10, i); + Assert.AreEqual(10U, u); + Assert.AreEqual(10L, l); + Assert.AreEqual(10UL, ul); + Assert.AreEqual(10F, f); + Assert.AreEqual(10D, d); + Assert.AreEqual("10", s); + } + + [TestMethod] + [DataRow("john.doe@example.com", "abc123", null)] + [DataRow("john.doe@example.com", "abc123", "/unit/test")] + public void NullValueInData(string email, string password, string returnUrl) + { + + } + } +} diff --git a/test/E2ETests/TestAssets/DataSourceTestProject/UnitTest1.cs b/test/E2ETests/TestAssets/DataSourceTestProject/ITestDataSourceTests/DataSourceTests.cs similarity index 75% rename from test/E2ETests/TestAssets/DataSourceTestProject/UnitTest1.cs rename to test/E2ETests/TestAssets/DataSourceTestProject/ITestDataSourceTests/DataSourceTests.cs index f444c78a00..ae1fc4743c 100644 --- a/test/E2ETests/TestAssets/DataSourceTestProject/UnitTest1.cs +++ b/test/E2ETests/TestAssets/DataSourceTestProject/ITestDataSourceTests/DataSourceTests.cs @@ -1,12 +1,14 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. +// Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT license. See LICENSE file in the project root for full license information. -namespace DataSourceTestProject +namespace DataSourceTestProject.ITestDataSourceTests { using Microsoft.VisualStudio.TestTools.UnitTesting; + using System; + [TestClass] - public class UnitTest1 + public class DataRowTests_Regular { public TestContext TestContext { @@ -20,4 +22,4 @@ public void CsvTestMethod() Assert.AreEqual(1, TestContext.DataRow["Item1"]); } } -} \ No newline at end of file +} diff --git a/test/E2ETests/TestAssets/DataSourceTestProject/ITestDataSourceTests/DynamicDataTests.cs b/test/E2ETests/TestAssets/DataSourceTestProject/ITestDataSourceTests/DynamicDataTests.cs new file mode 100644 index 0000000000..525e1ce1ee --- /dev/null +++ b/test/E2ETests/TestAssets/DataSourceTestProject/ITestDataSourceTests/DynamicDataTests.cs @@ -0,0 +1,42 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. + +namespace DataSourceTestProject.ITestDataSourceTests +{ + using Microsoft.VisualStudio.TestTools.UnitTesting; + + using System; + using System.Collections.Generic; + + [TestClass] + public class DynamicDataTests + { + [DataTestMethod()] + [DynamicData(nameof(GetParseUserDatas), DynamicDataSourceType.Method)] + public void DynamicDataTest(string userDatas, User expectedUser) + { + // Prepare + var srv = new UserService(); + + // Act + var user = srv.ParseUserDatas(userDatas); + + // Assert + Assert.AreNotSame(user, expectedUser); + Assert.AreEqual(user.FirstName, expectedUser.FirstName); + Assert.AreEqual(user.LastName, expectedUser.LastName); + } + + public static IEnumerable GetParseUserDatas() + { + yield return new object[] { + "John;Doe", + new User() + { + FirstName = "John", + LastName = "Doe" + } + }; + } + } +} diff --git a/test/E2ETests/TestAssets/ReferencedProjectFromDataSourceTest/ReferencedProjectFromDataSourceTest.csproj b/test/E2ETests/TestAssets/ReferencedProjectFromDataSourceTest/ReferencedProjectFromDataSourceTest.csproj new file mode 100644 index 0000000000..7f4f98b98c --- /dev/null +++ b/test/E2ETests/TestAssets/ReferencedProjectFromDataSourceTest/ReferencedProjectFromDataSourceTest.csproj @@ -0,0 +1,7 @@ + + + + net452 + + + diff --git a/test/E2ETests/TestAssets/ReferencedProjectFromDataSourceTest/User.cs b/test/E2ETests/TestAssets/ReferencedProjectFromDataSourceTest/User.cs new file mode 100644 index 0000000000..9957914e73 --- /dev/null +++ b/test/E2ETests/TestAssets/ReferencedProjectFromDataSourceTest/User.cs @@ -0,0 +1,26 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. + +namespace DataSourceTestProject.ITestDataSourceTests +{ + public class User + { + public string LastName { get; set; } + + public string FirstName { get; set; } + } + + public class UserService + { + public User ParseUserDatas(string datas) + { + var splittedDatas = datas.Split(';'); + + return new User() + { + FirstName = splittedDatas[0], + LastName = splittedDatas[1] + }; + } + } +}