diff --git a/TestFx.sln b/TestFx.sln index e787ced7eb..714c2d1dcf 100644 --- a/TestFx.sln +++ b/TestFx.sln @@ -168,6 +168,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ParallelMethodsTestProject" EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ParallelClassesTestProject", "test\E2ETests\TestAssets\ParallelTestClass\ParallelClassesTestProject.csproj", "{CD0CA7CD-CED3-45FF-9F36-B1C8DF7A9220}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DataSourceTestProject", "test\E2ETests\TestAssets\DataSourceTestProject\DataSourceTestProject.csproj", "{5A4967CD-B527-4D43-81C2-4CA90EE10222}" +EndProject Global GlobalSection(SharedMSBuildProjectFiles) = preSolution src\TestFramework\Extension.Shared\Extension.Shared.projitems*{272ca5e1-8e81-4825-9e47-86cce02f700d}*SharedItemsImports = 13 @@ -909,6 +911,30 @@ Global {CD0CA7CD-CED3-45FF-9F36-B1C8DF7A9220}.Release|x64.Build.0 = Release|Any CPU {CD0CA7CD-CED3-45FF-9F36-B1C8DF7A9220}.Release|x86.ActiveCfg = Release|Any CPU {CD0CA7CD-CED3-45FF-9F36-B1C8DF7A9220}.Release|x86.Build.0 = Release|Any CPU + {5A4967CD-B527-4D43-81C2-4CA90EE10222}.Code Analysis Debug|Any CPU.ActiveCfg = Debug|Any CPU + {5A4967CD-B527-4D43-81C2-4CA90EE10222}.Code Analysis Debug|Any CPU.Build.0 = Debug|Any CPU + {5A4967CD-B527-4D43-81C2-4CA90EE10222}.Code Analysis Debug|ARM.ActiveCfg = Debug|Any CPU + {5A4967CD-B527-4D43-81C2-4CA90EE10222}.Code Analysis Debug|ARM.Build.0 = Debug|Any CPU + {5A4967CD-B527-4D43-81C2-4CA90EE10222}.Code Analysis Debug|x64.ActiveCfg = Debug|Any CPU + {5A4967CD-B527-4D43-81C2-4CA90EE10222}.Code Analysis Debug|x64.Build.0 = Debug|Any CPU + {5A4967CD-B527-4D43-81C2-4CA90EE10222}.Code Analysis Debug|x86.ActiveCfg = Debug|Any CPU + {5A4967CD-B527-4D43-81C2-4CA90EE10222}.Code Analysis Debug|x86.Build.0 = Debug|Any CPU + {5A4967CD-B527-4D43-81C2-4CA90EE10222}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {5A4967CD-B527-4D43-81C2-4CA90EE10222}.Debug|Any CPU.Build.0 = Debug|Any CPU + {5A4967CD-B527-4D43-81C2-4CA90EE10222}.Debug|ARM.ActiveCfg = Debug|Any CPU + {5A4967CD-B527-4D43-81C2-4CA90EE10222}.Debug|ARM.Build.0 = Debug|Any CPU + {5A4967CD-B527-4D43-81C2-4CA90EE10222}.Debug|x64.ActiveCfg = Debug|Any CPU + {5A4967CD-B527-4D43-81C2-4CA90EE10222}.Debug|x64.Build.0 = Debug|Any CPU + {5A4967CD-B527-4D43-81C2-4CA90EE10222}.Debug|x86.ActiveCfg = Debug|Any CPU + {5A4967CD-B527-4D43-81C2-4CA90EE10222}.Debug|x86.Build.0 = Debug|Any CPU + {5A4967CD-B527-4D43-81C2-4CA90EE10222}.Release|Any CPU.ActiveCfg = Release|Any CPU + {5A4967CD-B527-4D43-81C2-4CA90EE10222}.Release|Any CPU.Build.0 = Release|Any CPU + {5A4967CD-B527-4D43-81C2-4CA90EE10222}.Release|ARM.ActiveCfg = Release|Any CPU + {5A4967CD-B527-4D43-81C2-4CA90EE10222}.Release|ARM.Build.0 = Release|Any CPU + {5A4967CD-B527-4D43-81C2-4CA90EE10222}.Release|x64.ActiveCfg = Release|Any CPU + {5A4967CD-B527-4D43-81C2-4CA90EE10222}.Release|x64.Build.0 = Release|Any CPU + {5A4967CD-B527-4D43-81C2-4CA90EE10222}.Release|x86.ActiveCfg = Release|Any CPU + {5A4967CD-B527-4D43-81C2-4CA90EE10222}.Release|x86.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -963,6 +989,7 @@ Global {655001BB-C00F-4EF7-A324-7F7C48656D35} = {F2D0BF2C-38F2-4244-80E3-4AAD1C3F4C89} {4004757A-0082-4410-B94A-6166B20F153C} = {D53BD452-F69F-4FB3-8B98-386EDA28A4C8} {CD0CA7CD-CED3-45FF-9F36-B1C8DF7A9220} = {D53BD452-F69F-4FB3-8B98-386EDA28A4C8} + {5A4967CD-B527-4D43-81C2-4CA90EE10222} = {D53BD452-F69F-4FB3-8B98-386EDA28A4C8} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {31E0F4D5-975A-41CC-933E-545B2201FAF9} diff --git a/src/Adapter/PlatformServices.Desktop/Data/CsvDataConnection.cs b/src/Adapter/PlatformServices.Desktop/Data/CsvDataConnection.cs index eb5dd01729..9972c24dbe 100644 --- a/src/Adapter/PlatformServices.Desktop/Data/CsvDataConnection.cs +++ b/src/Adapter/PlatformServices.Desktop/Data/CsvDataConnection.cs @@ -22,6 +22,7 @@ internal sealed class CsvDataConnection : TestDataConnection { // Template used to map from a filename to a DB connection string private const string CsvConnectionTemplate = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source={0};Persist Security Info=False;Extended Properties=\"text;HDR=YES;FMT=Delimited\""; + private const string CsvConnectionTemplate64 = "Provider=Microsoft.Ace.OLEDB.12.0;Data Source={0};Persist Security Info=False;Extended Properties=\"text;HDR=YES;FMT=Delimited\""; private string fileName; @@ -93,7 +94,16 @@ public DataTable ReadTable(string tableName, IEnumerable columns, int maxRows) using (OleDbCommand command = new OleDbCommand()) { // We have to use the name of the folder which contains the CSV file in the connection string - connection.ConnectionString = string.Format(CultureInfo.InvariantCulture, CsvConnectionTemplate, Path.GetDirectoryName(fullPath)); + // If target platform is x64, then use CsvConnectionTemplate64 connection string. + if (IntPtr.Size == 8) + { + connection.ConnectionString = string.Format(CultureInfo.InvariantCulture, CsvConnectionTemplate64, Path.GetDirectoryName(fullPath)); + } + else + { + connection.ConnectionString = string.Format(CultureInfo.InvariantCulture, CsvConnectionTemplate, Path.GetDirectoryName(fullPath)); + } + WriteDiagnostics("Connection String: {0}", connection.ConnectionString); // We have to open the connection now, before we try to quote diff --git a/test/E2ETests/Smoke.E2E.Tests/DataSourceTests.cs b/test/E2ETests/Smoke.E2E.Tests/DataSourceTests.cs new file mode 100644 index 0000000000..2224f2f6f2 --- /dev/null +++ b/test/E2ETests/Smoke.E2E.Tests/DataSourceTests.cs @@ -0,0 +1,28 @@ +// 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( + "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 0e0ddd9c83..6005ad1c50 100644 --- a/test/E2ETests/Smoke.E2E.Tests/Smoke.E2E.Tests.csproj +++ b/test/E2ETests/Smoke.E2E.Tests/Smoke.E2E.Tests.csproj @@ -39,6 +39,7 @@ + diff --git a/test/E2ETests/TestAssets/DataSourceTestProject/DataSourceTestProject.csproj b/test/E2ETests/TestAssets/DataSourceTestProject/DataSourceTestProject.csproj new file mode 100644 index 0000000000..5b3ec27ed2 --- /dev/null +++ b/test/E2ETests/TestAssets/DataSourceTestProject/DataSourceTestProject.csproj @@ -0,0 +1,30 @@ + + + + ..\..\..\..\ + + + + net452 + false + false + $(TestFxRoot)artifacts\TestAssets\ + + + + + + + + + + + Always + + + + + + + + diff --git a/test/E2ETests/TestAssets/DataSourceTestProject/UnitTest1.cs b/test/E2ETests/TestAssets/DataSourceTestProject/UnitTest1.cs new file mode 100644 index 0000000000..16c9c03d98 --- /dev/null +++ b/test/E2ETests/TestAssets/DataSourceTestProject/UnitTest1.cs @@ -0,0 +1,23 @@ +// 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 +{ + using Microsoft.VisualStudio.TestTools.UnitTesting; + + [TestClass] + public class UnitTest1 + { + public TestContext TestContext + { + get; + set; + } + + [TestMethod, DataSource("Microsoft.VisualStudio.TestTools.DataSource.CSV", "a.csv", "a#csv", DataAccessMethod.Sequential)] + public void CsvTestMethod() + { + Assert.AreEqual(1, TestContext.DataRow["Item1"]); + } + } +} \ No newline at end of file diff --git a/test/E2ETests/TestAssets/DataSourceTestProject/a.csv b/test/E2ETests/TestAssets/DataSourceTestProject/a.csv new file mode 100644 index 0000000000..c7ef7a1b19 --- /dev/null +++ b/test/E2ETests/TestAssets/DataSourceTestProject/a.csv @@ -0,0 +1,5 @@ +Item1,Item2,Item3 +1,2,3 +4,5,6 +1,7,8 +9,10,11