Is that possible to assert just the json attribute names rather than values.
Actual:
{
CartId = 0
ConvertedAt = null
Currency = BankCurrency
{
BaseCurrencyCode = null
BaseToGlobalRate = 0
BaseToQuoteRate = 0
GlobalCurrencyCode = null
}
CustomerIsGuest = False
}
Expected :
{
CartId = 418
ConvertedAt = 2019-07-22 04:01:49
Currency = BankCurrency
{
BaseCurrencyCode = null
BaseToGlobalRate = 1
BaseToQuoteRate = 1
GlobalCurrencyCode = "AUD"
}
CustomerIsGuest = False
}
So when compare above both actual
and expected
should tally.
Basically I wanted to compare above json .Net objects and check attribute names (structure) is correct rather than attribute values in there. If you see above actual and expected structure is tallying but not the values inside. I have used below but it still complaining.
TheReturnedContentModelIs(new UserResponse())
Validation:
public async Task TheReturnedContentModelIs<T>(T expected)
{
var responseString = await ResponseMessage.Content.ReadAsStringAsync();
var actual = JsonConvert.DeserializeObject<T>(responseString);
actual.Should()
.BeEquivalentTo(expected,
opt => opt.Using<object>(_ => { })
.When(e => e.RuntimeType.IsValueType)
.Using<string>(_ => { })
.WhenTypeIs<string>());