C# Unit Testing - Assertions on JSON





.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ height:90px;width:728px;box-sizing:border-box;
}







2















I am just playing around with some Json and Fluentassertions, I am able to make a call to an API successfully, get the results, deserialize them but for some reason when i get to do an assertion on the response its losing the data and it empty. I have debugged, can see the data flowing through and then losing it during assertion.



Any help appreciated.



{
[TestClass]
public class UnitTest1
{
HttpClient client = new HttpClient();

[TestMethod]
public void ActorNotInSeason6Episode1()
{
try
{
//test = extent.CreateTest("Test 1");
HttpResponseMessage respone = client.GetAsync("https://api.themoviedb.org/3/tv/1399/season/6/episode/1/credits?api_key=").Result;
Assert.IsTrue(respone.IsSuccessStatusCode.Equals(true));
string ResponseMessage = respone.Content.ReadAsStringAsync().Result;
Actors actors = JsonConvert.DeserializeObject<Actors>(ResponseMessage);
//var a = Actors.cast["cast"];
//var names = a.Children;
//var a = actors.cast.Children();


actors.cast.Should().Contain("Emilia Clarke", "Test");

}
catch(AssertFailedException)
{
Assert.Fail();

}
}

}
}



class Actors
{
public JArray cast { get; set; }
public JArray guest_stars { get; set; }

}
}


JSON



{[
{
"character": "Daenerys Targaryen",
"credit_id": "5256c8af19c2956ff60479f6",
"gender": 1,
"id": 1223786,
"name": "Emilia Clarke",
"order": 0,
"profile_path": "/lRSqMNNhPL4Ib1hAJxmDFBXHAMU.jpg"
}
]}









share|improve this question

























  • the JSON shown has no cast key. Is the JSON shown accurate?

    – Nkosi
    Nov 23 '18 at 17:05













  • When i make the call to the API the cast key is there {"cast": But JArray removes it i believe and just stores the above

    – Philip Kamuna
    Nov 23 '18 at 17:19











  • that does not sound accurate. The shown JSON does not match the Actors object model definition

    – Nkosi
    Nov 23 '18 at 17:22











  • This is the JSON when i check in Postman: {[ {"cast":[{ "character": "Daenerys Targaryen", "credit_id": "5256c8af19c2956ff60479f6", "gender": 1, "id": 1223786, "name": "Emilia Clarke", "order": 0, "profile_path": "/lRSqMNNhPL4Ib1hAJxmDFBXHAMU.jpg" } ]} When i debug and inspect cast in the model definition it is storing it without the {"cast":

    – Philip Kamuna
    Nov 23 '18 at 17:30













  • I called the API in the browser and got {"cast":[{"character":"Daenerys Targaryen",....

    – Nkosi
    Nov 23 '18 at 17:44


















2















I am just playing around with some Json and Fluentassertions, I am able to make a call to an API successfully, get the results, deserialize them but for some reason when i get to do an assertion on the response its losing the data and it empty. I have debugged, can see the data flowing through and then losing it during assertion.



Any help appreciated.



{
[TestClass]
public class UnitTest1
{
HttpClient client = new HttpClient();

[TestMethod]
public void ActorNotInSeason6Episode1()
{
try
{
//test = extent.CreateTest("Test 1");
HttpResponseMessage respone = client.GetAsync("https://api.themoviedb.org/3/tv/1399/season/6/episode/1/credits?api_key=").Result;
Assert.IsTrue(respone.IsSuccessStatusCode.Equals(true));
string ResponseMessage = respone.Content.ReadAsStringAsync().Result;
Actors actors = JsonConvert.DeserializeObject<Actors>(ResponseMessage);
//var a = Actors.cast["cast"];
//var names = a.Children;
//var a = actors.cast.Children();


actors.cast.Should().Contain("Emilia Clarke", "Test");

}
catch(AssertFailedException)
{
Assert.Fail();

}
}

}
}



class Actors
{
public JArray cast { get; set; }
public JArray guest_stars { get; set; }

}
}


JSON



{[
{
"character": "Daenerys Targaryen",
"credit_id": "5256c8af19c2956ff60479f6",
"gender": 1,
"id": 1223786,
"name": "Emilia Clarke",
"order": 0,
"profile_path": "/lRSqMNNhPL4Ib1hAJxmDFBXHAMU.jpg"
}
]}









share|improve this question

























  • the JSON shown has no cast key. Is the JSON shown accurate?

    – Nkosi
    Nov 23 '18 at 17:05













  • When i make the call to the API the cast key is there {"cast": But JArray removes it i believe and just stores the above

    – Philip Kamuna
    Nov 23 '18 at 17:19











  • that does not sound accurate. The shown JSON does not match the Actors object model definition

    – Nkosi
    Nov 23 '18 at 17:22











  • This is the JSON when i check in Postman: {[ {"cast":[{ "character": "Daenerys Targaryen", "credit_id": "5256c8af19c2956ff60479f6", "gender": 1, "id": 1223786, "name": "Emilia Clarke", "order": 0, "profile_path": "/lRSqMNNhPL4Ib1hAJxmDFBXHAMU.jpg" } ]} When i debug and inspect cast in the model definition it is storing it without the {"cast":

    – Philip Kamuna
    Nov 23 '18 at 17:30













  • I called the API in the browser and got {"cast":[{"character":"Daenerys Targaryen",....

    – Nkosi
    Nov 23 '18 at 17:44














2












2








2


0






I am just playing around with some Json and Fluentassertions, I am able to make a call to an API successfully, get the results, deserialize them but for some reason when i get to do an assertion on the response its losing the data and it empty. I have debugged, can see the data flowing through and then losing it during assertion.



Any help appreciated.



{
[TestClass]
public class UnitTest1
{
HttpClient client = new HttpClient();

[TestMethod]
public void ActorNotInSeason6Episode1()
{
try
{
//test = extent.CreateTest("Test 1");
HttpResponseMessage respone = client.GetAsync("https://api.themoviedb.org/3/tv/1399/season/6/episode/1/credits?api_key=").Result;
Assert.IsTrue(respone.IsSuccessStatusCode.Equals(true));
string ResponseMessage = respone.Content.ReadAsStringAsync().Result;
Actors actors = JsonConvert.DeserializeObject<Actors>(ResponseMessage);
//var a = Actors.cast["cast"];
//var names = a.Children;
//var a = actors.cast.Children();


actors.cast.Should().Contain("Emilia Clarke", "Test");

}
catch(AssertFailedException)
{
Assert.Fail();

}
}

}
}



class Actors
{
public JArray cast { get; set; }
public JArray guest_stars { get; set; }

}
}


JSON



{[
{
"character": "Daenerys Targaryen",
"credit_id": "5256c8af19c2956ff60479f6",
"gender": 1,
"id": 1223786,
"name": "Emilia Clarke",
"order": 0,
"profile_path": "/lRSqMNNhPL4Ib1hAJxmDFBXHAMU.jpg"
}
]}









share|improve this question
















I am just playing around with some Json and Fluentassertions, I am able to make a call to an API successfully, get the results, deserialize them but for some reason when i get to do an assertion on the response its losing the data and it empty. I have debugged, can see the data flowing through and then losing it during assertion.



Any help appreciated.



{
[TestClass]
public class UnitTest1
{
HttpClient client = new HttpClient();

[TestMethod]
public void ActorNotInSeason6Episode1()
{
try
{
//test = extent.CreateTest("Test 1");
HttpResponseMessage respone = client.GetAsync("https://api.themoviedb.org/3/tv/1399/season/6/episode/1/credits?api_key=").Result;
Assert.IsTrue(respone.IsSuccessStatusCode.Equals(true));
string ResponseMessage = respone.Content.ReadAsStringAsync().Result;
Actors actors = JsonConvert.DeserializeObject<Actors>(ResponseMessage);
//var a = Actors.cast["cast"];
//var names = a.Children;
//var a = actors.cast.Children();


actors.cast.Should().Contain("Emilia Clarke", "Test");

}
catch(AssertFailedException)
{
Assert.Fail();

}
}

}
}



class Actors
{
public JArray cast { get; set; }
public JArray guest_stars { get; set; }

}
}


JSON



{[
{
"character": "Daenerys Targaryen",
"credit_id": "5256c8af19c2956ff60479f6",
"gender": 1,
"id": 1223786,
"name": "Emilia Clarke",
"order": 0,
"profile_path": "/lRSqMNNhPL4Ib1hAJxmDFBXHAMU.jpg"
}
]}






c# unit-testing nunit assertion fluent-assertions






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 23 '18 at 17:19







Philip Kamuna

















asked Nov 23 '18 at 17:03









Philip KamunaPhilip Kamuna

314




314













  • the JSON shown has no cast key. Is the JSON shown accurate?

    – Nkosi
    Nov 23 '18 at 17:05













  • When i make the call to the API the cast key is there {"cast": But JArray removes it i believe and just stores the above

    – Philip Kamuna
    Nov 23 '18 at 17:19











  • that does not sound accurate. The shown JSON does not match the Actors object model definition

    – Nkosi
    Nov 23 '18 at 17:22











  • This is the JSON when i check in Postman: {[ {"cast":[{ "character": "Daenerys Targaryen", "credit_id": "5256c8af19c2956ff60479f6", "gender": 1, "id": 1223786, "name": "Emilia Clarke", "order": 0, "profile_path": "/lRSqMNNhPL4Ib1hAJxmDFBXHAMU.jpg" } ]} When i debug and inspect cast in the model definition it is storing it without the {"cast":

    – Philip Kamuna
    Nov 23 '18 at 17:30













  • I called the API in the browser and got {"cast":[{"character":"Daenerys Targaryen",....

    – Nkosi
    Nov 23 '18 at 17:44



















  • the JSON shown has no cast key. Is the JSON shown accurate?

    – Nkosi
    Nov 23 '18 at 17:05













  • When i make the call to the API the cast key is there {"cast": But JArray removes it i believe and just stores the above

    – Philip Kamuna
    Nov 23 '18 at 17:19











  • that does not sound accurate. The shown JSON does not match the Actors object model definition

    – Nkosi
    Nov 23 '18 at 17:22











  • This is the JSON when i check in Postman: {[ {"cast":[{ "character": "Daenerys Targaryen", "credit_id": "5256c8af19c2956ff60479f6", "gender": 1, "id": 1223786, "name": "Emilia Clarke", "order": 0, "profile_path": "/lRSqMNNhPL4Ib1hAJxmDFBXHAMU.jpg" } ]} When i debug and inspect cast in the model definition it is storing it without the {"cast":

    – Philip Kamuna
    Nov 23 '18 at 17:30













  • I called the API in the browser and got {"cast":[{"character":"Daenerys Targaryen",....

    – Nkosi
    Nov 23 '18 at 17:44

















the JSON shown has no cast key. Is the JSON shown accurate?

– Nkosi
Nov 23 '18 at 17:05







the JSON shown has no cast key. Is the JSON shown accurate?

– Nkosi
Nov 23 '18 at 17:05















When i make the call to the API the cast key is there {"cast": But JArray removes it i believe and just stores the above

– Philip Kamuna
Nov 23 '18 at 17:19





When i make the call to the API the cast key is there {"cast": But JArray removes it i believe and just stores the above

– Philip Kamuna
Nov 23 '18 at 17:19













that does not sound accurate. The shown JSON does not match the Actors object model definition

– Nkosi
Nov 23 '18 at 17:22





that does not sound accurate. The shown JSON does not match the Actors object model definition

– Nkosi
Nov 23 '18 at 17:22













This is the JSON when i check in Postman: {[ {"cast":[{ "character": "Daenerys Targaryen", "credit_id": "5256c8af19c2956ff60479f6", "gender": 1, "id": 1223786, "name": "Emilia Clarke", "order": 0, "profile_path": "/lRSqMNNhPL4Ib1hAJxmDFBXHAMU.jpg" } ]} When i debug and inspect cast in the model definition it is storing it without the {"cast":

– Philip Kamuna
Nov 23 '18 at 17:30







This is the JSON when i check in Postman: {[ {"cast":[{ "character": "Daenerys Targaryen", "credit_id": "5256c8af19c2956ff60479f6", "gender": 1, "id": 1223786, "name": "Emilia Clarke", "order": 0, "profile_path": "/lRSqMNNhPL4Ib1hAJxmDFBXHAMU.jpg" } ]} When i debug and inspect cast in the model definition it is storing it without the {"cast":

– Philip Kamuna
Nov 23 '18 at 17:30















I called the API in the browser and got {"cast":[{"character":"Daenerys Targaryen",....

– Nkosi
Nov 23 '18 at 17:44





I called the API in the browser and got {"cast":[{"character":"Daenerys Targaryen",....

– Nkosi
Nov 23 '18 at 17:44












2 Answers
2






active

oldest

votes


















3














Using the following strongly typed definitions based on the expected JSON from themoviedb



public partial class RootObject {
[JsonProperty("cast")]
public Cast Cast { get; set; }

[JsonProperty("crew")]
public Crew Crew { get; set; }

[JsonProperty("guest_stars")]
public Cast GuestStars { get; set; }

[JsonProperty("id")]
public long Id { get; set; }
}

public partial class Cast {
[JsonProperty("character")]
public string Character { get; set; }

[JsonProperty("credit_id")]
public string CreditId { get; set; }

[JsonProperty("gender")]
public long Gender { get; set; }

[JsonProperty("id")]
public long Id { get; set; }

[JsonProperty("name")]
public string Name { get; set; }

[JsonProperty("order")]
public long Order { get; set; }

[JsonProperty("profile_path")]
public string ProfilePath { get; set; }
}

public partial class Crew {
[JsonProperty("id")]
public long Id { get; set; }

[JsonProperty("credit_id")]
public string CreditId { get; set; }

[JsonProperty("name")]
public string Name { get; set; }

[JsonProperty("department")]
public string Department { get; set; }

[JsonProperty("job")]
public string Job { get; set; }

[JsonProperty("gender")]
public long Gender { get; set; }

[JsonProperty("profile_path")]
public string ProfilePath { get; set; }
}


You would need to do the following in your test



//...

var actors = JsonConvert.DeserializeObject<RootObject>(ResponseMessage);

//Assert
actors.Cast.Should().Contain(actor => actor.Name == "Emilia Clarke");





share|improve this answer































    0














    Here is fluentassertions extension for JSON, which contains many useful methods for asserting JSON:



    Available extension methods
    BeEquivalentTo()
    ContainSingleElement()
    ContainSubtree()
    HaveCount()
    HaveElement()
    HaveValue()
    MatchRegex()
    NotBeEquivalentTo()
    NotHaveElement()
    NotHaveValue()
    NotMatchRegex()



    I am not an author of this library.






    share|improve this answer
























      Your Answer






      StackExchange.ifUsing("editor", function () {
      StackExchange.using("externalEditor", function () {
      StackExchange.using("snippets", function () {
      StackExchange.snippets.init();
      });
      });
      }, "code-snippets");

      StackExchange.ready(function() {
      var channelOptions = {
      tags: "".split(" "),
      id: "1"
      };
      initTagRenderer("".split(" "), "".split(" "), channelOptions);

      StackExchange.using("externalEditor", function() {
      // Have to fire editor after snippets, if snippets enabled
      if (StackExchange.settings.snippets.snippetsEnabled) {
      StackExchange.using("snippets", function() {
      createEditor();
      });
      }
      else {
      createEditor();
      }
      });

      function createEditor() {
      StackExchange.prepareEditor({
      heartbeatType: 'answer',
      autoActivateHeartbeat: false,
      convertImagesToLinks: true,
      noModals: true,
      showLowRepImageUploadWarning: true,
      reputationToPostImages: 10,
      bindNavPrevention: true,
      postfix: "",
      imageUploader: {
      brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
      contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
      allowUrls: true
      },
      onDemand: true,
      discardSelector: ".discard-answer"
      ,immediatelyShowMarkdownHelp:true
      });


      }
      });














      draft saved

      draft discarded


















      StackExchange.ready(
      function () {
      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53450568%2fc-sharp-unit-testing-assertions-on-json%23new-answer', 'question_page');
      }
      );

      Post as a guest















      Required, but never shown

























      2 Answers
      2






      active

      oldest

      votes








      2 Answers
      2






      active

      oldest

      votes









      active

      oldest

      votes






      active

      oldest

      votes









      3














      Using the following strongly typed definitions based on the expected JSON from themoviedb



      public partial class RootObject {
      [JsonProperty("cast")]
      public Cast Cast { get; set; }

      [JsonProperty("crew")]
      public Crew Crew { get; set; }

      [JsonProperty("guest_stars")]
      public Cast GuestStars { get; set; }

      [JsonProperty("id")]
      public long Id { get; set; }
      }

      public partial class Cast {
      [JsonProperty("character")]
      public string Character { get; set; }

      [JsonProperty("credit_id")]
      public string CreditId { get; set; }

      [JsonProperty("gender")]
      public long Gender { get; set; }

      [JsonProperty("id")]
      public long Id { get; set; }

      [JsonProperty("name")]
      public string Name { get; set; }

      [JsonProperty("order")]
      public long Order { get; set; }

      [JsonProperty("profile_path")]
      public string ProfilePath { get; set; }
      }

      public partial class Crew {
      [JsonProperty("id")]
      public long Id { get; set; }

      [JsonProperty("credit_id")]
      public string CreditId { get; set; }

      [JsonProperty("name")]
      public string Name { get; set; }

      [JsonProperty("department")]
      public string Department { get; set; }

      [JsonProperty("job")]
      public string Job { get; set; }

      [JsonProperty("gender")]
      public long Gender { get; set; }

      [JsonProperty("profile_path")]
      public string ProfilePath { get; set; }
      }


      You would need to do the following in your test



      //...

      var actors = JsonConvert.DeserializeObject<RootObject>(ResponseMessage);

      //Assert
      actors.Cast.Should().Contain(actor => actor.Name == "Emilia Clarke");





      share|improve this answer




























        3














        Using the following strongly typed definitions based on the expected JSON from themoviedb



        public partial class RootObject {
        [JsonProperty("cast")]
        public Cast Cast { get; set; }

        [JsonProperty("crew")]
        public Crew Crew { get; set; }

        [JsonProperty("guest_stars")]
        public Cast GuestStars { get; set; }

        [JsonProperty("id")]
        public long Id { get; set; }
        }

        public partial class Cast {
        [JsonProperty("character")]
        public string Character { get; set; }

        [JsonProperty("credit_id")]
        public string CreditId { get; set; }

        [JsonProperty("gender")]
        public long Gender { get; set; }

        [JsonProperty("id")]
        public long Id { get; set; }

        [JsonProperty("name")]
        public string Name { get; set; }

        [JsonProperty("order")]
        public long Order { get; set; }

        [JsonProperty("profile_path")]
        public string ProfilePath { get; set; }
        }

        public partial class Crew {
        [JsonProperty("id")]
        public long Id { get; set; }

        [JsonProperty("credit_id")]
        public string CreditId { get; set; }

        [JsonProperty("name")]
        public string Name { get; set; }

        [JsonProperty("department")]
        public string Department { get; set; }

        [JsonProperty("job")]
        public string Job { get; set; }

        [JsonProperty("gender")]
        public long Gender { get; set; }

        [JsonProperty("profile_path")]
        public string ProfilePath { get; set; }
        }


        You would need to do the following in your test



        //...

        var actors = JsonConvert.DeserializeObject<RootObject>(ResponseMessage);

        //Assert
        actors.Cast.Should().Contain(actor => actor.Name == "Emilia Clarke");





        share|improve this answer


























          3












          3








          3







          Using the following strongly typed definitions based on the expected JSON from themoviedb



          public partial class RootObject {
          [JsonProperty("cast")]
          public Cast Cast { get; set; }

          [JsonProperty("crew")]
          public Crew Crew { get; set; }

          [JsonProperty("guest_stars")]
          public Cast GuestStars { get; set; }

          [JsonProperty("id")]
          public long Id { get; set; }
          }

          public partial class Cast {
          [JsonProperty("character")]
          public string Character { get; set; }

          [JsonProperty("credit_id")]
          public string CreditId { get; set; }

          [JsonProperty("gender")]
          public long Gender { get; set; }

          [JsonProperty("id")]
          public long Id { get; set; }

          [JsonProperty("name")]
          public string Name { get; set; }

          [JsonProperty("order")]
          public long Order { get; set; }

          [JsonProperty("profile_path")]
          public string ProfilePath { get; set; }
          }

          public partial class Crew {
          [JsonProperty("id")]
          public long Id { get; set; }

          [JsonProperty("credit_id")]
          public string CreditId { get; set; }

          [JsonProperty("name")]
          public string Name { get; set; }

          [JsonProperty("department")]
          public string Department { get; set; }

          [JsonProperty("job")]
          public string Job { get; set; }

          [JsonProperty("gender")]
          public long Gender { get; set; }

          [JsonProperty("profile_path")]
          public string ProfilePath { get; set; }
          }


          You would need to do the following in your test



          //...

          var actors = JsonConvert.DeserializeObject<RootObject>(ResponseMessage);

          //Assert
          actors.Cast.Should().Contain(actor => actor.Name == "Emilia Clarke");





          share|improve this answer













          Using the following strongly typed definitions based on the expected JSON from themoviedb



          public partial class RootObject {
          [JsonProperty("cast")]
          public Cast Cast { get; set; }

          [JsonProperty("crew")]
          public Crew Crew { get; set; }

          [JsonProperty("guest_stars")]
          public Cast GuestStars { get; set; }

          [JsonProperty("id")]
          public long Id { get; set; }
          }

          public partial class Cast {
          [JsonProperty("character")]
          public string Character { get; set; }

          [JsonProperty("credit_id")]
          public string CreditId { get; set; }

          [JsonProperty("gender")]
          public long Gender { get; set; }

          [JsonProperty("id")]
          public long Id { get; set; }

          [JsonProperty("name")]
          public string Name { get; set; }

          [JsonProperty("order")]
          public long Order { get; set; }

          [JsonProperty("profile_path")]
          public string ProfilePath { get; set; }
          }

          public partial class Crew {
          [JsonProperty("id")]
          public long Id { get; set; }

          [JsonProperty("credit_id")]
          public string CreditId { get; set; }

          [JsonProperty("name")]
          public string Name { get; set; }

          [JsonProperty("department")]
          public string Department { get; set; }

          [JsonProperty("job")]
          public string Job { get; set; }

          [JsonProperty("gender")]
          public long Gender { get; set; }

          [JsonProperty("profile_path")]
          public string ProfilePath { get; set; }
          }


          You would need to do the following in your test



          //...

          var actors = JsonConvert.DeserializeObject<RootObject>(ResponseMessage);

          //Assert
          actors.Cast.Should().Contain(actor => actor.Name == "Emilia Clarke");






          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Nov 23 '18 at 17:32









          NkosiNkosi

          120k17142206




          120k17142206

























              0














              Here is fluentassertions extension for JSON, which contains many useful methods for asserting JSON:



              Available extension methods
              BeEquivalentTo()
              ContainSingleElement()
              ContainSubtree()
              HaveCount()
              HaveElement()
              HaveValue()
              MatchRegex()
              NotBeEquivalentTo()
              NotHaveElement()
              NotHaveValue()
              NotMatchRegex()



              I am not an author of this library.






              share|improve this answer




























                0














                Here is fluentassertions extension for JSON, which contains many useful methods for asserting JSON:



                Available extension methods
                BeEquivalentTo()
                ContainSingleElement()
                ContainSubtree()
                HaveCount()
                HaveElement()
                HaveValue()
                MatchRegex()
                NotBeEquivalentTo()
                NotHaveElement()
                NotHaveValue()
                NotMatchRegex()



                I am not an author of this library.






                share|improve this answer


























                  0












                  0








                  0







                  Here is fluentassertions extension for JSON, which contains many useful methods for asserting JSON:



                  Available extension methods
                  BeEquivalentTo()
                  ContainSingleElement()
                  ContainSubtree()
                  HaveCount()
                  HaveElement()
                  HaveValue()
                  MatchRegex()
                  NotBeEquivalentTo()
                  NotHaveElement()
                  NotHaveValue()
                  NotMatchRegex()



                  I am not an author of this library.






                  share|improve this answer













                  Here is fluentassertions extension for JSON, which contains many useful methods for asserting JSON:



                  Available extension methods
                  BeEquivalentTo()
                  ContainSingleElement()
                  ContainSubtree()
                  HaveCount()
                  HaveElement()
                  HaveValue()
                  MatchRegex()
                  NotBeEquivalentTo()
                  NotHaveElement()
                  NotHaveValue()
                  NotMatchRegex()



                  I am not an author of this library.







                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Feb 12 at 13:15









                  Karel KralKarel Kral

                  3,11342633




                  3,11342633






























                      draft saved

                      draft discarded




















































                      Thanks for contributing an answer to Stack Overflow!


                      • Please be sure to answer the question. Provide details and share your research!

                      But avoid



                      • Asking for help, clarification, or responding to other answers.

                      • Making statements based on opinion; back them up with references or personal experience.


                      To learn more, see our tips on writing great answers.




                      draft saved


                      draft discarded














                      StackExchange.ready(
                      function () {
                      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53450568%2fc-sharp-unit-testing-assertions-on-json%23new-answer', 'question_page');
                      }
                      );

                      Post as a guest















                      Required, but never shown





















































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown

































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown







                      這個網誌中的熱門文章

                      Academy of Television Arts & Sciences

                      L'Équipe

                      1995 France bombings