Skip to content

Open-source eCommerce platform for C# and ASP.NET Core 10 with MongoDB. Build multi-store shops and multi-vendor marketplaces with B2B/B2C, REST API, plugins, Vue 3 and Docker.

1.2 KB
Raw Blame
using System.Text.RegularExpressions;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Theme.Nordic;

namespace Grand.Modules.Tests.Themes;

[TestClass]
public class NordicThemeResourcesTests
{
    private static string NordicViews => Path.Combine(Installer.RepositoryPaths.Root, "src", "Plugins", "Theme.Nordic", "Views", "Nordic");

    [TestMethod]
    public void EveryThemeResourceUsedInViewsIsInstalledByThePlugin()
    {
        var used = Directory.GetFiles(NordicViews, "*.cshtml", SearchOption.AllDirectories)
            .SelectMany(f => Regex.Matches(File.ReadAllText(f), @"""(Theme\.Nordic\.[^""]+)""").Select(m => m.Groups[1].Value))
            .Distinct()
            .ToList();

        var missing = used.Where(key => !NordicThemePlugin.Resources.ContainsKey(key)).ToList();
        Assert.AreEqual(0, missing.Count, $"not installed by NordicThemePlugin: {string.Join(", ", missing)}");
    }

    [TestMethod]
    public void ThemeResourcesAreNamespacedAndHaveValues()
    {
        foreach (var (name, value) in NordicThemePlugin.Resources)
        {
            StringAssert.StartsWith(name, "Theme.Nordic.");
            Assert.IsFalse(string.IsNullOrWhiteSpace(value), name);
        }
    }
}