Skip to content

Fixed a bug in ITestDataSource data deserialization #864

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 5, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions TestFx.sln
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
22 changes: 5 additions & 17 deletions src/Adapter/MSTest.CoreAdapter/Helpers/DataSerializationHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -70,9 +71,8 @@ public static string[] Serialize(object[] data)
/// Deserialzes the data serialzed by <see cref="Serialize(object[])" /> method.
/// </summary>
/// <param name="serializedData">Serialized data array to deserialize.</param>
/// <param name="assemblies">Assemblies that serialized types defined in.</param>
/// <returns>Deserialized array.</returns>
public static object[] Deserialize(string[] serializedData, params Assembly[] assemblies)
public static object[] Deserialize(string[] serializedData)
{
if (serializedData == null || serializedData.Length % 2 != 0)
{
Expand All @@ -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))
Expand All @@ -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)
Expand All @@ -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));
}

Expand Down
189 changes: 189 additions & 0 deletions test/E2ETests/DiscoveryAndExecutionTests/TestDataSourceTests.cs
Original file line number Diff line number Diff line change
@@ -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 ([email protected],abc123,)",
"NullValueInData ([email protected],abc123,/unit/test)");

Assert.That.FailedTestCount(testResults, 0);
}
}
}
30 changes: 0 additions & 30 deletions test/E2ETests/Smoke.E2E.Tests/DataSourceTests.cs

This file was deleted.

2 changes: 1 addition & 1 deletion test/E2ETests/Smoke.E2E.Tests/Smoke.E2E.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
<Compile Include="CompatTests.cs" />
<Compile Include="TestProjectFSharpTests.cs" />
<Compile Include="CustomTestExecutionExtensibilityTests.cs" />
<Compile Include="DataSourceTests.cs" />
<Compile Include="TestDataSourceTests.cs" />
<Compile Include="DeploymentTests.cs" />
<Compile Include="DesktopCSharpCLITests.cs" />
<Compile Include="ParallelExecutionTests.cs" />
Expand Down
Loading