public void WithActivationValidForLessThanFourDays_RenewsAndSavesActivation() { var licenseCondition = BuildCheckLicenseConditions(); _savedActivation.ActivatedTill = DateTime.Now.AddDays(3); _savedActivation.Key = "AAA-BBB-CCC"; _savedActivation.SetResult(Result.OK, "OK"); _licenseChecker.ActivateWithoutSaving(Arg.Any <string>()).Returns(_savedActivation.Some <Activation, LicenseError>()); licenseCondition.Check(); _licenseChecker.DidNotReceive().GetActivation(); _licenseChecker.Received().ActivateWithoutSaving(_savedActivation.Key); _licenseChecker.Received().SaveActivation(_savedActivation); }
public async Task OnlineActivationCommand_CurrentActivationIsNotValid_LicenseCheckerActivationIsValid_SaveNewActivationAndStoreLicenseForAllUsersQuery() { _expectedLicenseKey = "not empty"; CreateLicenseKeyEnteredInteraction(_expectedLicenseKey); _licenseChecker.ActivateWithoutSaving(_expectedLicenseKey).Returns(x => BuildValidActivation(_expectedLicenseKey).Some <Activation, LicenseError>()); var viewModel = BuildViewModel(); await viewModel.OnlineActivationAsyncCommand.ExecuteAsync(null); _interactionRequest.AssertWasRaised <StoreLicenseForAllUsersInteraction>(); }
public void Setup() { _savedActivation = null; _expectedLicenseKey = null; _activationFromServer = null; _process = Substitute.For <IProcessStarter>(); _licenseChecker = Substitute.For <ILicenseChecker>(); _licenseChecker.GetSavedActivation().Returns(x => _savedActivation.SomeNotNull(LicenseError.NoActivation)); _licenseChecker.ActivateWithoutSaving(Arg.Any <string>()).Returns(key => _activationFromServer.SomeNotNull(LicenseError.NoActivation)); _offlineActivator = Substitute.For <IOfflineActivator>(); _interactionRequest = new UnitTestInteractionRequest(); }
private void Activate(string key) { IsCheckingLicense = true; try { var activation = _licenseChecker.ActivateWithoutSaving(key.Replace("-", "")); _dispatcher.BeginInvoke(() => UpdateActivation(activation)); } finally { IsCheckingLicense = false; LicenseCheckFinishedEvent.Set(); } }
public void OnlineActivationCommand_CurrentActivationIsNotValid_LicenseCheckerActivationIsValid_SaveNewActivationAndStoreLicenseForAllUsersQuery() { _expectedLicenseKey = "not empty"; _interactionInvoker.When(x => x.Invoke(Arg.Any <InputInteraction>())).Do( x => { var inputInteraction = x.Arg <InputInteraction>(); inputInteraction.Success = true; inputInteraction.InputText = _expectedLicenseKey; }); _licenseChecker.ActivateWithoutSaving(_expectedLicenseKey).Returns(x => BuildValidActivation(_expectedLicenseKey).Some <Activation, LicenseError>()); var viewModel = BuildViewModel(); viewModel.OnlineActivationCommand.Execute(null); viewModel.LicenseCheckFinishedEvent.WaitOne(_timeout); _interactionInvoker.Received().Invoke(Arg.Any <StoreLicenseForAllUsersInteraction>()); }
private Option <Activation, LicenseError> RenewActivation() { var activation = _licenseChecker.GetSavedActivation(); if (activation.Exists(a => a.ActivationMethod == ActivationMethod.Offline)) { return(activation); } if (activation.Exists(IsActivationPeriodStillValid)) { return(activation); } var licenseKey = activation.Match( some: a => a.Key.Some <string, LicenseError>(), none: e => _licenseChecker.GetSavedLicenseKey()); return(licenseKey.Match( some: key => { var newActivation = _licenseChecker.ActivateWithoutSaving(key); // Only save if we receive a valid license or the license was blocked newActivation .Filter(a => a.IsActivationStillValid() || a.Result == Result.BLOCKED, LicenseError.NoActivation) .MatchSome(a => _licenseChecker.SaveActivation(a)); // If the online activation failed and the old activation is still valid, return the current activation if (!newActivation.HasValue && activation.Exists(a => a.IsActivationStillValid())) { return activation; } return newActivation; }, none: e => Option.None <Activation, LicenseError>(LicenseError.NoLicenseKey))); }
public Option <Activation, LicenseError> ActivateWithoutSaving(string key) { return(_licenseChecker.ActivateWithoutSaving(key)); }
private async Task Activate(string key) { var activation = _licenseChecker.ActivateWithoutSaving(key.Replace("-", "")); await UpdateActivation(activation); }