mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2025-10-15 19:54:57 +08:00

Need to rework the host/shell container spin-off for multitenancy. Need to rework interception. dev branch is now broken until the end of this sprint, enjoy the default branch. --HG-- branch : dev
68 lines
2.0 KiB
C#
68 lines
2.0 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.IO;
|
|
using System.Linq;
|
|
using Autofac;
|
|
using NHibernate;
|
|
using NUnit.Framework;
|
|
using Orchard.Data;
|
|
using Orchard.Services;
|
|
using Orchard.Tests.Data;
|
|
using Orchard.Tests.Stubs;
|
|
|
|
namespace Orchard.Tests.Modules {
|
|
public abstract class DatabaseEnabledTestsBase {
|
|
|
|
protected IContainer _container;
|
|
|
|
protected ISession _session;
|
|
protected string _databaseFilePath;
|
|
protected ISessionFactory _sessionFactory;
|
|
protected StubClock _clock;
|
|
|
|
|
|
[TestFixtureSetUp]
|
|
public void InitFixture() {
|
|
_databaseFilePath = Path.GetTempFileName();
|
|
}
|
|
|
|
[TestFixtureTearDown]
|
|
public void TearDownFixture() {
|
|
File.Delete(_databaseFilePath);
|
|
}
|
|
|
|
[SetUp]
|
|
public virtual void Init() {
|
|
_sessionFactory = DataUtility.CreateSessionFactory(_databaseFilePath, DatabaseTypes.ToArray());
|
|
_session = _sessionFactory.OpenSession();
|
|
_clock = new StubClock();
|
|
|
|
var builder = new ContainerBuilder();
|
|
//builder.RegisterModule(new ImplicitCollectionSupportModule());
|
|
builder.RegisterInstance(new StubLocator(_session)).As<ISessionLocator>();
|
|
builder.RegisterInstance(_clock).As<IClock>();
|
|
builder.RegisterGeneric(typeof(Repository<>)).As(typeof(IRepository<>));
|
|
Register(builder);
|
|
_container = builder.Build();
|
|
}
|
|
|
|
[TearDown]
|
|
public void Cleanup() {
|
|
_container.Dispose();
|
|
_session.Close();
|
|
}
|
|
|
|
public abstract void Register(ContainerBuilder builder);
|
|
|
|
protected virtual IEnumerable<Type> DatabaseTypes {
|
|
get {
|
|
return Enumerable.Empty<Type>();
|
|
}
|
|
}
|
|
|
|
protected void ClearSession() {
|
|
_session.Flush();
|
|
_session.Clear();
|
|
}
|
|
}
|
|
} |