|
| 1 | +using System; |
| 2 | +using System.Collections.Generic; |
| 3 | +using System.IO; |
| 4 | +using System.Linq; |
| 5 | +using System.Xml; |
| 6 | +using NUnit.Framework; |
| 7 | +using Umbraco.Tests.TestHelpers; |
| 8 | + |
| 9 | +namespace Umbraco.Tests.Configurations |
| 10 | +{ |
| 11 | + [TestFixture] |
| 12 | + public class LanguageXmlTests |
| 13 | + { |
| 14 | + [Test] |
| 15 | + public void Can_Load_Language_Xml_Files() |
| 16 | + { |
| 17 | + var languageDirectory = GetLanguageDirectory(); |
| 18 | + var readFilesCount = 0; |
| 19 | + var xmlDocument = new XmlDocument(); |
| 20 | + foreach (var languageFile in languageDirectory.EnumerateFiles("*.xml")) |
| 21 | + { |
| 22 | + // Load will throw an exception if the XML isn't valid. |
| 23 | + xmlDocument.Load(languageFile.FullName); |
| 24 | + readFilesCount++; |
| 25 | + } |
| 26 | + |
| 27 | + // Ensure that at least one file was read. |
| 28 | + Assert.AreNotEqual(0, readFilesCount); |
| 29 | + } |
| 30 | + |
| 31 | + private static DirectoryInfo GetLanguageDirectory() |
| 32 | + { |
| 33 | + var testDirectoryPathParts = Path.GetDirectoryName(TestContext.CurrentContext.TestDirectory) |
| 34 | + .Split(new[] { Path.DirectorySeparatorChar }, StringSplitOptions.RemoveEmptyEntries); |
| 35 | + var solutionDirectoryPathParts = testDirectoryPathParts |
| 36 | + .Take(Array.IndexOf(testDirectoryPathParts, "src") + 1); |
| 37 | + var languageFolderPathParts = new List<string>(solutionDirectoryPathParts); |
| 38 | + var additionalPathParts = new[] { "Umbraco.Web.UI", "Umbraco", "config", "lang" }; |
| 39 | + languageFolderPathParts.AddRange(additionalPathParts); |
| 40 | + |
| 41 | + // Hack for build-server - when this path is generated in that envrionment it's missing the "src" folder. |
| 42 | + // Not sure why, but if it's missing we'll add it in the right place. |
| 43 | + if (!languageFolderPathParts.Contains("src")) |
| 44 | + { |
| 45 | + languageFolderPathParts.Insert(languageFolderPathParts.Count - additionalPathParts.Length, "src"); |
| 46 | + } |
| 47 | + |
| 48 | + return new DirectoryInfo(string.Join(Path.DirectorySeparatorChar.ToString(), languageFolderPathParts)); |
| 49 | + } |
| 50 | + } |
| 51 | +} |
0 commit comments