Some test fixes and more test temp file cleanup

--HG--
branch : dev
This commit is contained in:
Nathan Heskew
2010-11-19 23:41:33 -08:00
parent 48c8ec4571
commit 5393c5c825
10 changed files with 253 additions and 221 deletions

View File

@@ -30,6 +30,7 @@ using Orchard.Tests.ContentManagement;
using Orchard.Data.Providers;
using Orchard.Tests.FileSystems.AppData;
using Orchard.Tests.Modules.Migrations.Orchard.Tests.DataMigration.Records;
using Path = Bleroy.FluentPath.Path;
namespace Orchard.Tests.Modules.Migrations {
[TestFixture]
@@ -37,9 +38,10 @@ namespace Orchard.Tests.Modules.Migrations {
private IContainer _container;
private StubFolders _folders;
private ISchemaCommandGenerator _generator;
private ISessionFactory _sessionFactory;
private ISession _session;
private readonly Path _tempFixtureFolderName = Path.Get(System.IO.Path.GetTempPath()).Combine("Orchard.Tests.Modules.Migrations");
private Path _tempFolderName;
[TestFixtureSetUp]
public void CreateDb() {
@@ -51,9 +53,13 @@ namespace Orchard.Tests.Modules.Migrations {
typeof(ContentItemRecord),
typeof(ContentTypeRecord)};
var databaseFileName = System.IO.Path.GetTempFileName();
_tempFolderName = _tempFixtureFolderName.Combine(System.IO.Path.GetRandomFileName());
try {
_tempFixtureFolderName.Delete(true);
} catch {}
_tempFixtureFolderName.CreateDirectory();
_sessionFactory = DataUtility.CreateSessionFactory(
databaseFileName, types);
_tempFolderName, types);
var builder = new ContainerBuilder();
_folders = new StubFolders();
@@ -65,7 +71,7 @@ namespace Orchard.Tests.Modules.Migrations {
});
builder.RegisterInstance(new ShellSettings { Name = "Default", DataTablePrefix = "TEST", DataProvider = "SqlCe" });
builder.RegisterInstance(AppDataFolderTests.CreateAppDataFolder(Path.GetDirectoryName(databaseFileName))).As<IAppDataFolder>();
builder.RegisterInstance(AppDataFolderTests.CreateAppDataFolder(_tempFixtureFolderName)).As<IAppDataFolder>();
builder.RegisterType<SessionConfigurationCache>().As<ISessionConfigurationCache>();
builder.RegisterType<SqlCeDataServicesProvider>().As<IDataServicesProvider>();
builder.RegisterInstance(manager).As<IDataServicesProviderFactory>();
@@ -95,6 +101,12 @@ Features:
");
}
[TestFixtureTearDown]
public void Term() {
try { _tempFixtureFolderName.Delete(true); }
catch { }
}
public class StubFolders : IExtensionFolders {
public StubFolders() {
Manifests = new Dictionary<string, string>();

View File

@@ -69,6 +69,9 @@
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\lib\fluentnhibernate\FluentNHibernate.dll</HintPath>
</Reference>
<Reference Include="FluentPath">
<HintPath>..\..\lib\fluentpath\FluentPath.dll</HintPath>
</Reference>
<Reference Include="IronRuby, Version=1.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\lib\dlr\IronRuby.dll</HintPath>

View File

@@ -6,14 +6,16 @@ using Autofac;
using ClaySharp;
using NUnit.Framework;
using Orchard.Scripting.Services;
using Path = Bleroy.FluentPath.Path;
namespace Orchard.Tests.Scripting {
namespace Orchard.Tests.Modules.Scripting {
[TestFixture]
public class ScriptingTests {
private IContainer _container;
private IScriptingRuntime _scriptingRuntime;
private IScriptingManager _scriptingManager;
private string _tempFolderName;
private readonly Path _tempFixtureFolderName = Path.Get(System.IO.Path.GetTempPath()).Combine("Orchard.Tests.Modules.Scripting");
private Path _tempFolderName;
[SetUp]
public void Init() {
@@ -23,14 +25,18 @@ namespace Orchard.Tests.Scripting {
_container = builder.Build();
_scriptingRuntime = _container.Resolve<IScriptingRuntime>();
_scriptingManager = _container.Resolve<IScriptingManager>();
_tempFolderName = Path.GetTempFileName();
File.Delete(_tempFolderName);
Directory.CreateDirectory(_tempFolderName);
_tempFolderName = _tempFixtureFolderName.Combine(System.IO.Path.GetRandomFileName());
try {
_tempFolderName.Delete();
}
catch { }
_tempFolderName.CreateDirectory();
}
[TearDown]
public void Term() {
Directory.Delete(_tempFolderName, true);
try { _tempFixtureFolderName.Delete(true); }
catch { }
}
[Test]
@@ -71,7 +77,7 @@ namespace Orchard.Tests.Scripting {
[Test]
public void ScriptingManagerCanExecuteFile() {
var targetPath = Path.Combine(_tempFolderName, "SampleMethodDefinition.rb");
var targetPath = _tempFolderName.Combine("SampleMethodDefinition.rb");
File.WriteAllText(targetPath, "def f\r\nreturn 32\r\nend\r\n");
_scriptingManager.ExecuteFile(targetPath);
Assert.That(_scriptingManager.ExecuteExpression("f / 4"), Is.EqualTo(8));
@@ -95,7 +101,7 @@ namespace Orchard.Tests.Scripting {
[Test]
public void CanDeclareCallbackOnInstanceEvalWithFile() {
var targetPath = Path.Combine(_tempFolderName, "CallbackOnInstanceEval.rb");
var targetPath = _tempFolderName.Combine("CallbackOnInstanceEval.rb");
File.WriteAllText(targetPath, "class ExecContext\r\ndef initialize(callbacks)\r\n@callbacks = callbacks;\r\nend\r\ndef execute(text)\r\ninstance_eval(text.to_s);\r\nend\r\ndef method_missing(name, *args, &block)\r\n@callbacks.send(name, args, &block);\r\nend\r\nend\r\ndef execute(&block)\r\nExecContext.new(callbacks).instance_eval(&block);\r\nend\r\n");
_scriptingManager.ExecuteFile(targetPath);
_scriptingManager.SetVariable("callbacks", new CallbackApi());