Skip to content

Commit

Permalink
Drop Shouldly assertions
Browse files Browse the repository at this point in the history
  • Loading branch information
Havret committed Jan 1, 2025
1 parent 3ec16d4 commit 67438ab
Show file tree
Hide file tree
Showing 12 changed files with 57 additions and 70 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
using System.Text.Json;
using System.Text.Json.Protobuf.Tests;
using Protobuf.System.Text.Json.Tests.Utils;
using Shouldly;
using Xunit;

namespace Protobuf.System.Text.Json.Tests;
Expand All @@ -25,8 +24,8 @@ public void Should_deserialize_a_new_version_of_a_message_using_the_old_version_
var deserialized = JsonSerializer.Deserialize<MessageWithVersionMismatch>(payload, jsonSerializerOptions);

// Assert
deserialized.ShouldNotBeNull();
deserialized.DoubleProperty.ShouldBe(msg.DoubleProperty);
Assert.NotNull(deserialized);
Assert.Equal(msg.DoubleProperty, deserialized.DoubleProperty);
}

[Fact]
Expand All @@ -44,7 +43,7 @@ public void Should_deserialize_the_old_version_of_a_message_using_the_new_versio
var deserialized = JsonSerializer.Deserialize<MessageWithVersionMismatchV2>(payload, jsonSerializerOptions);

// Assert
deserialized.ShouldNotBeNull();
deserialized.DoubleProperty.ShouldBe(msg.DoubleProperty);
Assert.NotNull(deserialized);
Assert.Equal(msg.DoubleProperty, deserialized.DoubleProperty);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
using System.Text.Json.Protobuf.Tests;
using System.Text.Json.Serialization;
using Protobuf.System.Text.Json.Tests.Utils;
using Shouldly;
using SmartAnalyzers.ApprovalTestsExtensions;
using Xunit;

Expand Down Expand Up @@ -51,7 +50,7 @@ public void Should_deserialize_message_with_complex_property()
var deserialized = JsonSerializer.Deserialize<MessageWithComplexProperty>(serialized, jsonSerializerOptions);

// Assert
deserialized.ShouldBeEquivalentTo(msg);
Assert.Equal(msg, deserialized);
}

[Fact]
Expand All @@ -74,6 +73,6 @@ public void Should_deserialize_message_with_complex_property_when_no_value_is_se
var deserialized = JsonSerializer.Deserialize<MessageWithComplexProperty>(serialized, jsonSerializerOptions);

// Assert
deserialized.ShouldBeEquivalentTo(msg);
Assert.Equal(msg, deserialized);
}
}
14 changes: 6 additions & 8 deletions test/Protobuf.System.Text.Json.Tests/MessageWithDurationTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
using System.Text.Json.Protobuf.Tests;
using Google.Protobuf.WellKnownTypes;
using Protobuf.System.Text.Json.Tests.Utils;
using Shouldly;
using SmartAnalyzers.ApprovalTestsExtensions;
using Xunit;

Expand Down Expand Up @@ -60,8 +59,8 @@ public void Should_serialize_and_deserialize_message_with_duration()
var deserialized = JsonSerializer.Deserialize<MessageWithDuration>(serialized, jsonSerializerOptions);

// Assert
deserialized.ShouldNotBeNull();
deserialized.ShouldBeEquivalentTo(msg);
Assert.NotNull(deserialized);
Assert.Equal(deserialized, msg);
}

[Fact]
Expand All @@ -76,8 +75,8 @@ public void Should_serialize_and_deserialize_message_with_duration_when_value_is
var deserialized = JsonSerializer.Deserialize<MessageWithDuration>(serialized, jsonSerializerOptions);

// Assert
deserialized.ShouldNotBeNull();
deserialized.ShouldBeEquivalentTo(msg);
Assert.NotNull(deserialized);
Assert.Equal(deserialized, msg);
}

[Fact]
Expand Down Expand Up @@ -125,8 +124,7 @@ public void Should_deserialize_duration_property_from_complex_object_when_TreatD
var deserialized = JsonSerializer.Deserialize<MessageWithDuration>(payload, jsonSerializerOptions);

// Assert
deserialized.ShouldNotBeNull();
deserialized.ShouldBeEquivalentTo(msg);

Assert.NotNull(deserialized);
Assert.Equal(deserialized, msg);
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
using System.Text.Json;
using System.Text.Json.Protobuf.Tests;
using Protobuf.System.Text.Json.Tests.Utils;
using Shouldly;
using SmartAnalyzers.ApprovalTestsExtensions;
using Xunit;

Expand Down Expand Up @@ -42,8 +41,8 @@ public void Should_deserialize_message_with_with_enum_field()
var deserialized = JsonSerializer.Deserialize<MessageWithEnum>(serialized, jsonSerializerOptions);

// Assert
deserialized.ShouldNotBeNull();
deserialized.ShouldBeEquivalentTo(msg);
Assert.NotNull(deserialized);
Assert.Equal(deserialized, msg);
}

[Fact]
Expand Down Expand Up @@ -106,8 +105,8 @@ public void Should_deserialize_message_with_enum_field_when_value_serialized_usi
var deserialized = JsonSerializer.Deserialize<MessageWithEnum>(serialized, jsonSerializerOptions);

// Assert
deserialized.ShouldNotBeNull();
deserialized.ShouldBeEquivalentTo(msg);
Assert.NotNull(deserialized);
Assert.Equal(deserialized, msg);
}

[Fact]
Expand All @@ -127,6 +126,6 @@ public void Should_throw_exception_when_string_enum_value_cannot_be_deserialized

// Act & Assert
var exception = Assert.Throws<JsonException>(() => JsonSerializer.Deserialize<MessageWithEnum>(invalidPayload, jsonSerializerOptions));
exception.Message.ShouldContain("'INVALID_OPTION' is not a valid value for type System.Text.Json.Protobuf.Tests.TestEnum.");
Assert.Contains("'INVALID_OPTION' is not a valid value for type System.Text.Json.Protobuf.Tests.TestEnum.", exception.Message);
}
}
5 changes: 2 additions & 3 deletions test/Protobuf.System.Text.Json.Tests/MessageWithMapsTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
using System.Text.Json.Protobuf.Tests;
using Google.Protobuf;
using Protobuf.System.Text.Json.Tests.Utils;
using Shouldly;
using SmartAnalyzers.ApprovalTestsExtensions;
using Xunit;

Expand Down Expand Up @@ -59,7 +58,7 @@ public void Should_deserialize_message_with_map_field()
var deserialized = JsonSerializer.Deserialize<MessageWithMaps>(serialized, jsonSerializerOptions);

// Assert
deserialized.ShouldNotBeNull();
deserialized.ShouldBeEquivalentTo(msg);
Assert.NotNull(deserialized);
Assert.Equal(deserialized, msg);
}
}
30 changes: 15 additions & 15 deletions test/Protobuf.System.Text.Json.Tests/MessageWithOneOfTests.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
using System.Text.Json;
using System.Text.Json.Protobuf.Tests;
using Protobuf.System.Text.Json.Tests.Utils;
using Shouldly;
using SmartAnalyzers.ApprovalTestsExtensions;
using Xunit;

Expand Down Expand Up @@ -58,10 +57,10 @@ public void Should_serialize_and_deserialize_message_with_one_of_when_value_is_s
var deserialized = JsonSerializer.Deserialize<MessageWithOneOf>(serialized, jsonSerializerOptions);

// Assert
deserialized.ShouldNotBeNull();
deserialized.Int32PropertyValue.ShouldBe(msg.Int32PropertyValue);
deserialized.Int64PropertyValue.ShouldBe(msg.Int64PropertyValue);
deserialized.PropertyCase.ShouldBe(msg.PropertyCase);
Assert.NotNull(deserialized);
Assert.Equal(msg.Int32PropertyValue, deserialized.Int32PropertyValue);
Assert.Equal(msg.Int64PropertyValue, deserialized.Int64PropertyValue);
Assert.Equal(msg.PropertyCase, deserialized.PropertyCase);
}

[Fact]
Expand All @@ -76,10 +75,11 @@ public void Should_serialize_and_deserialize_message_with_one_of_when_value_is_n
var deserialized = JsonSerializer.Deserialize<MessageWithOneOf>(serialized, jsonSerializerOptions);

// Assert
deserialized.ShouldNotBeNull();
deserialized.Int32PropertyValue.ShouldBe(msg.Int32PropertyValue);
deserialized.Int64PropertyValue.ShouldBe(msg.Int64PropertyValue);
deserialized.PropertyCase.ShouldBe(msg.PropertyCase);
Assert.NotNull(deserialized);
Assert.Equal(msg.Int32PropertyValue, deserialized.Int32PropertyValue);
Assert.Equal(msg.Int64PropertyValue, deserialized.Int64PropertyValue);
Assert.Equal(msg.PropertyCase, deserialized.PropertyCase);

}

[Fact]
Expand Down Expand Up @@ -132,9 +132,9 @@ public void Should_serialize_and_deserialize_message_with_optional_property_when
var deserialized = JsonSerializer.Deserialize<MessageWithOptionalProperty>(serialized, jsonSerializerOptions);

// Assert
deserialized.ShouldNotBeNull();
deserialized.Int32Property.ShouldBe(msg.Int32Property);
deserialized.HasInt32Property.ShouldBe(msg.HasInt32Property);
Assert.NotNull(deserialized);
Assert.Equal(msg.Int32Property, deserialized.Int32Property);
Assert.Equal(msg.HasInt32Property, deserialized.HasInt32Property);
}

[Fact]
Expand All @@ -149,8 +149,8 @@ public void Should_serialize_and_deserialize_message_with_optional_property_when
var deserialized = JsonSerializer.Deserialize<MessageWithOptionalProperty>(serialized, jsonSerializerOptions);

// Assert
deserialized.ShouldNotBeNull();
deserialized.Int32Property.ShouldBe(msg.Int32Property);
deserialized.HasInt32Property.ShouldBe(msg.HasInt32Property);
Assert.NotNull(deserialized);
Assert.Equal(msg.Int32Property, deserialized.Int32Property);
Assert.Equal(msg.HasInt32Property, deserialized.HasInt32Property);
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
using System.Text.Json;
using System.Text.Json.Protobuf.Tests;
using Protobuf.System.Text.Json.Tests.Utils;
using Shouldly;
using SmartAnalyzers.ApprovalTestsExtensions;
using Xunit;

Expand Down Expand Up @@ -62,11 +61,10 @@ public void Should_deserialize_message_with_repeated_list()
var deserialized = JsonSerializer.Deserialize<MessageWithRepeatedList>(serialized, jsonSerializerOptions);

// Assert
deserialized.ShouldNotBeNull();

deserialized.Int32List.ShouldBe(msg.Int32List);
deserialized.Int64List.ShouldBe(msg.Int64List);
deserialized.EnumList.ShouldBe(msg.EnumList);
deserialized.NestedMessageList.ShouldBe(msg.NestedMessageList);
Assert.NotNull(deserialized);
Assert.Equal(msg.Int32List, deserialized.Int32List);
Assert.Equal(msg.Int64List, deserialized.Int64List);
Assert.Equal(msg.EnumList, deserialized.EnumList);
Assert.Equal(msg.NestedMessageList, deserialized.NestedMessageList);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
using System.Text.Json.Serialization;
using Google.Protobuf.WellKnownTypes;
using Protobuf.System.Text.Json.Tests.Utils;
using Shouldly;
using SmartAnalyzers.ApprovalTestsExtensions;
using Xunit;

Expand Down Expand Up @@ -62,8 +61,8 @@ public void Should_serialize_and_deserialize_message_with_timestamp()
var deserialized = JsonSerializer.Deserialize<MessageWithTimestamp>(serialized, jsonSerializerOptions);

// Assert
deserialized.ShouldNotBeNull();
deserialized.ShouldBeEquivalentTo(msg);
Assert.NotNull(deserialized);
Assert.Equal(msg, deserialized);
}

[Fact]
Expand All @@ -78,8 +77,8 @@ public void Should_serialize_and_deserialize_message_with_timestamp_when_value_i
var deserialized = JsonSerializer.Deserialize<MessageWithTimestamp>(serialized, jsonSerializerOptions);

// Assert
deserialized.ShouldNotBeNull();
deserialized.ShouldBeEquivalentTo(msg);
Assert.NotNull(deserialized);
Assert.Equal(deserialized, msg);
}

[Fact]
Expand All @@ -95,7 +94,7 @@ public void Should_serialize_and_deserialize_message_with_timestamp_when_value_i
var deserialized = JsonSerializer.Deserialize<MessageWithTimestamp>(serialized, jsonSerializerOptions);

// Assert
deserialized.ShouldNotBeNull();
deserialized.ShouldBeEquivalentTo(msg);
Assert.NotNull(deserialized);
Assert.Equal(deserialized, msg);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
using System.Text.Json.Protobuf.Tests;
using System.Text.Json.Serialization;
using Protobuf.System.Text.Json.Tests.Utils;
using Shouldly;
using SmartAnalyzers.ApprovalTestsExtensions;
using Xunit;

Expand Down Expand Up @@ -74,7 +73,8 @@ public void Should_serialize_and_deserialize_message_with_well_known_types_when_


// Assert
deserialized.ShouldBe(msg);
Assert.Equal(msg, deserialized);

}

[Fact]
Expand All @@ -89,6 +89,6 @@ public void Should_serialize_and_deserialize_message_with_well_known_types_when_
var deserialized = JsonSerializer.Deserialize<MessageWithWellKnownTypes>(serialized, jsonSerializerOptions);

// Assert
deserialized.ShouldBe(msg);
Assert.Equal(msg, deserialized);
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using System.Text.Json;
using System.Text.Json.Protobuf.Tests;
using Shouldly;
using Xunit;

namespace Protobuf.System.Text.Json.Tests;
Expand Down Expand Up @@ -30,6 +29,6 @@ public void Should_support_PropertyNameCaseInsensitive_setting()

var deserialized = JsonSerializer.Deserialize<SimpleMessage>(payload, deserializerOptions);

deserialized.ShouldBeEquivalentTo(originalMessage);
Assert.Equal(originalMessage, deserialized);
}
}
12 changes: 5 additions & 7 deletions test/Protobuf.System.Text.Json.Tests/SchemaEvolutionTests.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.IO;
using System.Linq;
using System.Text.Json;
using System.Text.Json.Protobuf.Tests;
using System.Threading.Tasks;
using Protobuf.System.Text.Json.Tests.Utils;
using Shouldly;
using Xunit;

namespace Protobuf.System.Text.Json.Tests;
Expand All @@ -32,7 +29,8 @@ public void Should_be_able_to_deserialize_array_of_schema_v2_to_array_of_schema_
var deserialized = JsonSerializer.Deserialize<SchemaEvolutionV1[]>(serialized, jsonSerializerOptions);

// Assert
deserialized.ShouldHaveSingleItem();
Assert.NotNull(deserialized);
Assert.Single(deserialized);
}

[Fact]
Expand All @@ -54,7 +52,7 @@ public async Task Should_be_able_to_deserialize_array_of_schema_v2_to_array_of_s
var deserialized = JsonSerializer.Deserialize<SchemaEvolutionV1[]>(memoryStream, jsonSerializerOptions);

// Assert
deserialized.ShouldNotBeNull();
deserialized.Length.ShouldBe(schemaEvolutionV2.Count);
Assert.NotNull(deserialized);
Assert.Equal(schemaEvolutionV2.Count, deserialized.Length);
}
}
7 changes: 3 additions & 4 deletions test/Protobuf.System.Text.Json.Tests/SimpleMessageTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
using System.Text.Json.Protobuf.Tests;
using Google.Protobuf;
using Protobuf.System.Text.Json.Tests.Utils;
using Shouldly;
using SmartAnalyzers.ApprovalTestsExtensions;
using Xunit;

Expand Down Expand Up @@ -71,8 +70,8 @@ public void Should_deserialize_message_with_primitive_types()
var deserialized = JsonSerializer.Deserialize<SimpleMessage>(serialized, jsonSerializerOptions);

// Assert
deserialized.ShouldNotBeNull();
deserialized.Int32Property.ShouldBe(msg.Int32Property);
deserialized.Int64Property.ShouldBe(msg.Int64Property);
Assert.NotNull(deserialized);
Assert.Equal(msg.Int32Property, deserialized.Int32Property);
Assert.Equal(msg.Int64Property, deserialized.Int64Property);
}
}

0 comments on commit 67438ab

Please sign in to comment.