-
-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Serialization also works and tests added
- Loading branch information
1 parent
83b07a9
commit 5c98192
Showing
4 changed files
with
49 additions
and
0 deletions.
There are no files selected for viewing
15 changes: 15 additions & 0 deletions
15
Tomlet.Tests/TestModelClasses/ComplexTestRecordWithAttributeMapping.cs
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,15 @@ | ||
namespace Tomlet.Tests.TestModelClasses | ||
{ | ||
public record ComplexTestRecordWithAttributeMapping | ||
{ | ||
[TomlProperty("string")] | ||
public string MyString { get; init; } | ||
public WidgetForThisComplexTestRecordWithAttributeMapping MyWidget { get; init; } | ||
} | ||
|
||
public record WidgetForThisComplexTestRecordWithAttributeMapping | ||
{ | ||
[TomlProperty("my_int")] | ||
public int MyInt { get; init; } | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
using Tomlet.Tests.TestModelClasses; | ||
using Xunit; | ||
|
||
namespace Tomlet.Tests | ||
{ | ||
public class TomlPropertyMappingTests | ||
{ | ||
[Fact] | ||
public void DeserializationWorks() | ||
{ | ||
var record = TomletMain.To<ComplexTestRecordWithAttributeMapping>(TestResources.ComplexTestRecordForAttributeMapping); | ||
Assert.Equal("Test", record.MyString); | ||
Assert.IsType<WidgetForThisComplexTestRecordWithAttributeMapping>(record.MyWidget); | ||
Assert.Equal(42, record.MyWidget.MyInt); | ||
} | ||
|
||
[Fact] | ||
public void SerializationWorks() | ||
{ | ||
var testString = TestResources.ComplexTestRecordForAttributeMapping.Trim(); | ||
var record = TomletMain.To<ComplexTestRecordWithAttributeMapping>(testString); | ||
var serialized = TomletMain.TomlStringFrom(record).Trim(); | ||
Assert.Equal(testString, serialized); | ||
} | ||
} | ||
} |
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