Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

adding unit test for validating language xml files. #7174

Merged
merged 8 commits into from
Nov 1, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 51 additions & 0 deletions src/Umbraco.Tests/Configurations/LanguageXmlTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Xml;
using NUnit.Framework;
using Umbraco.Tests.TestHelpers;

namespace Umbraco.Tests.Configurations
{
[TestFixture]
public class LanguageXmlTests
{
[Test]
public void Can_Load_Language_Xml_Files()
{
var languageDirectory = GetLanguageDirectory();
var readFilesCount = 0;
var xmlDocument = new XmlDocument();
foreach (var languageFile in languageDirectory.EnumerateFiles("*.xml"))
{
// Load will throw an exception if the XML isn't valid.
xmlDocument.Load(languageFile.FullName);
readFilesCount++;
}

// Ensure that at least one file was read.
Assert.AreNotEqual(0, readFilesCount);
}

private static DirectoryInfo GetLanguageDirectory()
{
var testDirectoryPathParts = Path.GetDirectoryName(TestContext.CurrentContext.TestDirectory)
.Split(new[] { Path.DirectorySeparatorChar }, StringSplitOptions.RemoveEmptyEntries);
var solutionDirectoryPathParts = testDirectoryPathParts
.Take(Array.IndexOf(testDirectoryPathParts, "src") + 1);
var languageFolderPathParts = new List<string>(solutionDirectoryPathParts);
var additionalPathParts = new[] { "Umbraco.Web.UI", "Umbraco", "config", "lang" };
languageFolderPathParts.AddRange(additionalPathParts);

// Hack for build-server - when this path is generated in that envrionment it's missing the "src" folder.
// Not sure why, but if it's missing we'll add it in the right place.
if (!languageFolderPathParts.Contains("src"))
{
languageFolderPathParts.Insert(languageFolderPathParts.Count - additionalPathParts.Length, "src");
}

return new DirectoryInfo(string.Join(Path.DirectorySeparatorChar.ToString(), languageFolderPathParts));
}
}
}
1 change: 1 addition & 0 deletions src/Umbraco.Tests/Umbraco.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@
<Compile Include="Composing\CompositionTests.cs" />
<Compile Include="Composing\LightInjectValidation.cs" />
<Compile Include="Composing\ContainerConformingTests.cs" />
<Compile Include="Configurations\LanguageXmlTests.cs" />
<Compile Include="Configurations\GlobalSettingsTests.cs" />
<Compile Include="CoreThings\CallContextTests.cs" />
<Compile Include="Components\ComponentTests.cs" />
Expand Down