Skip to content

Commit

Permalink
get rid of fluent assertions (#104166)
Browse files Browse the repository at this point in the history
  • Loading branch information
adamsitnik authored Jun 30, 2024
1 parent 33896ac commit 9a4329d
Show file tree
Hide file tree
Showing 22 changed files with 253 additions and 265 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public void ArraySerializableValueType()
{
nint[] nints = [42, 43, 44];
object deserialized = Deserialize(Serialize(nints));
deserialized.Should().BeEquivalentTo(nints);
Assert.Equal(nints, deserialized);
}

[Fact]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,11 @@ public void DeserializeStoredObjects(object value, TypeSerializableValue[] seria
if (deserialized is StringComparer)
{
// StringComparer derived classes are not public and they don't serialize the actual type.
value.Should().BeAssignableTo<StringComparer>();
Assert.IsAssignableFrom<StringComparer>(value);
}
else
{
deserialized.Should().BeOfType(value.GetType());
Assert.IsType(value.GetType(), deserialized);
}

bool isSamePlatform = i == platformIndex;
Expand All @@ -60,7 +60,7 @@ public void BasicObjectsRoundtrip(
&& value is Array array
&& array.Length > 0)
{
deserialized.Should().NotBeSameAs(value);
Assert.NotSame(value, deserialized);
}

EqualityExtensions.CheckEquals(value, deserialized, isSamePlatform: true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,6 @@ public abstract class ComparerTests<T> : SerializationTest<T> where T : ISeriali
public void NullableComparers_Roundtrip(string expectedType, object obj)
{
object roundTrip = RoundTrip(obj);
roundTrip.GetType().Name.Should().Be(expectedType);
Assert.Equal(expectedType, roundTrip.GetType().Name);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,7 @@ public void ValueTypeReferencesSelf()

// This fails in the SerializationConstructor in BinaryFormattedObject's deserializer because the
// type isn't convertible to NodeWithNodeStruct. In BinaryFormatter it fails with fixups.
Action action = () => Deserialize(stream);
action.Should().Throw<SerializationException>();
Assert.Throws<SerializationException>(() => Deserialize(stream));
}

[Fact]
Expand All @@ -51,8 +50,7 @@ public void ValueTypeReferencesSelf2()

stream.Position = 0;

Action action = () => Deserialize(stream);
action.Should().Throw<SerializationException>();
Assert.Throws<SerializationException>(() => Deserialize(stream));
}

[Fact]
Expand All @@ -74,8 +72,7 @@ public void ValueTypeReferencesSelf3()
// Both deserializers create this where every boxed struct is the exact same boxed instance.
stream.Position = 0;

Action action = () => Deserialize(stream);
action.Should().Throw<SerializationException>();
Assert.Throws<SerializationException>(() => Deserialize(stream));
}

[Fact]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ public void SelfReferencingISerializableObject()

var deserialized = (NodeWithValueISerializable)Deserialize(stream);

deserialized.Value.Should().Be(42);
deserialized.Node.Should().BeSameAs(deserialized);
Assert.Equal(42, deserialized.Value);
Assert.Same(deserialized, deserialized.Node);
}

[Fact]
Expand All @@ -44,9 +44,9 @@ public void SimpleLoopingISerializableObjects()
Stream stream = Serialize(node1);

var deserialized = (NodeWithValueISerializable)Deserialize(stream);
deserialized.Value.Should().Be(42);
deserialized.Node!.Value.Should().Be(43);
deserialized.Node.Node.Should().BeSameAs(deserialized);
Assert.Equal(42, deserialized.Value);
Assert.Equal(43, deserialized.Node!.Value);
Assert.Same(deserialized, deserialized.Node.Node);
}

[Fact]
Expand All @@ -60,8 +60,8 @@ public virtual void BackPointerToISerializableClass()

// BinaryFormatter doesn't handle this round trip.
var deserialized = (ClassWithValueISerializable<StructWithReferenceISerializable<object>>)Deserialize(stream);
deserialized.Value.Value.Should().Be(42);
deserialized.Value.Reference.Should().BeSameAs(deserialized);
Assert.Equal(42, deserialized.Value.Value);
Assert.Same(deserialized, deserialized.Value.Reference);
}

[Fact]
Expand All @@ -75,10 +75,10 @@ public void BackPointerToArray()
Stream stream = Serialize(nints);
var deserialized = (StructWithSelfArrayReferenceISerializable[])Deserialize(stream);

deserialized[0].Value.Should().Be(42);
deserialized[1].Value.Should().Be(43);
deserialized[2].Value.Should().Be(44);
deserialized[0].Array.Should().BeSameAs(deserialized);
Assert.Equal(42, deserialized[0].Value);
Assert.Equal(43, deserialized[1].Value);
Assert.Equal(44, deserialized[2].Value);
Assert.Same(deserialized, deserialized[0].Array);
}

[Fact]
Expand All @@ -89,8 +89,8 @@ public void BackPointerFromNestedStruct()

NodeWithNodeStruct deserialized = (NodeWithNodeStruct)Deserialize(Serialize(node));

deserialized.NodeStruct.Node.Should().BeSameAs(deserialized);
deserialized.Value.Should().Be("Root");
Assert.Same(deserialized, deserialized.NodeStruct.Node);
Assert.Equal("Root", deserialized.Value);
}

[Fact]
Expand All @@ -103,9 +103,9 @@ public void IndirectBackPointerFromNestedStruct()

NodeWithNodeStruct deserialized = (NodeWithNodeStruct)Deserialize(Serialize(node));

deserialized.Value.Should().Be("Root");
deserialized.NodeStruct.Node!.NodeStruct.Node.Should().BeSameAs(deserialized);
deserialized.NodeStruct.Node!.Value.Should().Be("Node2");
Assert.Equal("Root", deserialized.Value);
Assert.Same(deserialized, deserialized.NodeStruct.Node!.NodeStruct.Node);
Assert.Equal("Node2", deserialized.NodeStruct.Node!.Value);
}

[Fact]
Expand All @@ -115,13 +115,13 @@ public void BinaryTreeCycles()
root.Left = root;

BinaryTreeNode deserialized = (BinaryTreeNode)Deserialize(Serialize(root));
deserialized.Left.Should().BeSameAs(deserialized);
deserialized.Right.Should().BeNull();
Assert.Same(deserialized, deserialized.Left);
Assert.Null(deserialized.Right);

root.Right = root.Left;
deserialized = (BinaryTreeNode)Deserialize(Serialize(root));
deserialized.Left.Should().BeSameAs(deserialized);
deserialized.Right.Should().BeSameAs(deserialized);
Assert.Same(deserialized, deserialized.Left);
Assert.Same(deserialized, deserialized.Right);
}

[Fact]
Expand All @@ -131,12 +131,12 @@ public void BinaryTreeCycles_ISerializable()
root.Left = root;

var deserialized = (BinaryTreeNodeISerializable)Deserialize(Serialize(root));
deserialized.Left.Should().BeSameAs(deserialized);
deserialized.Right.Should().BeNull();
Assert.Same(deserialized, deserialized.Left);
Assert.Null(deserialized.Right);

root.Right = root.Left;
deserialized = (BinaryTreeNodeISerializable)Deserialize(Serialize(root));
deserialized.Left.Should().BeSameAs(deserialized);
deserialized.Right.Should().BeSameAs(deserialized);
Assert.Same(deserialized, deserialized.Left);
Assert.Same(deserialized, deserialized.Right);
}
}
Loading

0 comments on commit 9a4329d

Please sign in to comment.