Skip to content

Commit

Permalink
Improved unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
loudenvier committed Nov 25, 2023
1 parent 62628d9 commit 4bfc78d
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 12 deletions.
42 changes: 30 additions & 12 deletions NetDotTests/DotNotationDeserializationTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -63,13 +63,38 @@ public void CanDeserializeRecordClass() {
}

[Fact]
public void CanDeserializeMasterDetailWithManyRecords() {
public void CanDeserializeMasterDetailWithManyItems() {
var master = DotNotation.Deserialize<Master>("""
Name=Master Record
details[0].Id=123
details[0].Tag=teste
details[0].Tag=test
details[2].Id=321
""");
Assert.NotNull(master);
Assert.Equal("Master Record", master.Name);
Assert.Equal(3, master.Details.Length);
Assert.Equal(123, master.Details[0].Id);
Assert.Equal("test", master.Details[0].Tag);
Assert.Null(master.Details[1]);
Assert.Equal(321, master.Details[2].Id);
Assert.Null(master.Details[2].Tag);
}
[Fact]
public void CanDeserializeMasterDetailRecordsWithManyItems() {
var master = DotNotation.Deserialize<MasterRec>("""
Name=Master Record
details[0].Id=123
details[0].Tag=test
details[2].Id=321
""");
Assert.NotNull(master);
Assert.Equal("Master Record", master.Name);
Assert.Equal(3, master.Details.Length);
Assert.Equal(123, master.Details[0].Id);
Assert.Equal("test", master.Details[0].Tag);
Assert.Null(master.Details[1]);
Assert.Equal(321, master.Details[2].Id);
Assert.Null(master.Details[2].Tag);
}
}

Expand All @@ -82,14 +107,7 @@ public class Detail {
public string Tag { get; set; }
}

/*public class PictureHttpUpload
{
public string Enable { get; set; }
public UploadServer[] UploadServerList { get; set; } = Array.Empty<UploadServer>();
}*/
public class UploadServer
{
public string Address { get; set; }
}

public record MasterRec(string Name, DetailRec[] Details);
public record DetailRec(int Id, string Tag);

}
2 changes: 2 additions & 0 deletions NetDotTests/DotNotationParsingtests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,8 @@ public void ArrayInRootCanBeSetWithArbitraryIndex() {
var pessoas = dict["pessoa"] as List<object?>;
Assert.NotNull(pessoas);
Assert.Equal(3, pessoas.Count);
Assert.Null(pessoas[0]);
Assert.Null(pessoas[1]);
Assert.Equal("felipe", pessoas[2]);
}
[Fact]
Expand Down

0 comments on commit 4bfc78d

Please sign in to comment.