Esempio n. 1
0
        public void CanValidatePostActionWithDefaultInstructionLocalization()
        {
            SimpleConfigModel baseConfig = new SimpleConfigModel()
            {
                Identity         = "Test",
                PostActionModels = new List <PostActionModel>
                {
                    new PostActionModel()
                    {
                        Id                    = "pa0",
                        Description           = "text",
                        ActionId              = Guid.NewGuid(),
                        ManualInstructionInfo = new List <ManualInstructionModel>()
                        {
                            new ManualInstructionModel(null, "my text")
                        }
                    },
                }
            };
            IEngineEnvironmentSettings environmentSettings = _environmentSettingsHelper.CreateEnvironment(virtualize: true);
            string tempFolder       = _environmentSettingsHelper.CreateTemporaryFolder();
            string localizationFile = string.Format(DefaultLocalizeConfigRelativePath, "de-DE");

            WriteFile(Path.Combine(tempFolder, localizationFile), "{ \"postActions/pa0/manualInstructions/default/text\": \"localized\" }", environmentSettings);

            using IMountPoint mountPoint = GetMountPointForPath(tempFolder, environmentSettings);

            var runnableProjectConfig = new RunnableProjectConfig(environmentSettings, A.Fake <IGenerator>(), baseConfig);
            var localizationModel     = LocalizationModelDeserializer.Deserialize(mountPoint.FileInfo(localizationFile) !);

            Assert.True(runnableProjectConfig.VerifyLocalizationModel(localizationModel));

            runnableProjectConfig.ConfigurationModel.Localize(localizationModel);
            runnableProjectConfig.PostActionModels.Single(model => model.Id == "pa0" && model.ManualInstructionInfo[0].Text == "localized");
        }
Esempio n. 2
0
        public void CanReadChoiceSymbol(
            string fileContent,
            bool errorExpected,
            string expectedSymbolNamesStr,
            string expectedSymbolDisplayNamesStr,
            string expectedDescriptionsStr,
            string expectedChoicesStr)
        {
            IEngineEnvironmentSettings environmentSettings = _environmentSettingsHelper.CreateEnvironment(virtualize: true);
            string tempFolder       = _environmentSettingsHelper.CreateTemporaryFolder();
            string localizationFile = string.Format(DefaultLocalizeConfigRelativePath, "de-DE");

            WriteFile(Path.Combine(tempFolder, localizationFile), fileContent, environmentSettings);

            using IMountPoint mountPoint = GetMountPointForPath(tempFolder, environmentSettings);
            if (!errorExpected)
            {
                var localizationModel = LocalizationModelDeserializer.Deserialize(mountPoint.FileInfo(localizationFile) !);
                Assert.NotNull(localizationModel);

                if (string.IsNullOrEmpty(expectedSymbolNamesStr))
                {
                    Assert.Empty(localizationModel.ParameterSymbols);
                    return;
                }
                var expectedSymbolNames  = expectedSymbolNamesStr.Split('|');
                var expectedDisplayNames = expectedSymbolDisplayNamesStr.Split('|');
                var expectedDescriptions = expectedDescriptionsStr.Split('|');
                var expectedChoices      = expectedChoicesStr?.Split('|');

                for (int i = 0; i < expectedSymbolNames.Length; i++)
                {
                    Assert.True(localizationModel.ParameterSymbols.ContainsKey(expectedSymbolNames[i]));
                    Assert.Equal(expectedDisplayNames[i] == "(null)" ? null : expectedDisplayNames[i], localizationModel.ParameterSymbols[expectedSymbolNames[i]].DisplayName);
                    Assert.Equal(expectedDescriptions[i] == "(null)" ? null : expectedDescriptions[i], localizationModel.ParameterSymbols[expectedSymbolNames[i]].Description);

                    if (expectedChoices == null || expectedChoices[i] == "(null)")
                    {
                        Assert.Empty(localizationModel.ParameterSymbols[expectedSymbolNames[i]].Choices);
                        continue;
                    }
                    var expectedChoicePairs = expectedChoices[i].Split('%');
                    foreach (var pair in expectedChoicePairs)
                    {
                        var choiceName        = pair.Split('*')[0];
                        var choiceDescription = pair.Split('*')[1];
                        var choiceDisplayName = pair.Split('*')[2];
                        Assert.True(localizationModel.ParameterSymbols[expectedSymbolNames[i]].Choices.ContainsKey(choiceName));
                        Assert.Equal(choiceDescription == "(null)" ? null : choiceDescription, localizationModel.ParameterSymbols[expectedSymbolNames[i]].Choices[choiceName].Description);
                        Assert.Equal(choiceDisplayName == "(null)" ? null : choiceDisplayName, localizationModel.ParameterSymbols[expectedSymbolNames[i]].Choices[choiceName].DisplayName);
                    }
                }
            }
            else
            {
                Assert.ThrowsAny <Exception>(() => LocalizationModelDeserializer.Deserialize(mountPoint.FileInfo(localizationFile) !));
            }
        }
        public static IFileSystemInfo ConfigFileSystemInfo(IMountPoint mountPoint, string configFile = null)
        {
            if (string.IsNullOrEmpty(configFile))
            {
                configFile = DefaultConfigRelativePath;
            }

            return(mountPoint.FileInfo(configFile));
        }
Esempio n. 4
0
        public void CanReadPostAction(
            string fileContent,
            bool errorExpected,
            string expectedPostActionsStr,
            string expectedDescriptionsStr,
            string expectedManualInstructionsStr)
        {
            IEngineEnvironmentSettings environmentSettings = _environmentSettingsHelper.CreateEnvironment(virtualize: true);
            string tempFolder       = _environmentSettingsHelper.CreateTemporaryFolder();
            string localizationFile = string.Format(DefaultLocalizeConfigRelativePath, "de-DE");

            WriteFile(Path.Combine(tempFolder, localizationFile), fileContent, environmentSettings);

            using IMountPoint mountPoint = GetMountPointForPath(tempFolder, environmentSettings);
            if (!errorExpected)
            {
                var localizationModel = LocalizationModelDeserializer.Deserialize(mountPoint.FileInfo(localizationFile) !);
                Assert.NotNull(localizationModel);

                if (string.IsNullOrEmpty(expectedPostActionsStr))
                {
                    Assert.Empty(localizationModel.PostActions);
                    return;
                }
                var expectedPostActions  = expectedPostActionsStr.Split('|');
                var expectedDescriptions = expectedDescriptionsStr.Split('|');
                var expectedInsturctions = expectedManualInstructionsStr?.Split('|');

                for (int i = 0; i < expectedPostActions.Length; i++)
                {
                    Assert.True(localizationModel.PostActions.ContainsKey(expectedPostActions[i]));
                    Assert.Equal(expectedDescriptions[i] == "(null)" ? null : expectedDescriptions[i], localizationModel.PostActions[expectedPostActions[i]].Description);

                    if (expectedInsturctions == null || expectedInsturctions[i] == "(null)")
                    {
                        Assert.Empty(localizationModel.PostActions[expectedPostActions[i]].Instructions);
                        continue;
                    }
                    var expectedInstructionPairs = expectedInsturctions[i].Split('%');
                    foreach (var pair in expectedInstructionPairs)
                    {
                        var id   = pair.Split('*')[0];
                        var text = pair.Split('*')[1];
                        Assert.True(localizationModel.PostActions[expectedPostActions[i]].Instructions.ContainsKey(id));
                        Assert.Equal(text == "(null)" ? null : text, localizationModel.PostActions[expectedPostActions[i]].Instructions[id]);
                    }
                }
            }
            else
            {
                Assert.ThrowsAny <Exception>(() => LocalizationModelDeserializer.Deserialize(mountPoint.FileInfo(localizationFile) !));
            }
        }
Esempio n. 5
0
        public bool TryGetFileFromIdAndPath(Guid mountPointId, string place, out IFile file, out IMountPoint mountPoint)
        {
            EnsureLoaded();
            if (!string.IsNullOrEmpty(place) && _mountPointManager.TryDemandMountPoint(mountPointId, out mountPoint))
            {
                file = mountPoint.FileInfo(place);
                return(file != null && file.Exists);
            }

            mountPoint = null;
            file       = null;
            return(false);
        }
Esempio n. 6
0
        // Note: this does not deal with configs split into multiple files.
        internal static IRunnableProjectConfig ConfigFromSource(IEngineEnvironmentSettings environment, IMountPoint mountPoint, string configFile = null)
        {
            if (string.IsNullOrEmpty(configFile))
            {
                configFile = DefaultConfigRelativePath;
            }

            using Stream stream             = mountPoint.FileInfo(configFile).OpenRead();
            using StreamReader streamReader = new StreamReader(stream);
            string configContent = streamReader.ReadToEnd();

            JObject configJson = JObject.Parse(configContent);

            return(SimpleConfigModel.FromJObject(environment, configJson));
        }
Esempio n. 7
0
        public void CannotValidatePostActionWithExtraInstructionLocalization()
        {
            SimpleConfigModel baseConfig = new SimpleConfigModel()
            {
                Identity         = "Test",
                PostActionModels = new List <PostActionModel>
                {
                    new PostActionModel()
                    {
                        Id                    = "pa0",
                        Description           = "text",
                        ActionId              = Guid.NewGuid(),
                        ManualInstructionInfo = new List <ManualInstructionModel>()
                        {
                            new ManualInstructionModel("first", "my text"),
                            new ManualInstructionModel("second", "my text"),
                        }
                    },
                }
            };

            List <(LogLevel, string)>  loggedMessages      = new List <(LogLevel, string)>();
            InMemoryLoggerProvider     loggerProvider      = new InMemoryLoggerProvider(loggedMessages);
            IEngineEnvironmentSettings environmentSettings = _environmentSettingsHelper.CreateEnvironment(virtualize: true, addLoggerProviders: new[] { loggerProvider });
            string tempFolder           = _environmentSettingsHelper.CreateTemporaryFolder();
            string localizationFilename = string.Format(DefaultLocalizeConfigRelativePath, "de-DE");

            WriteFile(
                Path.Combine(tempFolder, localizationFilename),
                "{ \"postActions/pa0/manualInstructions/first/text\": \"localized\", \"postActions/pa0/manualInstructions/extra/text\": \"extraLoc\" }",
                environmentSettings);

            using IMountPoint mountPoint = GetMountPointForPath(tempFolder, environmentSettings);

            var templateConfig    = new RunnableProjectConfig(environmentSettings, A.Fake <IGenerator>(), baseConfig);
            var localizationFile  = mountPoint.FileInfo(localizationFilename);
            var localizationModel = LocalizationModelDeserializer.Deserialize(localizationFile !);

            Assert.False(templateConfig.VerifyLocalizationModel(localizationModel, localizationFile));

            var warningMessages = loggedMessages.Where(log => log.Item1 == LogLevel.Warning);

            Assert.Single(warningMessages);
            Assert.Contains(
                string.Format(LocalizableStrings.Authoring_InvalidManualInstructionLocalizationIndex, "extra", "pa0"),
                warningMessages.Single().Item2);
            Assert.Contains(localizationFilename, warningMessages.Single().Item2);
        }
Esempio n. 8
0
        public void CanReadLocalizationFile(string fileContent, bool errorExpected)
        {
            IEngineEnvironmentSettings environmentSettings = _environmentSettingsHelper.CreateEnvironment(virtualize: true);
            string tempFolder       = _environmentSettingsHelper.CreateTemporaryFolder();
            string localizationFile = string.Format(DefaultLocalizeConfigRelativePath, "de-DE");

            WriteFile(Path.Combine(tempFolder, localizationFile), fileContent, environmentSettings);

            using IMountPoint mountPoint = GetMountPointForPath(tempFolder, environmentSettings);
            if (!errorExpected)
            {
                var localizationModel = LocalizationModelDeserializer.Deserialize(mountPoint.FileInfo(localizationFile) !);
                Assert.NotNull(localizationModel);
            }
            else
            {
                Assert.ThrowsAny <Exception>(() => LocalizationModelDeserializer.Deserialize(mountPoint.FileInfo(localizationFile) !));
            }
        }