forked from FamilySearch/gedcomx-csharp
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- NamePart.
- Loading branch information
1 parent
7cc0443
commit d708473
Showing
5 changed files
with
114 additions
and
50 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
using System.Xml.Serialization; | ||
|
||
using Gx.Common; | ||
using Gx.Conclusion; | ||
using Gx.Records; | ||
|
||
using Gx.Types; | ||
|
||
using Newtonsoft.Json; | ||
|
||
using NUnit.Framework; | ||
|
||
namespace Gedcomx.Model.Test | ||
{ | ||
/// <summary> | ||
/// Test calss for <see cref="NamePart"/> | ||
/// </summary> | ||
[TestFixture] | ||
public class NamePartTest | ||
{ | ||
[Test] | ||
public void NamePartEmpty() | ||
{ | ||
var sut = new NamePart(); | ||
|
||
VerifyXmlSerialization(sut); | ||
VerifyJsonSerialization(sut); | ||
} | ||
|
||
[Test] | ||
public void NamePartFilled() | ||
{ | ||
var sut = new NamePart | ||
{ | ||
// ExtensibleData | ||
Id = "A-1", | ||
// NamePart | ||
Value = "John", | ||
KnownType = NamePartType.Given, | ||
Fields = { new Field() }, | ||
Qualifiers = { new Qualifier() } | ||
}; | ||
|
||
VerifyXmlSerialization(sut); | ||
VerifyJsonSerialization(sut); | ||
} | ||
|
||
private static void VerifyXmlSerialization(NamePart sut) | ||
{ | ||
var serializer = new XmlSerializer(typeof(NamePart)); | ||
using var stream = new MemoryStream(); | ||
serializer.Serialize(stream, sut); | ||
|
||
stream.Seek(0, SeekOrigin.Begin); | ||
var result = new StreamReader(stream).ReadToEnd(); | ||
result.ShouldContain(sut); | ||
} | ||
|
||
private static void VerifyJsonSerialization(NamePart sut) | ||
{ | ||
JsonSerializerSettings jsonSettings = new() | ||
{ | ||
NullValueHandling = NullValueHandling.Ignore | ||
}; | ||
|
||
Assert.DoesNotThrow(() => JsonConvert.DeserializeObject<NamePart>(JsonConvert.SerializeObject(sut, jsonSettings), jsonSettings)); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters