public unsafe void ShouldParse(string json) { byte[] bytes = Encoding.UTF8.GetBytes(json); fixed(byte *p = bytes) { var pctx = new ParseContext(p, bytes.Length); var stub = new AccountStub(); Assert.That(NewHandler.TryParseAccount(ref pctx, stub), Is.EqualTo(201)); } }
public unsafe void Should_parse_json() { var body = new { id = 123, email = "*****@*****.**", status = @"\u0432\u0441\u0451 \u0441\u043b\u043e\u0436\u043d\u043e", sex = "m", fname = "Jury", sname = "Soldatenkov", interests = new[] { "sex", "drugs", "rock'n'roll" }, likes = new object[] { new { id = 245, ts = 123533214 }, new { id = 123, ts = 123532514 }, }, premium = new { start = 1000, finish = 2000 } }; var stringBody = JsonConvert.SerializeObject(body); byte[] bytes = Encoding.UTF8.GetBytes(stringBody); fixed(byte *p = &bytes[0]) { ParseContext pctx = new ParseContext(p, bytes.Length); byte[] idBytes = Encoding.UTF8.GetBytes("123"); Console.WriteLine(stringBody); Console.WriteLine((byte)','); Console.WriteLine(string.Join(" ", bytes)); Console.WriteLine(string.Join(" ", idBytes)); var account = new AccountStub(); var result = NewHandler.TryParseAccount(ref pctx, account); Assert.That(result, Is.EqualTo(201)); Assert.That(account.id, Is.EqualTo(body.id)); Assert.That(account.email, Is.EqualTo(body.email)); Assert.That(account.sexStatus.IsMale(), Is.True); //Assert.That(account.fname, Is.EqualTo(body.fname)); Assert.That(account.sname, Is.EqualTo(body.sname)); //CollectionAssert.AreEquivalent(account.interests, body.interests); Assert.That(account.likes.Count, Is.EqualTo(body.likes.Length)); Assert.That(account.premium.start, Is.EqualTo(body.premium.start)); Assert.That(account.premium.finish, Is.EqualTo(body.premium.finish)); } }