Пример #1
0
 public void GuidIdSerializeToJSON(GuidStronglyTypedIDSerializationTestData 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");
     }
     // GUIDS are random, two sets of test data have fixed, non-random guids, the rest are random
     if (inTestData.SerializedTestData.StartsWith("\"0000", System.StringComparison.InvariantCulture) || inTestData.SerializedTestData.StartsWith("\"01234", System.StringComparison.InvariantCulture))
     {
         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().MatchRegex("^\"[0-9A-Fa-f]{8}-?([0-9A-Fa-f]{4}-?){3}[0-9A-Fa-f]{12}\"$");
     }
 }
Пример #2
0
 public void GuidIdDeserializeFromJSON(GuidStronglyTypedIDSerializationTestData 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 <GuidStronglyTypedID>(inTestData.SerializedTestData);
         act.Should().Throw <System.Text.Json.JsonException>()
         .WithMessage("The input does not contain any JSON tokens.*");
     }
     else if (inTestData.SerializedTestData.StartsWith("\"0000", System.StringComparison.InvariantCulture) || inTestData.SerializedTestData.StartsWith("\"01234", System.StringComparison.InvariantCulture))
     {
         Fixture.Serializer.Deserialize <GuidStronglyTypedID>(inTestData.SerializedTestData).Should().BeEquivalentTo(inTestData.InstanceTestData);
         // var stronglyTypedID = JsonSerializer.Deserialize<GuidStronglyTypedID>(inTestData.SerializedTestData, Fixture.JsonSerializerOptions);
         // stronglyTypedID.Should().BeEquivalentTo(inTestData.InstanceTestData);
     }
     else
     {
         // ToDo: validate that strings that don't match a Guid throw an exception
     }
 }