public void AddOrUpdateHealthKitDataToStorage_GivenHealthKitDataGetsStoredInCache() { var testData = SetUpSingleHealthKitDataObject(); m_dataStorage.AddOrUpdateHealthKitDataToStorage(testData); var count = m_dataStorage.GetAllHealthKitData().Count(); Assert.IsTrue(count == 1); }
public IEnumerable <HealthKitData> GetAllHealthKitData() { var stopWatch = Stopwatch.StartNew(); var allRecords = m_dataStorage.GetAllHealthKitData(); stopWatch.Stop(); m_logger.Info(string.Format("{0} GetAllHealthKitData: Call took {1} Ms", m_dataStorage.GetType(), stopWatch.ElapsedMilliseconds)); return(allRecords); }
public HealthKitServerModule(IHealthKitDataStorage dataStorage, ILogFactory logger) : base("/api/v1") { m_logger = logger.GetLogger(GetType()); m_dataStorage = dataStorage; Get ["/ping"] = parameters => { var response = (Response)"pong"; response.StatusCode = HttpStatusCode.OK; return(response); }; Post["/addHealthKitData"] = parameters => { try { var person = this.Bind <HealthKitData>(); m_dataStorage.AddOrUpdateHealthKitDataToStorage(person); var response = Response.AsJson(person); response.StatusCode = HttpStatusCode.Created; return(response); } catch (Exception e) { m_logger.Error(e.Message, e); var response = (Response)e.ToString(); response.StatusCode = HttpStatusCode.BadRequest; return(response); } }; Get["/getAllHealthKitData"] = parameters => { var response = Response.AsJson(m_dataStorage.GetAllHealthKitData()); response.StatusCode = HttpStatusCode.OK; return(response); }; Get["/getHealthKitData"] = parameters => { var personId = this.Request.Query["id"]; int number; Nancy.Response response; if (int.TryParse(personId, out number)) { response = Response.AsJson(m_dataStorage.GetSpesificHealthKitData(number)); response.StatusCode = HttpStatusCode.OK; return(response); } response = Response.AsText("Bad Request"); response.StatusCode = HttpStatusCode.BadRequest; return(response); }; Get["/getHealthKitDataRecord"] = parameters => { var personId = this.Request.Query["id"]; var recordId = this.Request.Query["recordId"]; int idNumber = new int(); int recordIdNumber = new int(); Nancy.Response response; if (int.TryParse(personId, out idNumber) && int.TryParse(recordId, out recordIdNumber)) { response = Response.AsJson(m_dataStorage.GetSpesificHealthKitDataRecord(idNumber, recordIdNumber)); response.StatusCode = HttpStatusCode.OK; return(response); } response = Response.AsText("Bad Request"); response.StatusCode = HttpStatusCode.BadRequest; return(response); }; }