public void AllErrorCodes_ArePresentInTranslation(ErrorCode errorCode) { // Store the english translator for other tests... if (_englishTranslator == null) { _englishTranslator = new BasicTranslator(Path.Combine(_translationTestHelper.FindTranslationFolder(), "english.ini")); } var section = "ErrorCodes"; int exitCode = (int)errorCode; var defaultValue = StringValueAttribute.GetValue(errorCode); Assert.AreEqual(defaultValue, _englishTranslator.GetTranslation(section, exitCode.ToString()), $"The value for {errorCode} ({exitCode}) is not set!\r\nAdd:\r\n{exitCode}={defaultValue}"); }
public void SetUp() { _translationTestHelper = new TranslationTestHelper(); var a = Assembly.GetExecutingAssembly(); var appDir = Path.GetDirectoryName(a.CodeBase.Replace(@"file:///", "")); if (appDir == null) { throw new InvalidDataException("The app dir may never be null"); } _languagePath = _translationTestHelper.FindTranslationFolder(); Assert.True(Directory.Exists(_languagePath), "Could not find language path: " + _languagePath); var languageLoader = new LanguageLoader(_languagePath); _translations = languageLoader.GetAvailableLanguages().ToList(); _settings = new PdfCreatorSettings(new IniStorage()); _settings.LoadData("settings.ini"); var assemblyHelper = Substitute.For <IAssemblyHelper>(); assemblyHelper.GetPdfforgeAssemblyDirectory().Returns(Path.Combine(_languagePath, "..")); LoggingHelper.InitConsoleLogger("PDFCreator-TranslationTest", LoggingLevel.Error); var settingsProvider = new DefaultSettingsProvider(); settingsProvider.UpdateSettings(_settings); _translationProxy = new MappedTranslationProxy(new TranslationProxy(), _languagePath + "\\_sectionMappings.txt"); _translationHelper = new TranslationHelper(_translationProxy, settingsProvider, assemblyHelper); _translationHelper.InitTranslator(_settings.ApplicationSettings.Language); // TODO extact stuff into separate classes, so this test only contains the actual test code }
public void AllErrorCodes_AreMappedByErrorCodeInterpreter() { var section = "ErrorCodes"; var translator = new BasicTranslator(Path.Combine(_translationTestHelper.FindTranslationFolder(), "english.ini")); var errorCodes = translator.GetKeysForSection(section) .Where(IsInt) .Select(int.Parse) .Select(x => (ErrorCode)x) .ToList(); Assert.IsTrue(errorCodes.Any(), $"There are no entries in the section [{section}]"); var errorCodeInterpreter = new ErrorCodeInterpreter(translator); foreach (var errorCode in errorCodes) { Assert.IsTrue(Enum.IsDefined(typeof(ErrorCode), errorCode), $"The error code {(int)errorCode} is not defined"); var message = errorCodeInterpreter.GetErrorText(errorCode, true); StringAssert.DoesNotContain("Default", message, $"Error code {errorCode} contains the word 'default', which indicates that it has not been translated."); StringAssert.DoesNotContain(translator.GetTranslation(section, "Default"), message, $"Error code {errorCode} has the default translation!"); } }