Skip to content

Commit 09d4d38

Browse files
authored
Remove unsafe serialization testing (#3197)
1 parent 6ea87f0 commit 09d4d38

File tree

1 file changed

+6
-37
lines changed

1 file changed

+6
-37
lines changed

src/Microsoft.Data.SqlClient/tests/FunctionalTests/SqlExceptionTest.cs

Lines changed: 6 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -15,52 +15,24 @@ public class SqlExceptionTest
1515
private const string badServer = "92B96911A0BD43E8ADA4451031F7E7CF";
1616

1717
[Fact]
18-
[ActiveIssue("12161", TestPlatforms.AnyUnix)]
1918
public void SerializationTest()
2019
{
2120
SqlException e = CreateException();
2221
string json = JsonConvert.SerializeObject(e);
2322

24-
var settings = new JsonSerializerSettings()
25-
{
26-
TypeNameHandling = TypeNameHandling.All,
27-
};
28-
29-
// TODO: Deserialization fails on Unix with "Member 'ClassName' was not found."
23+
var settings = new JsonSerializerSettings();
3024
var sqlEx = JsonConvert.DeserializeObject<SqlException>(json, settings);
3125

3226
Assert.Equal(e.ClientConnectionId, sqlEx.ClientConnectionId);
3327
Assert.Equal(e.StackTrace, sqlEx.StackTrace);
3428
}
3529

36-
#if NETFRAMEWORK
37-
[Fact]
38-
[ActiveIssue("12161", TestPlatforms.AnyUnix)]
39-
public static void SqlExcpetionSerializationTest()
40-
{
41-
var formatter = new BinaryFormatter();
42-
SqlException e = CreateException();
43-
using (var stream = new MemoryStream())
44-
{
45-
try
46-
{
47-
formatter.Serialize(stream, e);
48-
stream.Position = 0;
49-
var e2 = (SqlException)formatter.Deserialize(stream);
50-
}
51-
catch (Exception ex)
52-
{
53-
Assert.Fail($"Unexpected Exception occurred: {ex.Message}");
54-
}
55-
}
56-
}
57-
#endif
58-
5930
[Fact]
6031
public void JSONSerializationTest()
6132
{
6233
string clientConnectionId = "90cdab4d-2145-4c24-a354-c8ccff903542";
63-
string json = @"{""ClassName"":""Microsoft.Data.SqlClient.SqlException"","
34+
string json = @"{"
35+
+ @"""ClassName"":""Microsoft.Data.SqlClient.SqlException"","
6436
+ @"""Message"":""A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: TCP Provider, error: 40 - Could not open a connection to SQL Server)"","
6537
+ @"""Data"":{""HelpLink.ProdName"":""Microsoft SQL Server"","
6638
+ @"""HelpLink.EvtSrc"":""MSSQLServer"","
@@ -79,13 +51,10 @@ public void JSONSerializationTest()
7951
+ @"""Source"":""Core .Net SqlClient Data Provider"","
8052
+ @"""WatsonBuckets"":null,"
8153
+ @"""Errors"":null,"
82-
+ @"""ClientConnectionId"":""90cdab4d-2145-4c24-a354-c8ccff903542""}";
83-
84-
var settings = new JsonSerializerSettings()
85-
{
86-
TypeNameHandling = TypeNameHandling.All,
87-
};
54+
+ @"""ClientConnectionId"":""90cdab4d-2145-4c24-a354-c8ccff903542"""
55+
+ @"}";
8856

57+
var settings = new JsonSerializerSettings();
8958
var sqlEx = JsonConvert.DeserializeObject<SqlException>(json, settings);
9059
Assert.IsType<SqlException>(sqlEx);
9160
Assert.Equal(clientConnectionId, sqlEx.ClientConnectionId.ToString());

0 commit comments

Comments
 (0)