public void Serialize_WinPointEvent() { var wpe = new WinPointEvent(Guid.NewGuid().ToString(), 1, DateTimeOffset.Now, "tid", "pid", "score", GameStatus.End); var actual = _serializer.Convert(wpe); Encoding.UTF8.GetString(actual.Data) .Should().Be($"{{\"Id\":\"{wpe.Id}\",\"Version\":1,\"OccuredDate\":\"{wpe.OccuredDate:yyyy/MM/dd HH:mm:ss}\",\"TeamId\":\"tid\",\"PlayerId\":\"pid\",\"NewScore\":\"score\",\"NewStatus\":\"End\"}}"); }
public void Serialize() { var le = new WinPointEvent("1", 1, DateTimeOffset.Now, "tid", "pid", "score", GameStatus.End); var opt = new JsonSerializerOptions(); opt.Converters.Add(new GameIdConverter()); opt.Converters.Add(new PlayersConverter()); opt.Converters.Add(new TeamConverter()); opt.Converters.Add(new WinPointEventConverter()); var actual = JsonSerializer.Serialize(le, opt); actual.Should().Be($"{{\"Id\":\"1\",\"Version\":1,\"OccuredDate\":\"{le.OccuredDate:yyyy/MM/dd HH:mm:ss}\",\"TeamId\":\"tid\",\"PlayerId\":\"pid\",\"NewScore\":\"score\",\"NewStatus\":\"End\"}}"); }
public void Deserialize() { var le = new WinPointEvent("1", 1, DateTimeOffset.Now, "tid", "pid", "score", GameStatus.End); var opt = new JsonSerializerOptions(); opt.Converters.Add(new GameIdConverter()); opt.Converters.Add(new PlayersConverter()); opt.Converters.Add(new TeamConverter()); opt.Converters.Add(new WinPointEventConverter()); var str = JsonSerializer.Serialize(le, opt); var actual = JsonSerializer.Deserialize <WinPointEvent>(str, opt); actual.Should().Be(le); }