Files
Umbraco-CMS/src/Umbraco.Tests/Install/UpgradeScriptsTests.cs
Shannon Deminick a5bea7fc59 Added the ability to automate any c# scripts for an upgrade process. I realize this is superceded already in 6.0
but we need a way to do this in 4.x too especially for this release since we need to run a script to fix some db
issues. I've added a framework using an UpgradeScriptManager and another install step + unit tests for some of the
UpgradeScriptManager methods.
2013-01-31 04:26:37 +06:00

67 lines
2.5 KiB
C#

using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using NUnit.Framework;
using Umbraco.Web.Install.UpgradeScripts;
namespace Umbraco.Tests.Install
{
[TestFixture]
public class UpgradeScriptsTests
{
[TearDown]
public void TearDown()
{
UpgradeScriptManager.Clear();
}
[TestCase("0.0.0", "6.0.0", "4.10.0", true)]
[TestCase("4.10.0", "6.0.0", "4.10.0", true)]
[TestCase("4.10.0", "4.11.4", "4.10.0", true)]
[TestCase("4.11.0", "4.11.4", "4.10.0", false)]
[TestCase("4.11.0", "6.0.0", "4.10.0", false)]
[TestCase("6.0.0", "6.0.0", "6.0.0", false)] //this is not in range because it is up to 6.0 but not including 6.0
[TestCase("6.0.0", "6.0.0", "6.0.1", false)]
public void Test_Version_Range(string startVersion, string endVersion, string current, bool inRange)
{
var currVersionParts = current.Split('.').Select(int.Parse).ToArray();
var currentVersion = new Version(currVersionParts[0], currVersionParts[1], currVersionParts[2]);
var startVersionParts = startVersion.Split('.').Select(int.Parse).ToArray();
var endVersionParts = endVersion.Split('.').Select(int.Parse).ToArray();
UpgradeScriptManager.AddUpgradeScript<UpgradeScript1>(
new VersionRange(
new Version(startVersionParts[0], startVersionParts[1], startVersionParts[2]),
new Version(endVersionParts[0], endVersionParts[1], endVersionParts[2])));
Assert.AreEqual(inRange, UpgradeScriptManager.HasScriptsForVersion(currentVersion));
}
[Test]
public void Test_Specific_Version()
{
var currentVersion = new Version(4, 10, 0);
UpgradeScriptManager.AddUpgradeScript<UpgradeScript1>(
new VersionRange(
new Version(4, 10, 0)));
Assert.IsTrue(UpgradeScriptManager.HasScriptsForVersion(currentVersion));
Assert.IsFalse(UpgradeScriptManager.HasScriptsForVersion(new Version(4, 10, 11)));
Assert.IsFalse(UpgradeScriptManager.HasScriptsForVersion(new Version(4, 11, 0)));
}
public class UpgradeScript1 : IUpgradeScript
{
public void Execute()
{
Debug.WriteLine("Executing!");
}
}
}
}