<commit_before>using System;
using System.Collections;

using NHibernate;
using NHibernate.Cfg;
using NHibernate.Tool.hbm2ddl;

using NUnit.Framework;

namespace NHibernate.Examples.Blogger 
{

	/// <summary>
	/// Summary description for BloggerFixture.
	/// </summary>
	[TestFixture]
	public class BloggerFixture 
	{

		private ISessionFactory _sessions; 

		[Test]
		public void Main() 
		{
			Configure();
			ExportTables();
			Blog blog = CreateBlog("GregBlog");
			Assert.IsTrue( blog.Id!=0, "The Id should have been assigned by the native generator" );
			
			BlogItem blogItem = CreateBlogItem(blog, "new item", "Required introduction in every blog.");
			Assert.IsTrue( blogItem.Id!=0, "The Id should have been assigned by the native generator" ); 
			Assert.AreEqual( blog, blogItem.ParentBlog, "The BlogItem's Parent should be the Blog" );
			Assert.AreEqual( "new item", blogItem.Title, "correct title was saved" );
			Assert.AreEqual( "Required introduction in every blog.", blogItem.Text, "correct text was saved." );

			BlogItem blogItem2 = CreateBlogItem(blog.Id, "item 2", "Finally some cool stuff in my second blog.");
			Assert.IsTrue( blogItem2.Id!=0, "The Id should have been assigned by the native generator." );
			Assert.AreEqual( "item 2", blogItem2.Title, "correct title was saved" );
			Assert.AreEqual( "Finally some cool stuff in my second blog.", blogItem2.Text, "correct text was saved." );
			
			UpdateBlogItem(blogItem2.Id, "Updated the cool stuff in my blog");
			
			// reload the blog to verify the db has the correct values
			ISession s = _sessions.OpenSession();
			blog = (Blog) s.Find( "from Blog as b where b.Name=:name", "GregBlog", NHibernate.String )[0];
			Assert.IsNotNull(blog);
			Assert.AreEqual( 2, blog.Items.Count );

			DateTime previousItemsDate = DateTime.Parse("2004-01-01");
			int index = 0;
			
			foreach(BlogItem item in blog.Items) 
			{
				if( index > 0 ) 
				{
					Assert.IsTrue( item.ItemDate > previousItemsDate, "is order-by working" );
				}
				previousItemsDate = item.ItemDate;

				if(item.Id==blogItem.Id)  
				{
					// it is problematic to compare DateTime values when using DateTime.Now to
					// set the value because Ms Sql can _NOT_ store dates with the same accuracy
					// as the DateTime struct can - so it is possible to store a DateTime and not
					// retrieve the exact same DateTime.  See the SQL Server BOL for a description
					// of how accurately a datetime value is stored in the db.
					//Assert.AreEqual( blogItem.ItemDate, item.ItemDate );
					Assert.AreEqual( blogItem.Text, item.Text );
					Assert.AreEqual( blogItem.Title, item.Title );

					// note - we can't compare the blogItem.ParentBlog and item.ParentBlog because they
					// will be differnt objects since they were loaded in different sessions.  If Blog 
					// implemented Equals() and GetHashCode() correctly then we could compare them - they<commit_msg>Modified code because of NHibernateUtil rename.<commit_after>using System;
using System.Collections;

using NHibernate;
using NHibernate.Cfg;
using NHibernate.Tool.hbm2ddl;

using NUnit.Framework;

namespace NHibernate.Examples.Blogger 
{

	/// <summary>
	/// Summary description for BloggerFixture.
	/// </summary>
	[TestFixture]
	public class BloggerFixture 
	{

		private ISessionFactory _sessions; 

		[Test]
		public void Main() 
		{
			Configure();
			ExportTables();
			Blog blog = CreateBlog("GregBlog");
			Assert.IsTrue( blog.Id!=0, "The Id should have been assigned by the native generator" );
			
			BlogItem blogItem = CreateBlogItem(blog, "new item", "Required introduction in every blog.");
			Assert.IsTrue( blogItem.Id!=0, "The Id should have been assigned by the native generator" ); 
			Assert.AreEqual( blog, blogItem.ParentBlog, "The BlogItem's Parent should be the Blog" );
			Assert.AreEqual( "new item", blogItem.Title, "correct title was saved" );
			Assert.AreEqual( "Required introduction in every blog.", blogItem.Text, "correct text was saved." );

			BlogItem blogItem2 = CreateBlogItem(blog.Id, "item 2", "Finally some cool stuff in my second blog.");
			Assert.IsTrue( blogItem2.Id!=0, "The Id should have been assigned by the native generator." );
			Assert.AreEqual( "item 2", blogItem2.Title, "correct title was saved" );
			Assert.AreEqual( "Finally some cool stuff in my second blog.", blogItem2.Text, "correct text was saved." );
			
			UpdateBlogItem(blogItem2.Id, "Updated the cool stuff in my blog");
			
			// reload the blog to verify the db has the correct values
			ISession s = _sessions.OpenSession();
			blog = (Blog) s.Find( "from Blog as b where b.Name=:name", "GregBlog", NHibernateUtil.String )[0];
			Assert.IsNotNull(blog);
			Assert.AreEqual( 2, blog.Items.Count );

			DateTime previousItemsDate = DateTime.Parse("2004-01-01");
			int index = 0;
			
			foreach(BlogItem item in blog.Items) 
			{
				if( index > 0 ) 
				{
					Assert.IsTrue( item.ItemDate > previousItemsDate, "is order-by working" );
				}
				previousItemsDate = item.ItemDate;

				if(item.Id==blogItem.Id)  
				{
					// it is problematic to compare DateTime values when using DateTime.Now to
					// set the value because Ms Sql can _NOT_ store dates with the same accuracy
					// as the DateTime struct can - so it is possible to store a DateTime and not
					// retrieve the exact same DateTime.  See the SQL Server BOL for a description
					// of how accurately a datetime value is stored in the db.
					//Assert.AreEqual( blogItem.ItemDate, item.ItemDate );
					Assert.AreEqual( blogItem.Text, item.Text );
					Assert.AreEqual( blogItem.Title, item.Title );

					// note - we can't compare the blogItem.ParentBlog and item.ParentBlog because they
					// will be differnt objects since they were loaded in different sessions.  If Blog 
					// implemented Equals() and GetHashCode() correctly then we could compare them - they
{'fraction_non_alphanumeric': 0.10264675941635562, 'fraction_numerical': 0.007804546996946046, 'mean_word_length': 3.429000751314801, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2645043', 'n_tokens_mistral': 2046, 'n_tokens_neox': 1682, 'n_words': 630}