예제 #1
0
		public void Trim()
		{
			using (session.BeginTransaction())
			{
				AnotherEntity ae1 = new AnotherEntity {Input = " hi "};
				AnotherEntity ae2 = new AnotherEntity {Input = "hi"};
				AnotherEntity ae3 = new AnotherEntity {Input = "heh"};
				session.Save(ae1);
				session.Save(ae2);
				session.Save(ae3);
				session.Flush();

				Assert.AreEqual(2, session.Query<AnotherEntity>().Count(e => e.Input.Trim() == "hi"));
				Assert.AreEqual(1, session.Query<AnotherEntity>().Count(e => e.Input.TrimEnd() == " hi"));

				// Emulated trim does not support multiple trim characters, but for many databases it should work fine anyways.
				Assert.AreEqual(1, session.Query<AnotherEntity>().Count(e => e.Input.Trim('h') == "e"));
				Assert.AreEqual(1, session.Query<AnotherEntity>().Count(e => e.Input.TrimStart('h') == "eh"));
				Assert.AreEqual(1, session.Query<AnotherEntity>().Count(e => e.Input.TrimEnd('h') == "he"));

				// Let it rollback to get rid of temporary changes.
			}
		}
예제 #2
0
        public void Trim()
        {
            List<int> idsToDelete = new List<int>();
            try
            {
                AnotherEntity ae1 = new AnotherEntity {Input = " hi "};
                AnotherEntity ae2 = new AnotherEntity {Input = "hi"};
                AnotherEntity ae3 = new AnotherEntity {Input = "heh"};
                session.Save(ae1);
                idsToDelete.Add(ae1.Id);
                session.Save(ae2);
                idsToDelete.Add(ae2.Id);
                session.Save(ae3);
                idsToDelete.Add(ae3.Id);
                session.Flush();

                Assert.AreEqual(2, session.Query<AnotherEntity>().Where(e => e.Input.Trim() == "hi").Count());
                Assert.AreEqual(1, session.Query<AnotherEntity>().Where(e => e.Input.TrimEnd() == " hi").Count());

                // Emulated trim does not support multiple trim characters, but for many databases it should work fine anyways.
                Assert.AreEqual(1, session.Query<AnotherEntity>().Where(e => e.Input.Trim('h') == "e").Count());
                Assert.AreEqual(1, session.Query<AnotherEntity>().Where(e => e.Input.TrimStart('h') == "eh").Count());
                Assert.AreEqual(1, session.Query<AnotherEntity>().Where(e => e.Input.TrimEnd('h') == "he").Count());
            }
            finally
            {
                foreach (int idToDelete in idsToDelete)
                    session.Delete(session.Get<AnotherEntity>(idToDelete));
                session.Flush();
            }
        }
		private string Key(AnotherEntity e)
		{
			return "Input=" + (e.Input ?? "NULL") + ", Output=" + (e.Output ?? "NULL");
		}