public void SerializationSucceeds1(string _, string didDocumentFileContents) { if (_ is null) { throw new ArgumentNullException(nameof(_)); } var typeMap = new Dictionary <string, Type>(ServiceConverterFactory.DefaultTypeMap); typeMap.Add("VerifiableCredentialService", typeof(VerifiableCredentialService)); var options = new JsonSerializerOptions { IgnoreNullValues = true, Converters = { new VerificationRelationshipConverterFactory(), new VerificationMethodConverter(), new ServiceConverterFactory(typeMap.ToImmutableDictionary()), new JsonLdContextConverter() } }; DidDocument?didDocument = JsonSerializer.Deserialize <DidDocument>(didDocumentFileContents, options); var roundTrippedDidDocument = JsonSerializer.Serialize(didDocument, options); Assert.NotNull(didDocument?.Id); Assert.NotNull(roundTrippedDidDocument); var comparer = new JsonElementComparer(); using var doc1 = JsonDocument.Parse(didDocumentFileContents); using var doc2 = JsonDocument.Parse(roundTrippedDidDocument); Assert.True(comparer.Equals(doc1.RootElement, doc2.RootElement)); }
public void SerializationSucceeds2(string _, string didDocumentFileContents) { if (_ is null) { throw new ArgumentNullException(nameof(_)); } var options = new JsonSerializerOptions { IgnoreNullValues = true, Converters = { new VerificationRelationshipConverterFactory(), new VerificationMethodConverter(), new ServiceConverterFactory(), new JsonLdContextConverter() } }; DidDocument?didDocument = JsonSerializer.Deserialize <DidDocument>(didDocumentFileContents, options); var roundTrippedDidDocument = JsonSerializer.Serialize(didDocument, options); Assert.NotNull(didDocument?.Id); Assert.NotNull(roundTrippedDidDocument); var comparer = new JsonElementComparer(); using var doc1 = JsonDocument.Parse(didDocumentFileContents); using var doc2 = JsonDocument.Parse(roundTrippedDidDocument); Assert.True(comparer.Equals(doc1.RootElement, doc2.RootElement)); }
public void RoundtripOneUriContext() { var options = new JsonSerializerOptions(); options.Converters.Add(new JsonLdContextConverter()); Context?context = JsonSerializer.Deserialize <Context>(OneUriContext, options); Assert.NotNull(context); var roundTrippedJson = JsonSerializer.Serialize(context, options); Assert.NotNull(roundTrippedJson); var comparer = new JsonElementComparer(); using var doc1 = JsonDocument.Parse(OneUriContext); using var doc2 = JsonDocument.Parse(roundTrippedJson); Assert.True(comparer.Equals(doc1.RootElement, doc2.RootElement)); }
public void RoundtripServiceTest1() { var options = new JsonSerializerOptions(); options.Converters.Add(new ServiceConverterFactory()); Service?service = JsonSerializer.Deserialize <Service>(TestService1, options); Assert.NotNull(service); var roundTrippedJson = JsonSerializer.Serialize(service, options); Assert.NotNull(roundTrippedJson); var comparer = new JsonElementComparer(); using var doc1 = JsonDocument.Parse(TestService1); using var doc2 = JsonDocument.Parse(roundTrippedJson); Assert.True(comparer.Equals(doc1.RootElement, doc2.RootElement)); }
public void FullDidDocumentTest() { var originalJson = TestDidDocument1; var typeMap = new Dictionary <string, Type>(ServiceConverterFactory.DefaultTypeMap); typeMap.Add("OpenIdConnectVersion1.0Service", typeof(OpenIdConnectVersion1)); typeMap.Add("CredentialRepositoryService", typeof(Service)); typeMap.Add("XdiService", typeof(Service)); typeMap.Add("AgentService", typeof(Service)); typeMap.Add("IdentityHub", typeof(Service)); typeMap.Add("MessagingService", typeof(Service)); typeMap.Add("SocialWebInboxService", typeof(SocialWebInboxService)); typeMap.Add("DidAuthPushModeVersion1", typeof(Service)); var options = new JsonSerializerOptions { IgnoreNullValues = true, Converters = { new VerificationRelationshipConverterFactory(), new VerificationMethodConverter(), new ServiceConverterFactory(typeMap.ToImmutableDictionary()), new JsonLdContextConverter() } }; var didObject = JsonSerializer.Deserialize <DidDocument>(originalJson, options); var roundTrippedJson = JsonSerializer.Serialize(didObject, options); var comparer = new JsonElementComparer(); using var doc1 = JsonDocument.Parse(originalJson); using var doc2 = JsonDocument.Parse(roundTrippedJson); Assert.True(comparer.Equals(doc1.RootElement, doc2.RootElement)); }