fixture.cs

来自「NHibernate NET开发者所需的」· CS 代码 · 共 60 行

CS
60
字号
using log4net;
using NHibernate.Cfg;
using NHibernate.Event;
using NUnit.Framework;

namespace NHibernate.Test.NHSpecificTest.NH1332
{
	[TestFixture]
	public class Fixture : BugTestCase
	{
		private static readonly ILog log = LogManager.GetLogger(typeof(Fixture));

		public override string BugNumber
		{
			get { return "NH1332"; }
		}

		protected override void Configure(Configuration configuration)
		{
			configuration.SetProperty(Environment.UseSecondLevelCache, "false");
			configuration.SetProperty(Environment.UseQueryCache, "false");
			configuration.SetProperty(Environment.CacheProvider, null);
			configuration.SetListener(ListenerType.PostCommitDelete, new PostCommitDelete());
		}

		[Test]
		public void Bug()
		{
			A a = new A("NH1332");
			using (ISession s = OpenSession())
			using (ITransaction tx = s.BeginTransaction())
			{
				
				s.Save(a);
				tx.Commit();
			}
			using (LogSpy ls = new LogSpy(log))
			{
				using (ISession s = OpenSession())
				using (ITransaction tx = s.BeginTransaction())
				{
					s.Delete(a);
					tx.Commit();
				}
				Assert.AreEqual(1, ls.Appender.GetEvents().Length);
				string logs = ls.Appender.GetEvents()[0].RenderedMessage;
				Assert.Greater(logs.IndexOf("PostCommitDelete fired."), -1);
			}
		}

		public class PostCommitDelete : IPostDeleteEventListener
		{
			public void OnPostDelete(PostDeleteEvent @event)
			{
				log.Debug("PostCommitDelete fired.");
			}
		}
	}
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?