public void IntStronglyTypedIdDeserializeFromJSON(IntStronglyTypedIdTestData 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, SerializationFixture.JsonSerializerOptions); 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 var stronglyTypedId = JsonSerializer.Deserialize <IntStronglyTypedId>(inTestData.SerializedTestData, SerializationFixture.JsonSerializerOptions); stronglyTypedId.Should().BeEquivalentTo(inTestData.InstanceTestData); } }
public void IntStronglyTypedIdSerializeToJSON(IntStronglyTypedIdTestData 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")) { //SerializationSystemTextJsonFixture.Serializer.Serialize(inTestData.InstanceTestData).Should().Be(inTestData.SerializedTestData); JsonSerializer.Serialize(inTestData.InstanceTestData, SerializationFixture.JsonSerializerOptions).Should().Be(inTestData.SerializedTestData); } else { //SerializationSystemTextJsonFixture.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, SerializationFixture.JsonSerializerOptions).Should().BeOfType(typeof(string), "the serializer should have returned a string representation of the InstanceTestData "); JsonSerializer.Serialize(inTestData.InstanceTestData, SerializationFixture.JsonSerializerOptions).Should().MatchRegex("^-{0,1}\\d+$"); } }