public void OnlineActivationCommand_CurrentActivationIsNotValid_LicenseCheckerActivationIsNotValid_DoNotSaveNewEditionAndInformUser()
        {
            _savedActivation = null;

            _expectedLicenseKey = "given-key";
            _interactionInvoker.When(x => x.Invoke(Arg.Any <InputInteraction>())).Do(
                x =>
            {
                ((InputInteraction)x[0]).Success   = true;
                ((InputInteraction)x[0]).InputText = _expectedLicenseKey;
            });
            var messageInteraction = new MessageInteraction("", "", MessageOptions.OKCancel, MessageIcon.None);

            _interactionInvoker.When(x => x.Invoke(Arg.Any <MessageInteraction>())).Do(
                x => messageInteraction = x.Arg <MessageInteraction>());

            _activationFromServer     = new Activation(acceptExpiredActivation: true);
            _activationFromServer.Key = _expectedLicenseKey.Replace("-", "");
            _activationFromServer.SetResult(Result.LICENSE_EXPIRED, "Expired");

            var viewModel = BuildViewModel();

            viewModel.OnlineActivationCommand.Execute(null);

            viewModel.LicenseCheckFinishedEvent.WaitOne(_timeout);
            _licenseChecker.DidNotReceive().SaveActivation(Arg.Any <Activation>());

            Assert.AreEqual(_translation.ActivationFailed, messageInteraction.Title);
            Assert.AreEqual(MessageOptions.OK, messageInteraction.Buttons);
            Assert.AreEqual(MessageIcon.Error, messageInteraction.Icon);
        }
        public async Task OfflineActivationCommandExecute_UserCancelsOfflineActivation_ActivationHelper()
        {
            var viewModel = BuildViewModel();

            _interactionRequest.RegisterInteractionHandler <OfflineActivationInteraction>(offlineActivationInteraction =>
            {
                offlineActivationInteraction.Success = false;
            });

            await viewModel.OfflineActivationAsyncCommand.ExecuteAsync(null);

            _offlineActivator.DidNotReceive().ActivateOfflineActivationString(Arg.Any <string>());
            _licenseChecker.DidNotReceive().SaveActivation(Arg.Any <Activation>());
        }
        public void WithActivationValidForMoreThanFourDays_DoesNotRenew()
        {
            var licenseCondition = BuildCheckLicenseConditions();

            _savedActivation = BuildValidActivation();
            _savedActivation.ActivatedTill = DateTime.Now.AddDays(4).AddMinutes(5);

            licenseCondition.Check();

            _licenseChecker.DidNotReceive().GetActivation();
            _licenseChecker.DidNotReceive().ActivateWithKey(Arg.Any <string>());
        }
        public void EnterLicenseKeyCommand_CurrentEditionIsValid_LicenseCheckerActivationIsNotValid_DoNotSaveNewActivationAndDoNotUpdateEdition()
        {
            _expectedLicenseKey       = "not empty";
            _licenseCheckerActivation = CreateValidActivation();
            _editionFactory           = BuildValidEditionHelper();
            var invalidEdition = CreateValidEdition();

            invalidEdition.LicenseStatus = LicenseStatus.Error; //make received Edition invalid
            _editionFactory.DetermineEdition(_licenseCheckerActivation).Returns(invalidEdition);
            _editionFactory.ReloadEdition().Returns(invalidEdition);
            var           viewModel             = BuildViewModel(_editionFactory);
            List <string> propertyChangedEvents = new List <string>();

            viewModel.PropertyChanged += (sender, args) => propertyChangedEvents.Add(args.PropertyName);

            viewModel.EnterLicenseKeyCommand.Execute(null);

            viewModel.LicenseCheckFinishedEvent.WaitOne(_timeout);
            _editionFactory.DidNotReceive().ReloadEdition();
            _licenseChecker.DidNotReceive().SaveActivation(Arg.Any <Activation>());
            Assert.Contains(nameof(viewModel.Edition), propertyChangedEvents);
            Assert.AreSame(_editionFactory.Edition, viewModel.Edition); //Keep old edition
        }