.net - NancyFx Unit Testing : Specify test Response.Body should be Json not CSV -


my unit test:

[fact] public void timeonsite_3_returns_an_array_of_location_and_location_name() {     //a     var response = new browser(new bootstrapper()).get("/reports/data/timeonsite",         =>         {             with.httprequest();             with.query("type", "3");         });     assert.equal(httpstatuscode.ok, response.statuscode);     //a     var raw = response.body.asstring();     console.writeline("timeonsite3:{0}", raw);      ///...etc.... } 

the first time run test (vs2013 using resharper testrunner) see response.body expected json string:

[{"location":"somewhere","location_name":"somewhere name"}] 

but later after i've worked bit , re-run, tests fail , response.body now:

location,location_name somewhere,somewhere name 

instead of being json. why/how force json?

the module looks this:

public class reportdatamodule : modulebase {     static readonly lazy<datasource> dbproviderdataloader = new lazy<datasource>(() => new datasource());      private readonly lazy<datasource> _dataloader;      public reportdatamodule() : this("/reports/data", dbproviderdataloader){}      public reportdatamodule(string path, lazy<datasource> reportdataloader) : base(path)     {         //         // _dataloader.value.timeonjob<timeonjobsummary> returns ienumerable<timeonjobsummary> (underneath it's list<>)         // timeonjobsummary          // public class timeonsitesummary         // {         //     public datetime date_group { get; set; }         //     public int qty { get; set; }         //     public int avg_days { get; set; }         // }          get["/timeonsite"] =              ctx =>                  negotiate.withmodel(_dataloader.value.timeonjob<timeonjobsummary>((int) (request.query.type),(string)request.query.dategroup));          _dataloader = reportdataloader;     } } 

modulebase looks (and has load of added utility methods doesn't override anything) :

public abstract class modulebase : nancymodule {     protected modulebase()     {     }      protected modulebase(string modulepath)         : base(modulepath)     {     }      //other protected methods nothing overridden } 

i still don't know why switches, nancy allow setting client accept header force json:

var response = new browser(new bootstrapper()).get("/reports/data/timeonsite",     =>     {         with.httprequest();         with.header("accept","application/json"); // <-- add accept header         with.query("type", "3");     }); 

Comments

Popular posts from this blog

Android layout hidden on keyboard show -

google app engine - 403 Forbidden POST - Flask WTForms -

c - Why would PK11_GenerateRandom() return an error -8023? -