に、私は、出力アサートはJSON出力のためのC#Specflow
検証のためのコードを取得するAPIを検証するためにspecflowにテストを書いていますが
[Then(@"the customer details will be returned")]
public void ThenTheCustomerDetailsWillBeReturned()
{
var actualResponse = ScenarioContextWrapper.Response;
JObject jsonResult = new JObject();
jsonResult = JObject.Parse(actualResponse);
Assert.AreEqual("ABC008", jsonResult.GetType().GetProperty("CustomerCode").GetValue(jsonResult, null));
Assert.AreEqual("ABC Industry", jsonResult.GetType().GetProperty("CustomerName").GetValue(jsonResult, null));
}
である。しかし、「{」は、ランタイムを実行できませんように私は例外を取得していますヌル参照 "}"上のバインディング
APIの出力は
{{
"Pagination": {
"NumberOfItems": 1,
"PageSize": 200,
"PageNumber": 1,
"NumberOfPages": 1
},
"Items": [
{
"Addresses": [],
"CustomerCode": "ABC008",
"CustomerName": "ABC Industry",
"GSTVATNumber": null,
"BankName": null,
"BankBranch": null,
"BankAccount": null,
"Website": null,
"PhoneNumber": null,
"FaxNumber": null,
"MobileNumber": null,
"DDINumber": null,
"TollFreeNumber": null,
"Email": null,
"EmailCC": null,
"Currency": {
"CurrencyCode": "NZD",
"Description": "New Zealand, Dollars",
"Guid": "29252c92-3d0e-4eba-a613-f9c6c22ed3a8",
"LastModifiedOn": "2017-01-31T20:22:20.816Z"
},
"Notes": null,
"Taxable": true,
"XeroContactId": null,
"SalesPerson": null,
"DiscountRate": null,
"PrintPackingSlipInsteadOfInvoice": null,
"PrintInvoice": null,
"StopCredit": false,
"Obsolete": false,
"XeroSalesAccount": null,
"XeroCostOfGoodsAccount": null,
"SellPriceTier": "",
"SellPriceTierReference": null,
"CustomerType": "",
"PaymentTerm": "",
"ContactFirstName": null,
"ContactLastName": null,
"SourceId": null,
"CreatedBy": "[email protected]",
"CreatedOn": "2017-02-05T18:50:53.697Z",
"Guid": "15145a60-8688-48a5-b849-ab66da3c0288",
"LastModifiedOn": "2017-02-05T18:50:53.697Z"
}
]
}}
あるご質問の元が一杯になっていないので、誰かがcustomercodeためのアサートに
おかげ
は、プロパティ名を確認してください。おそらくそれは理解するのに役立ちます:jsonResult.GetType()。GetProperties()。ToList()。ForEach(x => Console.WriteLine(x.Name)); – KernelMode
@KernelModeはい、それはプロパティ名を持っていません、なぜわかりません、どうすればjson出力をアサートできますか? –
私は答えの例を – KernelMode