Commits

Roger Kratz  committed 1086280

removed dependency to envers test project

  • Participants
  • Parent commits 3928d1b

Comments (0)

Files changed (2)

File NHibernate.Envers.SetForNet4Test/NHibernate.Envers.SetForNet4Test.csproj

     <Reference Include="NHibernate.Envers, Version=1.1.0.1, Culture=neutral, PublicKeyToken=e2c5b946037fb7f8, processorArchitecture=MSIL">
       <HintPath>..\lib\NHibernate.Envers.dll</HintPath>
     </Reference>
-    <Reference Include="NHibernate.Envers.Tests, Version=1.1.0.1, Culture=neutral, processorArchitecture=MSIL">
-      <HintPath>..\lib\NHibernate.Envers.Tests.dll</HintPath>
-    </Reference>
     <Reference Include="NHibernateSetForNet4, Version=1.0.0.0, Culture=neutral, processorArchitecture=MSIL">
       <HintPath>..\lib\NHibernateSetForNet4.dll</HintPath>
     </Reference>

File NHibernate.Envers.SetForNet4Test/Tests/SimpleTest.cs

 using System;
+using NHibernate.Cfg;
 using NHibernate.Envers.Configuration;
+using NHibernate.Envers.Configuration.Fluent;
 using NHibernate.Envers.SetForNet4;
-using NHibernate.Envers.Tests;
 using NHibernateSetForNet4;
 using NUnit.Framework;
 using SharpTestsEx;
 namespace NHibernate.Envers.SetForNet4Test.Tests
 {
 	[TestFixture]
-	public class SimpleTest : TestBase
+	public class SimpleTest
 	{
 		private Guid parentId;
 		private Guid childId1;
 		private Guid childId2;
+		private ISessionFactory sessionFactory;
 
-		protected override void AddToConfiguration(Cfg.Configuration configuration)
+		[SetUp]
+		public void Setup()
 		{
+			var cfg = new Cfg.Configuration();
 			//for nh core
-			configuration.Properties[Environment.CollectionTypeFactoryClass] 
-				= typeof(Net4CollectionTypeFactory).AssemblyQualifiedName;
+			cfg.Properties[Environment.CollectionTypeFactoryClass] = typeof(Net4CollectionTypeFactory).AssemblyQualifiedName;
+			//for nh envers
+			cfg.Properties[ConfigurationKey.CollectionProxyMapperFactory] = typeof(CollectionProxyMapperFactoryForNet4).AssemblyQualifiedName;
+			cfg.Configure();
+			cfg.AddAssembly(GetType().Assembly);
+			var enversCfg = new FluentConfiguration();
+			enversCfg.Audit<ParentEntity>();
+			cfg.IntegrateWithEnvers(enversCfg);
+			sessionFactory = cfg.BuildSessionFactory();
 
-			//for nh envers
-			configuration.Properties[ConfigurationKey.CollectionProxyMapperFactory] = typeof(CollectionProxyMapperFactoryForNet4).AssemblyQualifiedName;
+			setupData();
 		}
 
-		protected override void Initialize()
+		private void setupData()
 		{
 			var child1 = new ParentEntity("child1");
 			var child2 = new ParentEntity("child2");
 			var parent = new ParentEntity("parent");
 			parent.Children.Add(child1);
 			parent.Children.Add(child2);
-			
-			// Revision 1 (parent with two children))
-			using (var tx = Session.BeginTransaction())
+
+			using (var session = sessionFactory.OpenSession())
 			{
-				childId1 = (Guid) Session.Save(child1);
-				childId2 = (Guid) Session.Save(child2);
-				parentId = (Guid)Session.Save(parent);
-				parent.Children.Add(child1);
-				parent.Children.Add(child2);
-				tx.Commit();
-			}
-			// Revision 2 (changing child1)
-			using (var tx = Session.BeginTransaction())
-			{
-				child1.Name = "changed";
-				tx.Commit();
+				// Revision 1 (parent with two children))
+				using (var tx = session.BeginTransaction())
+				{
+					childId1 = (Guid)session.Save(child1);
+					childId2 = (Guid)session.Save(child2);
+					parentId = (Guid)session.Save(parent);
+					parent.Children.Add(child1);
+					parent.Children.Add(child2);
+					tx.Commit();
+				}
+				// Revision 2 (changing child1)
+				using (var tx = session.BeginTransaction())
+				{
+					child1.Name = "changed";
+					tx.Commit();
+				}	
 			}
 		}
 
 		[Test]
 		public void VerifyRevisionCount()
 		{
-			CollectionAssert.AreEquivalent(new[] { 1 }, AuditReader().GetRevisions(typeof(ParentEntity), parentId));
-			CollectionAssert.AreEquivalent(new[] { 1, 2}, AuditReader().GetRevisions(typeof(ParentEntity), childId1));
-			CollectionAssert.AreEquivalent(new[] { 1 }, AuditReader().GetRevisions(typeof(ParentEntity), childId2));
+			using (var session = sessionFactory.OpenSession())
+			{
+				CollectionAssert.AreEquivalent(new[] { 1 }, session.Auditer().GetRevisions(typeof(ParentEntity), parentId));
+				CollectionAssert.AreEquivalent(new[] { 1, 2 }, session.Auditer().GetRevisions(typeof(ParentEntity), childId1));
+				CollectionAssert.AreEquivalent(new[] { 1 }, session.Auditer().GetRevisions(typeof(ParentEntity), childId2));
+			}
 		}
 
 		[Test]
 		public void VerifyHistoryOfParent()
 		{
-			var rev1 = AuditReader().Find<ParentEntity>(parentId, 1);
-			var child1 = new ParentEntity("dummy"){Id = childId1};
-			var child2 = new ParentEntity("dummy"){Id = childId2};
+			using (var session = sessionFactory.OpenSession())
+			{
+				var rev1 = session.Auditer().Find<ParentEntity>(parentId, 1);
+				var child1 = new ParentEntity("dummy") {Id = childId1};
+				var child2 = new ParentEntity("dummy") {Id = childId2};
 
-			rev1.Children.SetEquals(new[]{child1, child2})
-				.Should().Be.True();
+				rev1.Children.SetEquals(new[] {child1, child2})
+					.Should().Be.True();
 
-			foreach (var child in rev1.Children)
-			{
-				child.Name.Should().Not.Be.EqualTo("changed");
+				foreach (var child in rev1.Children)
+				{
+					child.Name.Should().Not.Be.EqualTo("changed");
+				}
 			}
 		}
 
 		[Test]
 		public void VerifyHistoryOfChild1()
 		{
-			var rev1 = AuditReader().Find<ParentEntity>(childId1, 1);
-			var rev2 = AuditReader().Find<ParentEntity>(childId1, 2);
+			using (var session = sessionFactory.OpenSession())
+			{
+				var rev1 = session.Auditer().Find<ParentEntity>(childId1, 1);
+				var rev2 = session.Auditer().Find<ParentEntity>(childId1, 2);
 
-			rev1.Name
-				.Should().Be.EqualTo("child1");
-			rev2.Name
-				.Should().Be.EqualTo("changed");
+				rev1.Name.Should().Be.EqualTo("child1");
+				rev2.Name.Should().Be.EqualTo("changed");
+			}
 		}
 
 		[Test]
 		public void VerifyHistoryOfChild2()
 		{
-			var rev1 = AuditReader().Find<ParentEntity>(childId2, 1);
+			using (var session = sessionFactory.OpenSession())
+			{
+				var rev1 = session.Auditer().Find<ParentEntity>(childId2, 1);
 
-			rev1.Name
-				.Should().Be.EqualTo("child2");
+				rev1.Name.Should().Be.EqualTo("child2");
+			}
 		}
 	}
 }