Files
Orchard/src/Orchard.Tests.Modules/DatabaseEnabledTestsBase.cs

86 lines
2.6 KiB
C#
Raw Normal View History

using System;
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;
namespace Orchard.Tests.Modules
{
public abstract class DatabaseEnabledTestsBase
{
protected IContainer _container;
protected ITransaction _transaction;
protected ISession _session;
protected string _databaseFilePath;
protected ISessionFactory _sessionFactory;
protected StubClock _clock;
[OneTimeSetUp]
public void InitFixture()
{
}
[OneTimeTearDown]
public void TearDownFixture()
{
File.Delete(_databaseFilePath);
}
[SetUp]
public virtual void Init()
{
_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]
public virtual void Cleanup()
{
if (_container != null)
_container.Dispose();
}
public abstract void Register(ContainerBuilder builder);
protected virtual IEnumerable<Type> DatabaseTypes => Enumerable.Empty<Type>();
protected void ClearSession()
{
Trace.WriteLine("Flush and clear session");
_transaction.Commit();
_session.Clear();
_transaction = _session.BeginTransaction(IsolationLevel.ReadCommitted);
Trace.WriteLine("Flushed and cleared session");
}
}
#8268: Getting rid of [Obsolete] stuff (Lombiq Technologies: ORCH-308) (#8873) * Using Orchard.Mvc.FormValueRequiredAttribute instead of the FormValueRequiredAttribute class of the AdminController in the Orchard.Core.Contents namespace. * Removing obsoleted Spam value from the Orchard.Comments.Models.CommentStatus enum. * Removing the obsolete AddFilters method of the IFilterProvider interface in the Orchard.Mvc.Filters namespace. * Removing the obsolete LazyField<T> class from the Orchard.Core.Common.Utilities namespace. * Removing obsolete methods from OrchardLog4netLogger. * Removing obsolete Loader(Func<T, T> loader) method from LazyField.cs in the Orchard.ContentManagement.Utilities namespace. * Removing obsoleted ContentShapeResult ContentShape(IShape shape) method from ContentPartDriver. * Removing obsoleted ISessionLocator interface. * Removing obsoleted ContentFieldTemplate methods from ContentFieldDriver<TField>. * Removing obsoleted IMessagingChannel and IMessageManager interfaces, along with the migration step that updates the existing Send Email activities to use the new Message Queueing functionality. * Removing obsoleted CustomStepsStep. Don't need the CustomStepsStep RecipeBuilderStep because you can implement IRecipeBuilderStep and IRecipeExecutionStep instead of implementing custom export steps. * Removing obsoleted CustomPropertiesPart. It used to be necessary for the List feature (also obsolete) to be able to sort on custom data. * Removing the obsoleted ITaskLeaseService with its default implementation. Removing deprecated Orchard.TaskLease module because it only contains this interface with its default implementation. Use Orchard.Tasks.Locking.IDistributedLockService instead. * Removing LegacyRulesEvaluator. This condition provider was there for backwards compatibility during the deprecation period. * Removing IRuleManager with its default implementation. Use Orchard.Conditions.Services.ConditionManager instead. * Removing unused RequiresOwnership permission. * Reverting unnecessary sln file changes * Resolving IMessageChannelSelector instead of IMessageManager in editor templates * Removing commented out code from ContentPartDriverCoordinatorTests * Removing Orchard.jQuery too since its quite outdated and Orchard.Resources has been available since 1.9 * Readding the migration step that updates the existing Send Email activities --------- Co-authored-by: Benedek Farkas <benedek.farkas@lombiq.com>
2025-11-26 17:07:59 +01:00
}