Esempio n. 1
0
        public void DeleteConfigurationResetsReversalToShippedDefaultIfNoProjectAllReversal()
        {
            var defaultReversalPath = Path.Combine(FwDirectoryFinder.DefaultConfigurations, "ReversalIndex");

            // construct a controller to work in the default reversal directory
            _controller = new DictionaryConfigurationManagerController(Cache, _configurations, new List <string>(), _projectConfigPath, defaultReversalPath);
            var allRevFileName = DictionaryConfigurationModel.AllReversalIndexesFilenameBase + DictionaryConfigurationModel.FileExtension;
            var shippedRootDefaultConfigurationPath = Path.Combine(defaultReversalPath, allRevFileName);

            FileUtils.WriteStringtoFile(shippedRootDefaultConfigurationPath, "bogus data that is unread, the file is read from the real defaults", Encoding.UTF8);

            var configurationToDelete = _configurations[0];

            configurationToDelete.FilePath      = Path.Combine("whateverdir", "English" + DictionaryConfigurationModel.FileExtension);
            configurationToDelete.Label         = "English";
            configurationToDelete.WritingSystem = "en";

            var pathToConfiguration = configurationToDelete.FilePath;

            FileUtils.WriteStringtoFile(pathToConfiguration, "customized file contents", Encoding.UTF8);
            Assert.That(FileUtils.FileExists(pathToConfiguration), "Unit test not set up right");
            Assert.IsFalse(FileUtils.FileExists(Path.Combine(_projectConfigPath, allRevFileName)), "Unit test not set up right");

            // SUT
            _controller.DeleteConfiguration(configurationToDelete);

            Assert.That(FileUtils.FileExists(pathToConfiguration), "The English reversal file should have been reset to defaults, not deleted.");
            Assert.That(configurationToDelete.Label, Is.EqualTo("English"), "The label should still be English after a reset.");
            Assert.That(configurationToDelete.IsReversal, Is.True, "The reset configuration files should still be a reversal file.");
            Assert.Contains(configurationToDelete, _configurations, "The configuration should still be present in the list after being reset.");
            Assert.That(_controller.IsDirty, "Resetting is a change that is saved later; should be dirty");

            // Not asserting that the configurationToDelete.FilePath file contents are reset because that will happen later when it is saved.
        }
Esempio n. 2
0
        public void DeleteConfigurationResetsForShippedDefaultRatherThanDelete()
        {
            var shippedRootDefaultConfigurationPath = Path.Combine(_defaultConfigPath, "Root" + DictionaryConfigurationModel.FileExtension);

            FileUtils.WriteStringtoFile(shippedRootDefaultConfigurationPath, "bogus data that is unread, the file is read from the real defaults", Encoding.UTF8);

            var configurationToDelete = _configurations[0];

            configurationToDelete.FilePath = Path.Combine("whateverdir", "Root" + DictionaryConfigurationModel.FileExtension);
            configurationToDelete.Label    = "customizedLabel";

            var pathToConfiguration = configurationToDelete.FilePath;

            FileUtils.WriteStringtoFile(pathToConfiguration, "customized file contents", Encoding.UTF8);
            Assert.That(FileUtils.FileExists(pathToConfiguration), "Unit test not set up right");

            // SUT
            _controller.DeleteConfiguration(configurationToDelete);

            Assert.That(FileUtils.FileExists(pathToConfiguration), "The Root configuration file should have been reset to defaults, not deleted.");
            Assert.That(configurationToDelete.Label, Is.EqualTo("Root-based (complex forms as subentries)"), "The reset should match the shipped defaults.");
            Assert.Contains(configurationToDelete, _configurations, "The configuration should still be present in the list after being reset.");
            Assert.That(_controller.IsDirty, "Resetting is a change that is saved later; should be dirty");

            // Not asserting that the configurationToDelete.FilePath file contents are reset because that will happen later when it is saved.
        }
Esempio n. 3
0
        public void GenerateFilePath_AccountsForFilesOnDisk()
        {
            List <DictionaryConfigurationModel> conflictingConfigs;
            var configToRename = GenerateFilePath_Helper(out conflictingConfigs);

            FileUtils.WriteStringtoFile(Path.Combine(_projectConfigPath, "configuration3_3.fwdictconfig"), "file contents of config file that is in the way on disk but not actually registered in the list of configurations", Encoding.UTF8);

            // SUT
            DictionaryConfigurationManagerController.GenerateFilePath(_controller._projectConfigDir, _controller._configurations, configToRename);

            var newFilePath = configToRename.FilePath;

            Assert.That(newFilePath, Is.EqualTo(Path.Combine(_projectConfigPath, "configuration3_4.fwdictconfig")), "Did not account for collision with unregistered configuration on disk");
        }
Esempio n. 4
0
        public override void FixtureSetup()
        {
            base.FixtureSetup();
            FileUtils.Manager.SetFileAdapter(_mockFilesystem);

            FileUtils.EnsureDirectoryExists(_defaultConfigPath);
            NonUndoableUnitOfWorkHelper.DoSomehow(Cache.ActionHandlerAccessor, () =>
            {
                var styleFactory    = Cache.ServiceLocator.GetInstance <IStStyleFactory>();
                _characterTestStyle = styleFactory.Create(Cache.LangProject.StylesOC, "TestStyle", ContextValues.InternalConfigureView, StructureValues.Body, FunctionValues.Line, true, 2, false);
                _characterTestStyle.Usage.set_String(Cache.DefaultAnalWs, "Test Style");
                var propsBldr = TsPropsBldrClass.Create();
                propsBldr.SetIntPropValues((int)FwTextPropType.ktptForeColor, (int)FwTextPropVar.ktpvDefault,
                                           (int)ColorUtil.ConvertColorToBGR(Color.Red));
                propsBldr.SetIntPropValues((int)FwTextPropType.ktptUnderline, (int)FwTextPropVar.ktpvDefault,
                                           (int)FwUnderlineType.kuntDouble);
                propsBldr.SetIntPropValues((int)FwTextPropType.ktptUnderColor, (int)FwTextPropVar.ktpvDefault,
                                           (int)ColorUtil.ConvertColorToBGR(Color.Blue));
                propsBldr.SetIntPropValues((int)FwTextPropType.ktptBold, (int)FwTextPropVar.ktpvEnum, (int)FwTextToggleVal.kttvForceOn);
                propsBldr.SetIntPropValues((int)FwTextPropType.ktptItalic, (int)FwTextPropVar.ktpvEnum, (int)FwTextToggleVal.kttvForceOn);
                propsBldr.SetStrPropValue((int)FwTextPropType.ktptFontFamily, "times");
                _characterTestStyle.Rules = propsBldr.GetTextProps();
                _paraTestStyle            = styleFactory.Create(Cache.LangProject.StylesOC, "ParaTestStyle", ContextValues.InternalConfigureView, StructureValues.Body, FunctionValues.Line, false, 2, false);
                propsBldr.Clear();
                propsBldr.SetIntPropValues((int)FwTextPropType.ktptBackColor, (int)FwTextPropVar.ktpvDefault,
                                           (int)ColorUtil.ConvertColorToBGR(Color.Lime));
                propsBldr.SetIntPropValues((int)FwTextPropType.ktptAlign, (int)FwTextPropVar.ktpvEnum, (int)FwTextAlign.ktalCenter);
                propsBldr.SetIntPropValues((int)FwTextPropType.ktptLineHeight, (int)FwTextPropVar.ktpvMilliPoint, -3000);
                propsBldr.SetIntPropValues((int)FwTextPropType.ktptTrailingIndent, (int)FwTextPropVar.ktpvDefault, 4000);
                propsBldr.SetIntPropValues((int)FwTextPropType.ktptFirstIndent, (int)FwTextPropVar.ktpvDefault, -5000);
                propsBldr.SetIntPropValues((int)FwTextPropType.ktptLeadingIndent, (int)FwTextPropVar.ktpvDefault, 6000);
                propsBldr.SetIntPropValues((int)FwTextPropType.ktptSpaceBefore, (int)FwTextPropVar.ktpvDefault, 7000);
                propsBldr.SetIntPropValues((int)FwTextPropType.ktptSpaceAfter, (int)FwTextPropVar.ktpvDefault, 8000);
                _paraTestStyle.Rules = propsBldr.GetTextProps();
                _paraChildTestStyle  = styleFactory.Create(Cache.LangProject.StylesOC, "ParaChildTesttStyle",
                                                           ContextValues.InternalConfigureView, StructureValues.Body, FunctionValues.Line, false, 3, false);
                propsBldr.Clear();
                propsBldr.SetIntPropValues((int)FwTextPropType.ktptAlign, (int)FwTextPropVar.ktpvEnum, (int)FwTextAlign.ktalJustify);
                _paraChildTestStyle.Rules     = propsBldr.GetTextProps();
                _paraChildTestStyle.BasedOnRA = _paraTestStyle;
                _bulletedTestStyle            = styleFactory.Create(Cache.LangProject.StylesOC, "Bulleted List", ContextValues.InternalConfigureView, StructureValues.Body, FunctionValues.Line, false, 2, false);
                _numberedTestStyle            = styleFactory.Create(Cache.LangProject.StylesOC, "Numbered List", ContextValues.InternalConfigureView, StructureValues.Body, FunctionValues.Line, false, 2, false);
                _homographTestStyle           = styleFactory.Create(Cache.LangProject.StylesOC, "Homograph-Number", ContextValues.InternalConfigureView, StructureValues.Body, FunctionValues.Line, true, 2, false);

                var characterStyleBasedOnSomething       = styleFactory.Create(Cache.LangProject.StylesOC, "CharacterStyleBasedOnSomething", ContextValues.InternalConfigureView, StructureValues.Body, FunctionValues.Line, true, 2, false);
                characterStyleBasedOnSomething.BasedOnRA = _characterTestStyle;
            });
        }
Esempio n. 5
0
        public void DeleteConfigurationRemovesFromDisk()
        {
            var configurationToDelete = _configurations[0];

            DictionaryConfigurationManagerController.GenerateFilePath(_controller._projectConfigDir, _controller._configurations, configurationToDelete);
            var pathToConfiguration = configurationToDelete.FilePath;

            FileUtils.WriteStringtoFile(pathToConfiguration, "file contents", Encoding.UTF8);
            Assert.That(FileUtils.FileExists(pathToConfiguration), "Unit test not set up right");

            // SUT
            _controller.DeleteConfiguration(configurationToDelete);

            Assert.That(!FileUtils.FileExists(pathToConfiguration), "File should have been deleted");
            Assert.That(_controller.IsDirty, "made changes; should be dirty");
        }