/// <summary> /// Расчитывает количество минут до /// разблокировки лицензии для повторения. /// </summary> /// <returns>Время</returns> public TimeSpan GetLicenseUnlockForRepeat() { LicenseLevels license = progress.license; if (license == LicenseLevels.Level_0 || !progress.AllWorkoutDone()) { return(TimeSpan.Zero); } double minutes = GetLicenseTime(); double minutesLeft = 0; switch (license) { case LicenseLevels.Level_1: minutesLeft = LicenseTimeTraining.Level_1 - minutes; break; case LicenseLevels.Level_2: minutesLeft = LicenseTimeTraining.Level_2 - minutes; break; case LicenseLevels.Level_3: minutesLeft = LicenseTimeTraining.Level_3 - minutes; break; case LicenseLevels.Level_4: minutesLeft = LicenseTimeTraining.Level_4 - minutes; break; case LicenseLevels.Level_5: minutesLeft = LicenseTimeTraining.Level_5 - minutes; break; case LicenseLevels.Level_6: minutesLeft = LicenseTimeTraining.Level_6 - minutes; break; case LicenseLevels.Level_7: minutesLeft = LicenseTimeTraining.Level_7 - minutes; break; case LicenseLevels.Level_8: //лицензия на 1 месяц minutesLeft = LicenseTimeTraining.Level_8 - minutes; break; case LicenseLevels.Level_9: //лицензия на 6 месяцев minutesLeft = LicenseTimeTraining.Level_9 - minutes; break; } if (minutesLeft < 0) { minutesLeft = 0; } return(TimeSpan.FromMinutes(minutesLeft)); }
public void LicenseValidityCheck_LicenseExpiries_ExpectedReducedLevelByOne(LicenseLevels actualLevel) { WordLeo word = CreateWordLeo(actualLevel); word.progress.lastRepeat = DateTime.Now - new TimeSpan(0, LicenseTimeout.Level_9 + 5, 0); word.LicenseValidityCheck(); Assert.AreEqual(actualLevel - 1, word.progress.license); }
public void ReduceLicense_LicenseLevelEqualsZero_StateNotChange() { WordLeo word = CreateWordLeo(LicenseLevels.Level_0); LicenseLevels expextedLevel = LicenseLevels.Level_0; word.ReduceLicense(); var resultLevel = word.GetLicense(); Assert.AreEqual(resultLevel, expextedLevel); }
public void ReduceLicense_LicenseLevelEqualsFive_StateLicenseLevelEqualsFour() { WordLeo word = CreateWordLeo(LicenseLevels.Level_5); LicenseLevels expextedLevel = LicenseLevels.Level_4; var expextedTime = DateTime.Now; word.ReduceLicense(); var resultLevel = word.GetLicense(); Assert.AreEqual(expextedLevel, resultLevel); Assert.AreEqual(expextedTime.Second, word.progress.lastRepeat.Second); }
/// <summary> /// Минут до окончания лицензии /// </summary> /// <returns></returns> public TimeSpan GetLicenseValidityTime() { LicenseLevels license = progress.license; double minutes = GetLicenseTime(); double minutesLeft = 0; switch (license) { case LicenseLevels.Level_1: minutesLeft = LicenseTimeout.Level_1 - minutes; break; case LicenseLevels.Level_2: minutesLeft = LicenseTimeout.Level_2 - minutes; break; case LicenseLevels.Level_3: minutesLeft = LicenseTimeout.Level_3 - minutes; break; case LicenseLevels.Level_4: minutesLeft = LicenseTimeout.Level_4 - minutes; break; case LicenseLevels.Level_5: minutesLeft = LicenseTimeout.Level_5 - minutes; break; case LicenseLevels.Level_6: minutesLeft = LicenseTimeout.Level_6 - minutes; break; case LicenseLevels.Level_7: minutesLeft = LicenseTimeout.Level_7 - minutes; break; case LicenseLevels.Level_8: //лицензия на 1 месяц minutesLeft = LicenseTimeout.Level_8 - minutes; break; case LicenseLevels.Level_9: //лицензия на 6 месяцев minutesLeft = LicenseTimeout.Level_9 - minutes; break; } if (minutesLeft < 0) { minutesLeft = 0; } return(TimeSpan.FromMinutes(minutesLeft)); }
public void GetLicenseValidityTime() { LicenseLevels level = LicenseLevels.Level_3; int levelTime = LicenseTimeout.Level_3; int timeExpiries = levelTime - 20; double expectedValue = levelTime - timeExpiries; WordLeo word = CreateWordLeo(level); word.progress.lastRepeat = DateTime.Now - TimeSpan.FromMinutes(timeExpiries); double resultValue = RoundTofloat(word.GetLicenseValidityTime().TotalMinutes); Assert.AreEqual(expectedValue, resultValue); }
public void LicenseExpirationCheck_LicenseExpiries_ExpectedProgressHasReset(LicenseLevels expectedLevel) { bool currentProgress = true; bool expectedProgress = false; WordLeo word = CreateWordLeo(expectedLevel, currentProgress); word.progress.lastRepeat = DateTime.Now - new TimeSpan(0, LicenseTimeTraining.Level_9 + 1, 0); word.LicenseExpirationCheck(); Assert.AreEqual(word.progress.word_translate, expectedProgress); Assert.AreEqual(word.progress.translate_word, expectedProgress); Assert.AreEqual(word.progress.audio_word, expectedProgress); Assert.AreEqual(word.progress.word_puzzle, expectedProgress); }
//[Test] //public void GetProgressCount() //{ // Assert.Fail(); //} //[Test] //public void LearnAudio() //{ // Assert.Fail(); //} //[Test] //public void LearnPuzzle() //{ // Assert.Fail(); //} //[Test] //public void LearnTranslateWord() //{ // Assert.Fail(); //} //[Test] //public void LearnWordTranslate() //{ // Assert.Fail(); //} //[Test] //public void LicenseExists() //{ // Assert.Fail(); //} // Отложено до рефакторига //[Test] //public void AddLicenseLevel() //{ // WordLeo word = CreateWordLeo(LicenseLevels.Level_5); // word.AddLicenseLevel(); // var snapTime = DateTime.Now; // Assert.AreEqual(word.progress.license, LicenseLevels.Level_6); // Assert.AreEqual(word.progress.lastRepeat.Second, snapTime.Second); //} #region Utils private static WordLeo CreateWordLeo(LicenseLevels level = LicenseLevels.Level_0, bool workoutsProgress = false) { WordLeo word; word = new WordLeo(); word.progress = new WorkoutProgress(); word.progress.license = level; word.progress.word_translate = workoutsProgress; word.progress.translate_word = workoutsProgress; word.progress.audio_word = workoutsProgress; word.progress.word_puzzle = workoutsProgress; return(word); }
public void GetLicenseExpiration_LevelBiggestZero_ReturnExpectedValue() { LicenseLevels level = LicenseLevels.Level_3; int levelTime = LicenseTimeTraining.Level_3; int timeExpiries = levelTime - 20; WordLeo word = CreateWordLeo(level, true); word.progress.lastRepeat = DateTime.Now - new TimeSpan(0, timeExpiries, 0); TimeSpan interval = DateTime.Now - word.progress.lastRepeat; double expectedValue = levelTime - interval.TotalMinutes; expectedValue = RoundTofloat(expectedValue); double resultValue = word.GetLicenseUnlockForRepeat().TotalMinutes; resultValue = RoundTofloat(resultValue); Assert.AreEqual(expectedValue, resultValue); }
/// <summary> /// This method uses EsriHttpClient.Get method to fetch licensing info from licensing portal /// </summary> /// <returns></returns> Tuple <bool, string> TestGetLicense() { string printMore = ""; LicenseLevels ll = LicenseInformation.Level; string ll_str = Enum.GetName(typeof(LicenseLevels), ll); printMore += "License level: " + ll_str + "\n"; Tuple <bool, string> regPortal = GetLicensingPortalFReg(); //if (regPortal.Item1 == false) //Assert.Inconclusive(regPortal.Item2 + " [CR310474]"); string portalUrl = regPortal.Item2; printMore += "Licensing portal: " + portalUrl + "\n"; EsriHttpClient myClient = new EsriHttpClient(); #region REST call to get appInfo.Item.id and user.lastLogin of the licensing portal string selfUri = @"/sharing/rest/portals/self?f=json"; var selfResponse = myClient.Get(portalUrl + selfUri); if (selfResponse == null) { return(new Tuple <bool, string>(false, "HTTP response is null")); } if (selfResponse.StatusCode != System.Net.HttpStatusCode.OK) { return(new Tuple <bool, string>(false, "Licensing portal is not set")); } string outStr = selfResponse.Content.ReadAsStringAsync().Result; //Deserialize the response in JSON into a usable object. JavaScriptSerializer serializer = new JavaScriptSerializer(); PortalSelf self_obj = (PortalSelf)serializer.Deserialize(outStr, typeof(PortalSelf)); if ((self_obj == null) || (self_obj.appInfo == null) || (self_obj.user == null)) { return(new Tuple <bool, string>(true, printLicenseCodes() + "\nPro is licensed offline.")); } #endregion #region REST call to get the userLicenses string layerUri = @"/sharing/rest/content/listings/" + self_obj.appInfo.itemId + "/userLicenses?f=json&nonce=007×tamp=" + self_obj.user.lastLogin; var response = myClient.Get(portalUrl + layerUri); if (response == null) { return(new Tuple <bool, string>(false, "HTTP response is null")); } string outStr2 = response.Content.ReadAsStringAsync().Result; //Deserialize the response in JSON into a usable object. userLicenses obj = (userLicenses)serializer.Deserialize(outStr2, typeof(userLicenses)); if (obj == null || obj.userEntitlementsString == null) { return(new Tuple <bool, string>(true, printLicenseCodes() + "\nPro is licensed offline, and signed in with a different account.")); } userEntitlementsString entitlement = (userEntitlementsString)serializer.Deserialize(obj.userEntitlementsString, typeof(userEntitlementsString)); if (entitlement == null) { return(new Tuple <bool, string>(false, "Failed to fetch valid entitlements.")); } else { printMore += printLicenseCodes() + "Entitlements returned by GET request:"; foreach (string e in entitlement.entitlements) { printMore += " " + e; } printMore += "\nLicenses returned by GET request:"; foreach (string l in entitlement.licenses) { printMore += " " + l; } return(new Tuple <bool, string>(true, printMore)); } #endregion }
/// <summary> /// Проверка не истекла ли еще лицензия. /// Если истекла, то понижается уровень лицензии. /// </summary> public void LicenseValidityCheck() { LicenseLevels license = progress.license; TimeSpan interval = DateTime.Now - progress.lastRepeat; double minutes = interval.TotalMinutes; switch (license) { case LicenseLevels.Level_2: //лицензия на 1 час if (minutes > LicenseTimeout.Level_2) { ReduceLicense(); } break; case LicenseLevels.Level_3: //лицензия на 3 часа if (minutes > LicenseTimeout.Level_3) { ReduceLicense(); } break; case LicenseLevels.Level_4: //лицензия на 1 сутки if (minutes > LicenseTimeout.Level_4) { ReduceLicense(); } break; case LicenseLevels.Level_5: //лицензия на 2 суток if (minutes > LicenseTimeout.Level_5) { ReduceLicense(); } break; case LicenseLevels.Level_6: //лицензия на 3 суток if (minutes > LicenseTimeout.Level_6) { ReduceLicense(); } break; case LicenseLevels.Level_7: //лицензия на 1 неделю if (minutes > LicenseTimeout.Level_7) { ReduceLicense(); } break; case LicenseLevels.Level_8: //лицензия на 1 месяц if (minutes > LicenseTimeout.Level_8) { ReduceLicense(); } break; case LicenseLevels.Level_9: //лицензия на 6 месяцев if (minutes > LicenseTimeout.Level_9) { ReduceLicense(); } break; } }
/// <summary> /// Проверка можно ли уже повторять слово. /// Если можно, то сбрасываются все тренировки. /// </summary> public void LicenseExpirationCheck() { LicenseLevels license = progress.license; if (license == LicenseLevels.Level_0 || !progress.AllWorkoutDone()) { return; } double minutes = GetLicenseTime(); if (minutes > LicenseTimeout.Level_1) { LicenseValidityCheck(); } switch (license) { case LicenseLevels.Level_1: //лицензия на 20 минут if (minutes > LicenseTimeTraining.Level_1) { UnlockWorkouts(); } break; case LicenseLevels.Level_2: //лицензия на 1 час if (minutes > LicenseTimeTraining.Level_2) { UnlockWorkouts(); } break; case LicenseLevels.Level_3: //лицензия на 3 часа if (minutes > LicenseTimeTraining.Level_3) { UnlockWorkouts(); } break; case LicenseLevels.Level_4: //лицензия на 1 сутки if (minutes > LicenseTimeTraining.Level_4) { UnlockWorkouts(); } break; case LicenseLevels.Level_5: //лицензия на 2 суток if (minutes > LicenseTimeTraining.Level_5) { UnlockWorkouts(); } break; case LicenseLevels.Level_6: //лицензия на 3 суток if (minutes > LicenseTimeTraining.Level_6) { UnlockWorkouts(); } break; case LicenseLevels.Level_7: //лицензия на 1 неделю if (minutes > LicenseTimeTraining.Level_7) { UnlockWorkouts(); } break; case LicenseLevels.Level_8: //лицензия на 1 месяц if (minutes > LicenseTimeTraining.Level_8) { UnlockWorkouts(); } break; case LicenseLevels.Level_9: //лицензия на 6 месяцев if (minutes > LicenseTimeTraining.Level_9) { UnlockWorkouts(); } break; } }
public void LicenseValidityCheck_LicenseNotExpiries_ExpectedLevelHasNotChanged(LicenseLevels expectedLevel) { WordLeo word = CreateWordLeo(expectedLevel); word.progress.lastRepeat = DateTime.Now - new TimeSpan(0, 1, 0); word.LicenseValidityCheck(); Assert.AreEqual(expectedLevel, word.progress.license); }