/// <summary> /// This endpoint receives a collection of serialized JSON models and stores them in a database created using automated database migrations. /// </summary> /// <param name="message">The request objects in JSON should have the following structure: /// {"ix": INT, /// "name": STRING, /// "visits": INT?, /// "date": DATETIME} /// </param> //public void Post([FromBody]string value) public void Post(HttpRequestMessage message) { var json = message.Content.ReadAsStringAsync().Result; var requestModels = _jsonConverter.ConvertJsonStringToRequestModels(json); _dbContext.RequestModels.AddRange(requestModels); _dbContext.SaveChanges(); }
public void ConvertJsonStringToRequestModel_Proper() { var jsonString = "[{\"ix\": 10, \"name\": \"test\", \"visits\": 5 ,\"date\": \"2018-01-01\"}," + "{\"ix\": 11, \"name\": \"test1\", \"visits\": 6 ,\"date\": \"2018-01-02\"}]"; var expectedValue = new List <RequestModel>() { new RequestModel() { Index = 10, Name = "test", Visits = 5, Date = DateTime.Parse("2018-01-01") }, new RequestModel() { Index = 11, Name = "test1", Visits = 6, Date = DateTime.Parse("2018-01-02") } }; var actualValue = _jsonConverter.ConvertJsonStringToRequestModels(jsonString); Assert.AreEqual(expectedValue, actualValue); }