c# - Web API post returns bad request in Fiddler but Ok in unit test -


i attempting write web api our clients can post submission data future validation. have (much simplified) class user posts us:

public class clientsubmission {     [required]     [stringlength(maximumlength: 40)]     public string apikey { get; set; }      [stringlength(maximumlength: 250)]     public string name { get; set; } } 

and api controller:

public class rebatecontroller : apicontroller {     [httppost] // unnecessary it's in code put here     public ihttpactionresult new(clientsubmission content)     {         if (modelstate.isvalid)         {             return ok(content);         }          return badrequest(modelstate);     } } 

in fiddler when pass json object apikey object back, , when don't modelstate errors - expect! however, in 2 unit tests oknegotiatedcontentresult<clientsubmission> both tests. doing wrong?

[testclass] public class rebatecontrollertest {     private readonly rebatecontroller _controller;      public rebatecontrollertest()     {         _controller = new rebatecontroller();     }      [testmethod]     public void validapireturnsok()     {         var payload = getdefault();          var actionresult = _controller.new(payload);          assert.isinstanceoftype(actionresult, typeof (oknegotiatedcontentresult<clientsubmission>));     }      [testmethod]     public void nullapireturnsbadrequest()     {         var payload = getdefault();          payload.apikey = null;          var actionresult = _controller.new(payload);          assert.isinstanceoftype(actionresult, typeof (badrequestresult));     }      private static clientsubmission getdefault()     {         return new clientsubmission         {             apikey = "test api key",             name = "first name"         };     } } 

failing test:

failing test


Comments