public void GetSpesificHealthKitData_GivenMultipleHealthKitDataWithDifferentIds_ReturnsCorrectNumberofRecords()
        {
            var testData = SetUpMultipleHealthKitObjects();

            PutMultipleHealthKitRecordsInCache(testData);

            var countId1 = m_dataStorage.GetSpesificHealthKitData(11).Count();

            Assert.IsTrue(countId1 == 2);
        }
Exemplo n.º 2
0
        public IEnumerable <HealthKitData> GetSpesificHealthKitData(int personId)
        {
            var stopWatch    = Stopwatch.StartNew();
            var recordFromId = m_dataStorage.GetSpesificHealthKitData(personId);

            stopWatch.Stop();
            m_logger.Info(string.Format("{0} GetSpesificHealthKitData: Call took {1} Ms", m_dataStorage.GetType(), stopWatch.ElapsedMilliseconds));
            return(recordFromId);
        }
        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);
            };
        }