0

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>());
Shabar
  • 2,617
  • 11
  • 57
  • 98
  • Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the [ask] page for help clarifying this question. – Nkosi Jul 23 '19 at 10:52
  • The above is not JSON. So I am confused about what JSON you are referring to. – Nkosi Jul 23 '19 at 10:58
  • Show the full Test – Nkosi Jul 23 '19 at 10:59
  • @Nkosi Added more details as you mentioned – Shabar Jul 23 '19 at 11:07

0 Answers0