test: 增加 SMSHelper 发序列化测试

This commit is contained in:
Argo Zhang 2019-10-04 10:32:16 +08:00
parent f444db2ad6
commit af44b0ffeb
No known key found for this signature in database
GPG Key ID: 152E398953DDF19F
1 changed files with 30 additions and 0 deletions

View File

@ -0,0 +1,30 @@
using System.Text.Json;
using Xunit;
namespace Bootstrap.DataAccess
{
public class SMSHelperTest
{
[Fact]
public void Send()
{
var payload = "{\"code\":1,\"msg\":\"验证码发送成功\",\"data\":\"ec22128a2968928d2e146bd9836cde7b\"}";
var option = new JsonSerializerOptions();
option.PropertyNameCaseInsensitive = true;
var result = JsonSerializer.Deserialize<SMSResult>(payload, option);
Assert.Equal(1, result.Code);
var doc = JsonDocument.Parse(payload);
result.Code = doc.RootElement.GetProperty("code").GetInt32();
result.Data = doc.RootElement.GetProperty("data").GetString();
Assert.Equal(1, result.Code);
}
private class SMSResult
{
public int Code { get; set; }
public string Data { get; set; }
}
}
}