-
Notifications
You must be signed in to change notification settings - Fork 69
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #930 from WildernessLabs/feature/microjson-dictionary
Feature/microjson dictionary
- Loading branch information
Showing
11 changed files
with
309 additions
and
23 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
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
60 changes: 60 additions & 0 deletions
60
...ies_and_Frameworks/Serialization.MicroJson/Tests/MicroJson.Unit.Tests/CloudEntityTests.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,60 @@ | ||
using Meadow.Cloud; | ||
using Meadow.Foundation.Serialization; | ||
using Meadow.Update; | ||
using System.Collections.Generic; | ||
using Xunit; | ||
|
||
namespace Unit.Tests; | ||
|
||
public class CloudEntityTests | ||
{ | ||
[Fact] | ||
public void UpdateMessageSerializationTest() | ||
{ | ||
UpdateMessage message = new() | ||
{ | ||
|
||
}; | ||
|
||
var json = MicroJson.Serialize(message); | ||
} | ||
|
||
[Fact] | ||
public void MeadowCommandSerializationTest() | ||
{ | ||
var command = new MeadowCommand("command name", | ||
new Dictionary<string, object> | ||
{ | ||
{ "field 1", 23 }, | ||
{ "field 2", "foo" }, | ||
{ "field 3", true }, | ||
{ "field 4", 42.2d } | ||
}); | ||
|
||
var json = MicroJson.Serialize(command); | ||
} | ||
|
||
[Fact] | ||
public void MeadowCommandDeserializationTest() | ||
{ | ||
var expected = new Dictionary<string, object> | ||
{ | ||
{ "field 1", 23L }, | ||
{ "field 2", "foo" }, | ||
{ "field 3", true }, | ||
{ "field 4", 42.2d } | ||
}; | ||
|
||
var json = "{\"field 1\":23,\"field 2\":\"foo\",\"field 3\":true,\"field 4\":42.2}"; | ||
var result = MicroJson.Deserialize<Dictionary<string, object>>(json); | ||
|
||
Assert.NotNull(result); | ||
Assert.Equal(4, result.Count); | ||
foreach (var kvp in expected) | ||
{ | ||
Assert.True(result.ContainsKey(kvp.Key)); | ||
// this fails because the boxed '23' values arent-'t equat | ||
// Assert.True(result[kvp.Key] == kvp.Value, $"{result[kvp.Key]} != {kvp.Value}"); | ||
} | ||
} | ||
} |
16 changes: 16 additions & 0 deletions
16
...raries_and_Frameworks/Serialization.MicroJson/Tests/MicroJson.Unit.Tests/MenuJsonTests.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,16 @@ | ||
using Meadow.Foundation.Serialization; | ||
using Xunit; | ||
|
||
namespace Unit.Tests; | ||
|
||
public class MenuJsonTests | ||
{ | ||
[Fact] | ||
public void DeserializeMenuTest() | ||
{ | ||
var json = Inputs.GetInputResource("menu.json"); | ||
var result = MicroJson.Deserialize<MenuContainer>(json); | ||
|
||
Assert.NotNull(result); | ||
} | ||
} |
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
50 changes: 50 additions & 0 deletions
50
...ries_and_Frameworks/Serialization.MicroJson/Tests/MicroJson.Unit.Tests/PuzzleJsonTests.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,50 @@ | ||
using Meadow.Foundation.Serialization; | ||
using System.Collections.Generic; | ||
using Xunit; | ||
|
||
namespace Unit.Tests; | ||
|
||
public class PuzzleJsonTests | ||
{ | ||
[Fact] | ||
public void DeserializePuzzlesAsArrayTest() | ||
{ | ||
var json = Inputs.GetInputResource("puzzles.json"); | ||
var result = MicroJson.Deserialize<Puzzle[]>(json); | ||
|
||
Assert.NotNull(result); | ||
Assert.Equal(10, result.Length); | ||
|
||
foreach (var puzzle in result) | ||
{ | ||
Assert.NotNull(puzzle); | ||
Assert.NotNull(puzzle.Pieces); | ||
|
||
foreach (var piece in puzzle.Pieces) | ||
{ | ||
Assert.NotNull(piece); | ||
} | ||
} | ||
} | ||
|
||
[Fact] | ||
public void DeserializePuzzlesAsListTest() | ||
{ | ||
var json = Inputs.GetInputResource("puzzles.json"); | ||
var result = MicroJson.Deserialize<List<Puzzle>>(json); | ||
|
||
Assert.NotNull(result); | ||
Assert.Equal(10, result.Count); | ||
|
||
foreach (var puzzle in result) | ||
{ | ||
Assert.NotNull(puzzle); | ||
Assert.NotNull(puzzle.Pieces); | ||
|
||
foreach (var piece in puzzle.Pieces) | ||
{ | ||
Assert.NotNull(piece); | ||
} | ||
} | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
..._and_Frameworks/Serialization.MicroJson/Tests/MicroJson.Unit.Tests/test types/MenuItem.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 Unit.Tests; | ||
|
||
internal class MenuContainer | ||
{ | ||
public MenuItem[] Menu { get; set; } | ||
} | ||
|
||
internal class MenuItem | ||
{ | ||
public string Text { get; set; } | ||
public string Id { get; set; } | ||
public string Type { get; set; } | ||
public int Value { get; set; } | ||
public MenuItem[] Sub { get; set; } | ||
} |
10 changes: 10 additions & 0 deletions
10
...and_Frameworks/Serialization.MicroJson/Tests/MicroJson.Unit.Tests/test types/PieceType.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,10 @@ | ||
namespace Unit.Tests; | ||
|
||
public enum PieceType | ||
{ | ||
Horizontal2, | ||
Horizontal3, | ||
Vertical2, | ||
Vertical3, | ||
Solve | ||
} |
25 changes: 25 additions & 0 deletions
25
...es_and_Frameworks/Serialization.MicroJson/Tests/MicroJson.Unit.Tests/test types/Puzzle.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,25 @@ | ||
using System.Collections.Generic; | ||
|
||
namespace Unit.Tests; | ||
|
||
public class Puzzle | ||
{ | ||
public List<PuzzlePiece> Pieces { get; set; } | ||
|
||
public int MinMoves { get; set; } = -1; | ||
public int NumBlocks => Pieces.Count; | ||
|
||
public Puzzle() | ||
{ | ||
Pieces = []; | ||
} | ||
|
||
public bool AddPiece(int x, int y, PieceType type) | ||
{ | ||
PuzzlePiece piece = new PuzzlePiece(x, y, type); | ||
|
||
Pieces.Add(piece); | ||
|
||
return true; | ||
} | ||
} |
Oops, something went wrong.