2025-10-31 23:50:28 +01:00
|
|
|
using System;
|
2015-12-13 22:21:02 +01:00
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Data;
|
|
|
|
|
using System.Diagnostics;
|
|
|
|
|
using System.IO;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using Autofac;
|
|
|
|
|
using NHibernate;
|
|
|
|
|
using NUnit.Framework;
|
|
|
|
|
using Orchard.ContentManagement.FieldStorage.InfosetStorage;
|
|
|
|
|
using Orchard.ContentManagement.Handlers;
|
|
|
|
|
using Orchard.Data;
|
|
|
|
|
using Orchard.Environment.Configuration;
|
|
|
|
|
using Orchard.Services;
|
|
|
|
|
using Orchard.Tests.ContentManagement;
|
|
|
|
|
using Orchard.Tests.Stubs;
|
|
|
|
|
|
2025-10-31 23:50:28 +01:00
|
|
|
namespace Orchard.Tests.Modules
|
|
|
|
|
{
|
|
|
|
|
public abstract class DatabaseEnabledTestsBase
|
|
|
|
|
{
|
2015-12-13 22:21:02 +01:00
|
|
|
|
|
|
|
|
protected IContainer _container;
|
|
|
|
|
protected ITransaction _transaction;
|
|
|
|
|
|
|
|
|
|
protected ISession _session;
|
|
|
|
|
protected string _databaseFilePath;
|
|
|
|
|
protected ISessionFactory _sessionFactory;
|
|
|
|
|
protected StubClock _clock;
|
|
|
|
|
|
|
|
|
|
|
2025-09-19 22:57:28 +02:00
|
|
|
[OneTimeSetUp]
|
2025-10-31 23:50:28 +01:00
|
|
|
public void InitFixture()
|
|
|
|
|
{
|
2015-12-13 22:21:02 +01:00
|
|
|
}
|
|
|
|
|
|
2025-09-19 22:57:28 +02:00
|
|
|
[OneTimeTearDown]
|
2025-10-31 23:50:28 +01:00
|
|
|
public void TearDownFixture()
|
|
|
|
|
{
|
2015-12-13 22:21:02 +01:00
|
|
|
File.Delete(_databaseFilePath);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[SetUp]
|
2025-10-31 23:50:28 +01:00
|
|
|
public virtual void Init()
|
|
|
|
|
{
|
2015-12-13 22:21:02 +01:00
|
|
|
_databaseFilePath = Path.GetTempFileName();
|
|
|
|
|
_sessionFactory = DataUtility.CreateSessionFactory(_databaseFilePath, DatabaseTypes.ToArray());
|
|
|
|
|
_session = _sessionFactory.OpenSession();
|
|
|
|
|
_transaction = _session.BeginTransaction(IsolationLevel.ReadCommitted);
|
|
|
|
|
|
|
|
|
|
_clock = new StubClock();
|
|
|
|
|
|
|
|
|
|
var builder = new ContainerBuilder();
|
|
|
|
|
//builder.RegisterModule(new ImplicitCollectionSupportModule());
|
|
|
|
|
builder.RegisterType<InfosetHandler>().As<IContentHandler>();
|
|
|
|
|
builder.RegisterInstance(_clock).As<IClock>();
|
|
|
|
|
builder.RegisterGeneric(typeof(Repository<>)).As(typeof(IRepository<>));
|
|
|
|
|
builder.RegisterInstance(new ShellSettings { Name = ShellSettings.DefaultName, DataProvider = "SqlCe" });
|
|
|
|
|
builder.RegisterInstance(new TestTransactionManager(_session)).As<ITransactionManager>();
|
|
|
|
|
Register(builder);
|
|
|
|
|
_container = builder.Build();
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[TearDown]
|
2025-10-31 23:50:28 +01:00
|
|
|
public virtual void Cleanup()
|
|
|
|
|
{
|
|
|
|
|
if (_container != null)
|
2015-12-13 22:21:02 +01:00
|
|
|
_container.Dispose();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public abstract void Register(ContainerBuilder builder);
|
|
|
|
|
|
2025-10-31 23:50:28 +01:00
|
|
|
protected virtual IEnumerable<Type> DatabaseTypes => Enumerable.Empty<Type>();
|
|
|
|
|
|
|
|
|
|
protected void ClearSession()
|
|
|
|
|
{
|
2015-12-13 22:21:02 +01:00
|
|
|
Trace.WriteLine("Flush and clear session");
|
|
|
|
|
_transaction.Commit();
|
|
|
|
|
_session.Clear();
|
|
|
|
|
_transaction = _session.BeginTransaction(IsolationLevel.ReadCommitted);
|
|
|
|
|
Trace.WriteLine("Flushed and cleared session");
|
|
|
|
|
}
|
|
|
|
|
}
|
2025-11-26 17:07:59 +01:00
|
|
|
}
|