using Centron.Tests.EndToEnd.Infrastructure; using System; using Xunit; using Xunit.Abstractions; using Centron.BusinessLogic.Administration.Scripts.ScriptMethods; using System.Text.RegularExpressions; using System.Linq; namespace Centron.Tests.EndToEnd.Tests.ScriptMethods { public class ScriptMethodTests : CentronTest { public ScriptMethodTests(ITestOutputHelper testOutputHelper) : base(testOutputHelper) { } [Fact] public void CheckScriptNumbers() { var pool = new ScriptMethodPool(); foreach (var currentMethod in pool.ScriptMethods) { var numberInClassNameMatch = Regex.Match(currentMethod.GetType().Name, "\\d{5,}"); Assert.True(numberInClassNameMatch.Success, $"{currentMethod.GetType().Name} does not have a scriptnumber in its classname"); var numberInClassName = int.Parse(numberInClassNameMatch.Value); Assert.Equal(numberInClassName, currentMethod.ScriptNumber); } var doubles = pool.ScriptMethods.GroupBy(f => f.ScriptNumber).Where(f => f.Count() != 1).ToList(); Assert.Empty(doubles); } [Fact] public void CheckNoNewRiverScriptNumbers() { // We used to have a lot of scripts with numbers above 50000 from riverbird // They got removed from our code-base when we forked the code-base // But that means, there are lots of customer databases out there, that have already executed scripts above 50000 // If we now accidentally use one of those script numbers ourselves, then that script might not get executed for all customers // So this test checks, that we don't accidentally add a new script with number above 50000 var pool = new ScriptMethodPool(); var riverScripts = pool.ScriptMethods .Where(f => f.ScriptNumber >= 50000) .Select(f => new { ScriptNumber = f.ScriptNumber, Name = f.GetType().Name }) .ToList(); this.Verifier.Verify("RiverScripts", riverScripts); } } }