public SerializerTestModule() { Get("/serializer/{date}", args => { var stringparamDate = (string)args.date; var dateParsed = DateTime.ParseExact(stringparamDate, "yyyyMMddHHmmss", CultureInfo.InvariantCulture); return(new FakeSerializerModel() { CreatedOn = dateParsed }); }); Post("/serializer", args => { var model = new FakeSerializerModel { CreatedOn = new DateTime(2014, 01, 30, 0, 0, 0, DateTimeKind.Utc) }; this.BindTo(model); return(model); }); Post("/serializer/date", args => { var s = this.Request.Body.AsString(); var model = this.Bind <FakeSerializerModel>(); return(model); }); }
public SerializerTestModule() { Get["/serializer/{date}"] = parameters => { var stringparamDate = (string)parameters.date; var dateParsed = DateTime.ParseExact(stringparamDate, "yyyyMMddHHmmss", CultureInfo.InvariantCulture); return new FakeSerializerModel() { CreatedOn = dateParsed }; }; Post["/serializer"] = _ => { var model = new FakeSerializerModel { CreatedOn = new DateTime(2014, 01, 30) }; this.BindTo(model); return model; }; }
public SerializerTestModule() { Get("/serializer/{date}", args => { var stringparamDate = (string)args.date; var dateParsed = DateTime.ParseExact(stringparamDate, "yyyyMMddHHmmss", CultureInfo.InvariantCulture); return new FakeSerializerModel() { CreatedOn = dateParsed }; }); Post("/serializer", args => { var model = new FakeSerializerModel { CreatedOn = new DateTime(2014, 01, 30, 0, 0, 0, DateTimeKind.Utc) }; this.BindTo(model); return model; }); }
public async Task Should_BindTo_Utc_by_Default() { // Given var model = new FakeSerializerModel() { CreatedOn = new DateTime(2016, 05, 06, 7, 0, 0) }; //When var result = await browser.Post("/serializer/date", with => { with.Body("{\"createdOn\":\"2016-05-06T09:00:00.0000000+02:00\",\"name\":null}", "application/json"); with.Accept("application/json"); }); var resultModel = result.Body.DeserializeJson<FakeSerializerModel>(); // Then Assert.Equal(model.CreatedOn, resultModel.CreatedOn); }
public async Task Should_BindTo_Existing_Instance_Using_Body_Serializer() { // Given var model = new FakeSerializerModel { Name = "Marsellus Wallace" }; // When var result = await browser.Post("/serializer", with => { with.JsonBody(model); with.Accept("application/json"); }); var resultModel = result.Body.DeserializeJson<FakeSerializerModel>(); // Then Assert.Equal("Marsellus Wallace", resultModel.Name); Assert.Equal(new DateTime(2014, 01, 30), resultModel.CreatedOn); }
public SerializerTestModule() { Get["/serializer/{date}"] = parameters => { var stringparamDate = (string)parameters.date; var dateParsed = DateTime.ParseExact(stringparamDate, "yyyyMMddHHmmss", CultureInfo.InvariantCulture); return(new FakeSerializerModel() { CreatedOn = dateParsed }); }; Post["/serializer"] = _ => { var model = new FakeSerializerModel { CreatedOn = new DateTime(2014, 01, 30) }; this.BindTo(model); return(model); }; }
public async Task Should_BindTo_Local_With_GlobalConfigutation() { // Given var model = new FakeSerializerModel() { CreatedOn = new DateTime(2016, 05, 06, 9, 0, 0) }; var bootstrapper = new ConfigurableBootstrapper( configuration => { configuration.Configure( environment => environment.Globalization(supportedCultureNames: new[] { "en-US" }, dateTimeStyles: DateTimeStyles.AssumeLocal)); configuration.Modules(new Type[] { typeof(SerializerTestModule) }); }); var browser = new Browser(bootstrapper); //When var result = await browser.Post("/serializer/date", with => { with.JsonBody(model); with.Accept("application/json"); }); var resultModel = result.Body.DeserializeJson<FakeSerializerModel>(); // Then Assert.Equal(model.CreatedOn, resultModel.CreatedOn); }