Skip to content

Commit

Permalink
SDK update (#30992)
Browse files Browse the repository at this point in the history
* SDK update

* Remove tests using BinaryFormatter

---------

Co-authored-by: Brice Lambson <[email protected]>
  • Loading branch information
mitchdenny and bricelam authored Jun 1, 2023
1 parent 30d689e commit 729f882
Show file tree
Hide file tree
Showing 3 changed files with 2 additions and 108 deletions.
4 changes: 2 additions & 2 deletions global.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
{
"sdk": {
"version": "8.0.100-preview.5.23265.3",
"version": "8.0.100-preview.6.23279.4",
"allowPrerelease": true,
"rollForward": "latestMajor"
},
"tools": {
"dotnet": "8.0.100-preview.5.23265.3",
"dotnet": "8.0.100-preview.6.23279.4",
"runtimes": {
"aspnetcore": [
"7.0.3"
Expand Down
27 changes: 0 additions & 27 deletions test/EFCore.Design.Tests/DesignExceptionTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,31 +25,4 @@ public void OperationException_exposes_public_string_and_inner_exception_constru
Assert.Equal("Foo", ex.Message);
Assert.Same(inner, ex.InnerException);
}

[ConditionalFact]
public void Deserialized_OperationException_can_be_serialized_and_deserialized_again()
{
var transportedException = SerializeAndDeserialize(
SerializeAndDeserialize(
new OperationException(
"But somehow the vital connection is made",
new Exception("Bang!"))));

Assert.Equal("But somehow the vital connection is made", transportedException.Message);
Assert.Equal("Bang!", transportedException.InnerException.Message);
}

private TException SerializeAndDeserialize<TException>(TException exception)
where TException : Exception
{
var stream = new MemoryStream();
var formatter = new BinaryFormatter();

#pragma warning disable SYSLIB0011 // Issue https://github.com/dotnet/runtime/issues/39289 tracks finding an alternative to BinaryFormatter
formatter.Serialize(stream, exception);
stream.Seek(0, SeekOrigin.Begin);

return (TException)formatter.Deserialize(stream);
#pragma warning restore SYSLIB0011
}
}
79 changes: 0 additions & 79 deletions test/EFCore.Tests/ExceptionTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,19 +30,6 @@ public void RetryLimitExceededException_exposes_public_string_and_inner_exceptio
Assert.Same(inner, ex.InnerException);
}

[ConditionalFact]
public void Deserialized_RetryLimitExceededException_can_be_serialized_and_deserialized_again()
{
var transportedException = SerializeAndDeserialize(
SerializeAndDeserialize(
new RetryLimitExceededException(
"But somehow the vital connection is made",
new Exception("Bang!"))));

Assert.Equal("But somehow the vital connection is made", transportedException.Message);
Assert.Equal("Bang!", transportedException.InnerException.Message);
}

[ConditionalFact]
public void DbUpdateException_exposes_public_empty_constructor()
=> new DbUpdateException();
Expand All @@ -62,31 +49,6 @@ public void DbUpdateException_exposes_public_string_and_inner_exception_construc
Assert.Same(inner, ex.InnerException);
}

[ConditionalFact]
public void Deserialized_DbUpdateException_can_be_serialized_and_deserialized_again()
{
var transportedException = SerializeAndDeserialize(
SerializeAndDeserialize(
new DbUpdateException("But somehow the vital connection is made")));

Assert.Equal("But somehow the vital connection is made", transportedException.Message);
}

[ConditionalFact]
public void Deserialized_DbUpdateException_can_be_serialized_and_deserialized_again_with_entries()
{
var transportedException = SerializeAndDeserialize(
SerializeAndDeserialize(
new DbUpdateException(
"But somehow the vital connection is made",
new Exception("Bang!"),
new IUpdateEntry[] { new FakeUpdateEntry() })));

Assert.Equal("But somehow the vital connection is made", transportedException.Message);
Assert.Equal("Bang!", transportedException.InnerException.Message);
Assert.Empty(transportedException.Entries); // Because the entries cannot be serialized
}

[ConditionalFact]
public void DbUpdateConcurrencyException_exposes_public_empty_constructor()
=> new DbUpdateConcurrencyException();
Expand All @@ -106,33 +68,6 @@ public void DbUpdateConcurrencyException_exposes_public_string_and_inner_excepti
Assert.Same(inner, ex.InnerException);
}

[ConditionalFact]
public void Deserialized_DbUpdateConcurrencyException_can_be_serialized_and_deserialized_again()
{
var transportedException = SerializeAndDeserialize(
SerializeAndDeserialize(
new DbUpdateConcurrencyException("But somehow the vital connection is made")));

Assert.Equal(
"But somehow the vital connection is made",
transportedException.Message);
}

[ConditionalFact]
public void Deserialized_DbUpdateConcurrencyException_can_be_serialized_and_deserialized_again_with_entries()
{
var transportedException = SerializeAndDeserialize(
SerializeAndDeserialize(
new DbUpdateConcurrencyException(
"But somehow the vital connection is made",
new Exception("Bang!"),
new IUpdateEntry[] { new FakeUpdateEntry() })));

Assert.Equal("But somehow the vital connection is made", transportedException.Message);
Assert.Equal("Bang!", transportedException.InnerException.Message);
Assert.Empty(transportedException.Entries); // Because the entries cannot be serialized
}

[ConditionalFact]
public void DbUpdateException_exposes_public_string_and_entries_constructor()
{
Expand Down Expand Up @@ -221,18 +156,4 @@ private static IEntityType CreateEntityType()
model.AddEntityType(typeof(object), owned: false, ConfigurationSource.Convention);
return model.FinalizeModel().FindEntityType(typeof(object));
}

private TException SerializeAndDeserialize<TException>(TException exception)
where TException : Exception
{
var stream = new MemoryStream();
var formatter = new BinaryFormatter();

#pragma warning disable SYSLIB0011 // Issue https://github.com/dotnet/runtime/issues/39289 tracks finding an alternative to BinaryFormatter
formatter.Serialize(stream, exception);
stream.Seek(0, SeekOrigin.Begin);

return (TException)formatter.Deserialize(stream);
#pragma warning restore SYSLIB0011
}
}

0 comments on commit 729f882

Please sign in to comment.