public void Returns_content_if_response_is_OK() { string content = File.ReadAllText(SampleData.PathFor("DateActivity.txt")); var mock = new Mock <IRestClient>(); var deserializer = new RestSharp.Deserializers.XmlDeserializer(); deserializer.RootElement = "summary"; mock.Setup(x => x.Execute <ActivitySummary>(It.IsAny <IRestRequest>())) .Returns(new RestResponse <ActivitySummary> { StatusCode = HttpStatusCode.OK, Content = content, Data = deserializer.Deserialize <ActivitySummary>(new RestResponse() { Content = content }) }); //var client = new GuidClient(mock.Object); FitbitClient fitbitClient = new FitbitClient(mock.Object); var result = fitbitClient.GetDayActivitySummary(DateTime.Now); Assert.IsNotNull(result); Assert.AreEqual(12345, result.Steps); }
public IList <View.VParamType> OnOperationInvoke(string roleName, String opName, IList <View.VParamType> parameters) { List <View.VParamType> retVals = new List <View.VParamType>(); FitbitClient client = new FitbitClient(consumerKey, consumerSecret, accessToken, accessSecret); switch (opName) { case RoleFitbitUltra.OpGetActiveScoreName: { DateTime activityDate = (DateTime)parameters[0].Value(); ActivitySummary data = client.GetDayActivitySummary(activityDate); int result = data.ActiveScore; retVals.Add(new ParamType(ParamType.SimpleType.integer, "int", result, "result")); } break; case RoleFitbitUltra.OpGetCaloriesOutName: { DateTime activityDate = (DateTime)parameters[0].Value(); ActivitySummary data = client.GetDayActivitySummary(activityDate); int result = data.CaloriesOut; retVals.Add(new ParamType(ParamType.SimpleType.integer, "int", result, "result")); } break; case RoleFitbitUltra.OpGetDistanceName: { DateTime activityDate = (DateTime)parameters[0].Value(); ActivitySummary data = client.GetDayActivitySummary(activityDate); float result = data.Distances.Sum(z => z.Distance); retVals.Add(new ParamType(ParamType.SimpleType.binary, "float", result, "result")); } break; case RoleFitbitUltra.OpGetStepsName: { DateTime activityDate = (DateTime)parameters[0].Value(); ActivitySummary data = client.GetDayActivitySummary(activityDate); int result = data.Steps; retVals.Add(new ParamType(ParamType.SimpleType.integer, "int", result, "result")); } break; case RoleFitbitUltra.OpGetTotalMinutesAsleep: { DateTime activityDate = (DateTime)parameters[0].Value(); SleepSummary data = client.GetDaySleepSummary(activityDate); int result = data.TotalMinutesAsleep; retVals.Add(new ParamType(ParamType.SimpleType.integer, "int", result, "result")); } break; case RoleFitbitUltra.OpGetTotalSleepRecords: { DateTime activityDate = (DateTime)parameters[0].Value(); SleepSummary data = client.GetDaySleepSummary(activityDate); int result = data.TotalSleepRecords; retVals.Add(new ParamType(ParamType.SimpleType.integer, "int", result, "result")); } break; case RoleFitbitUltra.OpGetTotalTimeInBed: { DateTime activityDate = (DateTime)parameters[0].Value(); SleepSummary data = client.GetDaySleepSummary(activityDate); int result = data.TotalTimeInBed; retVals.Add(new ParamType(ParamType.SimpleType.integer, "int", result, "result")); } break; case RoleFitbitUltra.OpGetDevicePresence: { List <Fitbit.Models.Device> data = client.GetDevices(); bool result = data.Where(z => z.Type == DeviceType.Tracker).FirstOrDefault().LastSyncTime >= DateTime.Now.AddMinutes(-15); retVals.Add(new ParamType(ParamType.SimpleType.binary, "bool", result, "result")); } break; default: logger.Log("Invalid operation {0}", opName); break; } return(retVals); }