コード例 #1
0
		public void Update()
		{
			Video v = new Video("Shinobi", 10, 10);
			using (ISession s = OpenSession())
			{
				s.Save(v);
				s.Flush();
			}
			int savedId = v.Id;
			// update detached
			v.Heigth = 0;
			try
			{
				using (ISession s = OpenSession())
				{
					s.Update(v);
					s.Flush();
				}
				Assert.Fail("Updated an invalid entity");
			}
			catch (ValidationFailure)
			{
				// Ok
			}

			// update in the same session
			using (ISession s = OpenSession())
			{
				Video vu = (Video)s.Get(typeof(Video), savedId);
				vu.Width = 0;
				try
				{
					s.Update(vu);
					s.Flush();
					Assert.Fail("Updated an invalid entity");
				}
				catch (ValidationFailure)
				{
					//Ok
				}
			}

			// cleanup
			using (ISession s = OpenSession())
			{
				s.Delete(v);
				s.Flush();
			}
		}
コード例 #2
0
		public void Save()
		{
			try
			{
				using (ISession s = OpenSession())
				{
					s.Save(new Video());
					s.Flush();
				}
				Assert.Fail("Saved an invalid entity");
			}
			catch(ValidationFailure)
			{
				// Ok
			}

			Video v = new Video("Shinobi", 10, 10);
			using (ISession s = OpenSession())
			{
				s.Save(v);
				s.Delete(v);
				s.Flush();
			}
		}
コード例 #3
0
		public void Merge()
		{
			Video v = new Video("Shinobi", 10, 10);
			using (ISession s = OpenSession())
			{
				s.Save(v);
				s.Flush();
			}
			v.Heigth = 0;
			try
			{
				using (ISession s = OpenSession())
				{
					s.Merge(v);
					s.Flush();
				}
				Assert.Fail("Updated an invalid entity");
			}
			catch (ValidationFailure)
			{
				// Ok
			}

			Video v1 = new Video("Shinobi", 0, 10);
			try
			{
				using (ISession s = OpenSession())
				{
					s.Merge(v1);
					s.Flush();
				}
				Assert.Fail("saved an invalid entity");
			}
			catch (ValidationFailure)
			{
				// Ok
			}


			// cleanup
			using (ISession s = OpenSession())
			using (ITransaction tx = s.BeginTransaction())
			{
				s.Delete("from Video");
				tx.Commit();
			}
		}
コード例 #4
0
		public void Delete()
		{
			Video v = new Video("Shinobi", 10, 10);
			using (ISession s = OpenSession())
			{
				s.Save(v);
				s.Flush();
				// Validatable not called in deletation
				s.Delete(v);
				s.Flush();
			}
		}