用于数据驱动测试的动态 JsonProperty 反序列化
dynamic JsonProperty deserialise for data driven tests
我正在尝试自动化一些测试,我正在寻找一种方法来添加动态 Json属性
例如,我可以有这样的 Json 响应
"data": {
"ADA": {
"id": 2010,
},
"BTC": {
"id": 1,
},
"ETH": {
"id": 1027,
},
public class QuotesLatest
{
[JsonProperty("status")]
public Status Status { get; set; }
[JsonProperty("data")]
public Data Data { get; set; }
}
public class CryptoCurrency
{
[JsonProperty("id")]
public int Id { get; set; }
[JsonProperty("name")]
public string Name { get; set; }
}
我希望能够动态访问每个加密货币,而不是像这样做并且必须列出每个潜在值
public class Data
{
[JsonProperty("BTC")]
public CryptoCurrency BTC { get; set; }
[JsonProperty("ETH")]
public CryptoCurrency ETH { get; set; }
[JsonProperty("ADA")]
public CryptoCurrency ADA { get; set; }
[JsonProperty("DOGE")]
public CryptoCurrency DOGE { get; set; }
}
我想做这样的事情,但我不确定如何使 Json属性 动态化?
public class Data
{
public List<CryptoCurrency> CryptoCurrency {get; set;}
}
我希望能够使用数据驱动测试动态断言每个类似于下面的内容
Assert.That(quotesLatest.Data.CryptoCurrency[{cryptocurreny}].Id, Is.EqualTo(id));
public class QuotesLatest
{
// I am assuming this is the class where you have the 'Data' property.
[JsonProperty("data")]
public Dictionary<string, CryptoCurrency> Data { get; set; }
}
其中加密货币:
public class CryptoCurrency
{
[JsonProperty("id")]
public int Id { get; set; }
}
quotesLatest.Data["BTC"].Id
returns 1
对我来说。
我正在尝试自动化一些测试,我正在寻找一种方法来添加动态 Json属性
例如,我可以有这样的 Json 响应
"data": {
"ADA": {
"id": 2010,
},
"BTC": {
"id": 1,
},
"ETH": {
"id": 1027,
},
public class QuotesLatest
{
[JsonProperty("status")]
public Status Status { get; set; }
[JsonProperty("data")]
public Data Data { get; set; }
}
public class CryptoCurrency
{
[JsonProperty("id")]
public int Id { get; set; }
[JsonProperty("name")]
public string Name { get; set; }
}
我希望能够动态访问每个加密货币,而不是像这样做并且必须列出每个潜在值
public class Data
{
[JsonProperty("BTC")]
public CryptoCurrency BTC { get; set; }
[JsonProperty("ETH")]
public CryptoCurrency ETH { get; set; }
[JsonProperty("ADA")]
public CryptoCurrency ADA { get; set; }
[JsonProperty("DOGE")]
public CryptoCurrency DOGE { get; set; }
}
我想做这样的事情,但我不确定如何使 Json属性 动态化?
public class Data
{
public List<CryptoCurrency> CryptoCurrency {get; set;}
}
我希望能够使用数据驱动测试动态断言每个类似于下面的内容
Assert.That(quotesLatest.Data.CryptoCurrency[{cryptocurreny}].Id, Is.EqualTo(id));
public class QuotesLatest
{
// I am assuming this is the class where you have the 'Data' property.
[JsonProperty("data")]
public Dictionary<string, CryptoCurrency> Data { get; set; }
}
其中加密货币:
public class CryptoCurrency
{
[JsonProperty("id")]
public int Id { get; set; }
}
quotesLatest.Data["BTC"].Id
returns 1
对我来说。