public void IntIdSerializeToJSON(IntStronglyTypedIDSerializationTestData inTestData) { // ToDo low priority localize the unit test's exception's message if (inTestData == null) { throw new ArgumentNullException($"{nameof(inTestData)} argument should never be null"); } // new AbstractStronglyTypedID<int>() have random Values, two sets of test data have fixed, non-random integers, the rest are random if (inTestData.SerializedTestData.Equals("-2147483648") || inTestData.SerializedTestData.Equals("-1") || inTestData.SerializedTestData.Equals("0") || inTestData.SerializedTestData.Equals("2147483647") || inTestData.SerializedTestData.Equals("1234567")) { Fixture.Serializer.Serialize(inTestData.InstanceTestData).Should().Be(inTestData.SerializedTestData); // JsonSerializer.Serialize(inTestData.InstanceTestData, Fixture.JsonSerializerOptions).Should().Be(inTestData.SerializedTestData); } else { Fixture.Serializer.Serialize(inTestData.InstanceTestData).Should().MatchRegex("^[0-9A-Fa-f]{8}-?([0-9A-Fa-f]{4}-?){3}[0-9A-Fa-f]{12}$"); // JsonSerializer.Serialize(inTestData.InstanceTestData, Fixture.JsonSerializerOptions).Should().BeOfType(typeof(string), "the serializer should have returned a string representation of the InstanceTestData "); // JsonSerializer.Serialize(inTestData.InstanceTestData, Fixture.JsonSerializerOptions).Should().MatchRegex("^-{0,1}\\d+$"); } }
public void IntIdDeserializeFromJSON(IntStronglyTypedIDSerializationTestData inTestData) { // ToDo low priority localize the unit test's exception's message if (inTestData == null) { throw new ArgumentNullException($"{nameof(inTestData)} argument should never be null"); } if (String.IsNullOrEmpty(inTestData.SerializedTestData)) { Action act = () => JsonSerializer.Deserialize <IntStronglyTypedID>(inTestData.SerializedTestData); act.Should().Throw <System.Text.Json.JsonException>() .WithMessage("The input does not contain any JSON tokens.*"); } else { // ToDo: validate that non-integer strings throw an exception Fixture.Serializer.Deserialize <IntStronglyTypedID>(inTestData.SerializedTestData).Should().BeEquivalentTo(inTestData.InstanceTestData); // var stronglyTypedID = JsonSerializer.Deserialize<IntStronglyTypedID>(inTestData.SerializedTestData, Fixture.JsonSerializerOptions); // stronglyTypedID.Should().BeEquivalentTo(inTestData.InstanceTestData); } }