コード例 #1
0
        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);
        }
コード例 #2
0
        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>();
        }
コード例 #3
0
        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();
        }
コード例 #4
0
 private void Activate(string key)
 {
     IsCheckingLicense = true;
     try
     {
         var activation = _licenseChecker.ActivateWithoutSaving(key.Replace("-", ""));
         _dispatcher.BeginInvoke(() => UpdateActivation(activation));
     }
     finally
     {
         IsCheckingLicense = false;
         LicenseCheckFinishedEvent.Set();
     }
 }
コード例 #5
0
        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>());
        }
コード例 #6
0
        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)));
        }
コード例 #7
0
 public Option <Activation, LicenseError> ActivateWithoutSaving(string key)
 {
     return(_licenseChecker.ActivateWithoutSaving(key));
 }
コード例 #8
0
        private async Task Activate(string key)
        {
            var activation = _licenseChecker.ActivateWithoutSaving(key.Replace("-", ""));

            await UpdateActivation(activation);
        }