public void AddPrinterCommand_Execute_PrinterMappingContainsPrinterWithGivenName_DefaultProfileGuidIsAssigned()
        {
            var conversionProfiles = new[]
            {
                new ConversionProfile
                {
                    Guid = ProfileGuids.DEFAULT_PROFILE_GUID
                }
            };

            _applicationSettings = new Conversion.Settings.ApplicationSettings();

            var newPrinterName = "New printer for testing";

            _printerProvider.GetPDFCreatorPrinters().Returns(new[] { newPrinterName });
            var printerTabViewModel = BuildViewModel(conversionProfiles);

            string something;

            _printerActionAssistant.AddPrinter(out something).Returns(x =>
            {
                x[0] = newPrinterName;
                return(true);
            });

            printerTabViewModel.AddPrinterCommand.Execute(null);

            Assert.AreEqual(1, printerTabViewModel.PrinterMappings.Count, "Added more or less than one printer");
            Assert.AreEqual(newPrinterName, printerTabViewModel.PrinterMappings[0].PrinterMapping.PrinterName,
                            "Wrong printername");
            Assert.AreEqual(ProfileGuids.DEFAULT_PROFILE_GUID,
                            printerTabViewModel.PrinterMappings[0].PrinterMapping.ProfileGuid,
                            "Did not assign the default profile GUID.");
        }
        public void SetUp()
        {
            _translationHelper = new TranslationHelper(new TranslationProxy(), new DefaultSettingsProvider(), new AssemblyHelper());
            _translationHelper.InitEmptyTranslator();

            _printerActionAssistant = Substitute.For <IPrinterActionsAssistant>();

            _profile1 = new ConversionProfile
            {
                Name = "Profile1",
                Guid = "Profile1Guid"
            };

            _profile2 = new ConversionProfile
            {
                Name = "Profile1",
                Guid = "Profile1Guid"
            };

            _applicationSettings = new Conversion.Settings.ApplicationSettings();
            _applicationSettings.PrinterMappings = new[]
            {
                new PrinterMapping(ExistingPrinter, _profile1.Guid)
                , new PrinterMapping(UnknownPrinter, _profile2.Guid)
            }.ToList();

            _printerProvider = Substitute.For <IPrinterProvider>();
        }
        public void SetSettingsAndRaiseNotifications(Conversion.Settings.ApplicationSettings applicationSettings, IGpoSettings gpoSettings)
        {
            ApplicationSettings = applicationSettings;
            GpoSettings         = gpoSettings;

            OnSettingsChanged();
        }
        public void TitleReplacementAdd_WithEmptyList_CanExecute()
        {
            var settings = new Conversion.Settings.ApplicationSettings();

            settings.TitleReplacement = new TitleReplacement[] {};

            var titleTabViewModel = new TitleTabViewModel(_translator);

            titleTabViewModel.ApplyTitleReplacements(settings.TitleReplacement);

            Assert.IsTrue(titleTabViewModel.TitleAddCommand.CanExecute(null));
        }
        public void TitleReplacementDelete_WithNonEmptyList_CanExecute()
        {
            var settings = new Conversion.Settings.ApplicationSettings();

            settings.TitleReplacement = new[] { new TitleReplacement(ReplacementType.Replace, "a", "b"), new TitleReplacement(ReplacementType.Replace, "c", "d") }.ToList();

            var titleTabViewModel = new TitleTabViewModel(_translator);

            titleTabViewModel.ApplyTitleReplacements(settings.TitleReplacement);

            Assert.IsTrue(titleTabViewModel.TitleDeleteCommand.CanExecute(null));
        }
        public void TitleReplacementDelete_WithEmptyList_CannotExecute()
        {
            var settings = new Conversion.Settings.ApplicationSettings();

            settings.TitleReplacement = new TitleReplacement[] {};

            var titleTabViewModel = BuildTitleTabViewModel();

            titleTabViewModel.ApplyTitleReplacements(settings.TitleReplacement);

            Assert.IsFalse(titleTabViewModel.TitleDeleteCommand.CanExecute(null));
        }
        public void TitleReplacementAdd_WithEmptyList_InsertsOneElement()
        {
            var settings = new Conversion.Settings.ApplicationSettings();

            settings.TitleReplacement = new TitleReplacement[] {}.ToList();

            var titleTabViewModel = new TitleTabViewModel(_translator);

            titleTabViewModel.ApplyTitleReplacements(settings.TitleReplacement);

            titleTabViewModel.TitleAddCommand.Execute(null);

            Assert.AreEqual(1, settings.TitleReplacement.Count);
        }
        public void TitleReplacementAdd_WithNonEmptyList_NewElementIsCurrent()
        {
            var settings = new Conversion.Settings.ApplicationSettings();

            settings.TitleReplacement = new[] { new TitleReplacement(ReplacementType.Replace, "a", "b"), new TitleReplacement(ReplacementType.Replace, "c", "d") }.ToList();

            var titleTabViewModel = new TitleTabViewModel(_translator);

            titleTabViewModel.ApplyTitleReplacements(settings.TitleReplacement);
            var cv = CollectionViewSource.GetDefaultView(titleTabViewModel.TitleReplacements);

            titleTabViewModel.TitleAddCommand.Execute(null);

            Assert.AreEqual(2, cv.CurrentPosition);
        }
        public void SetSettingsAndRaiseNotifications(PdfCreatorSettings settings, IGpoSettings gpoSettings)
        {
            _applicationSettings = settings.ApplicationSettings;
            ConversionProfiles   = settings.ConversionProfiles;

            RaisePropertyChanged(nameof(_applicationSettings));
            RaisePropertyChanged(nameof(ConversionProfiles));

            UpdatePrinterList();
            ApplyPrinterMappings();
            UpdatePrinterCollectionViews();

            RaisePropertyChanged(nameof(PrimaryPrinter));
            UpdatePrimaryPrinter(PrimaryPrinter);
        }
        public void TitleReplacementDelete_AfterExecute_OtherElementStillThere()
        {
            var settings = new Conversion.Settings.ApplicationSettings();

            settings.TitleReplacement = new[] { new TitleReplacement(ReplacementType.Replace, "a", "b"), new TitleReplacement(ReplacementType.Replace, "c", "d") }.ToList();

            var titleTabViewModel = new TitleTabViewModel(_translator);

            titleTabViewModel.ApplyTitleReplacements(settings.TitleReplacement);

            var otherElement = settings.TitleReplacement[1];

            titleTabViewModel.TitleDeleteCommand.Execute(null);

            Assert.IsTrue(titleTabViewModel.TitleReplacements.Contains(otherElement));
        }
        public void TitleReplacementDelete_AfterExecute_ElementIsRemoved()
        {
            var settings = new Conversion.Settings.ApplicationSettings();

            settings.TitleReplacement = new[] { new TitleReplacement(ReplacementType.Replace, "a", "b"), new TitleReplacement(ReplacementType.Replace, "c", "d") }.ToList();

            var titleTabViewModel = new TitleTabViewModel(_translator);

            titleTabViewModel.ApplyTitleReplacements(settings.TitleReplacement);

            var deletedElement = settings.TitleReplacement[0];

            titleTabViewModel.TitleDeleteCommand.Execute(null);

            Assert.IsFalse(titleTabViewModel.TitleReplacements.Contains(deletedElement));
        }
        public void TitleReplacementDelete_CurrentItemChanged_RaisesCommandCanExecuteChanged()
        {
            var wasRaised = false;
            var settings  = new Conversion.Settings.ApplicationSettings();

            settings.TitleReplacement = new[] { new TitleReplacement(ReplacementType.Replace, "a", "b"), new TitleReplacement(ReplacementType.Replace, "c", "d") }.ToList();

            var titleTabViewModel = new TitleTabViewModel(_translator);

            titleTabViewModel.ApplyTitleReplacements(settings.TitleReplacement);

            titleTabViewModel.TitleDeleteCommand.CanExecuteChanged += (sender, args) => wasRaised = true;

            var cv = CollectionViewSource.GetDefaultView(titleTabViewModel.TitleReplacements);

            cv.MoveCurrentToPrevious();

            Assert.IsTrue(wasRaised);
        }