public void NhThrowsOnTooLong()
		{
			int maxStringLength = 4000;
			PropertyValueException ex = Assert.Throws<PropertyValueException>(() =>
				{
					using (ISession s = OpenSession())
					{
						StringClass b = new StringClass();
						b.LongStringValue = new string('x', maxStringLength + 1);
						s.Save(b);
						s.Flush();
					}
				});

			Assert.That(ex.Message, Iz.EqualTo("Error dehydrating property value for NHibernate.Test.TypesTest.StringClass.LongStringValue"));
			Assert.That(ex.InnerException, Iz.TypeOf<HibernateException>());
			Assert.That(ex.InnerException.Message, Iz.EqualTo("The length of the string value exceeds the length configured in the mapping/parameter."));
		}
		public void InsertNullValue ()
		{
			using( ISession s = OpenSession() )
			{
				StringClass b = new StringClass();
				b.StringValue = null;
				s.Save( b );
				s.Flush();
			}

			using( ISession s = OpenSession() )
			{
				StringClass b = (StringClass) s.CreateCriteria(
					typeof( StringClass ) ).UniqueResult();
				Assert.IsNull( b.StringValue );
				s.Delete( b );
				s.Flush();
			}
		}
        public void DbThrowsOnTooLong()
        {
            bool dbThrewError = false;

            try
            {
                using (ISession s = OpenSession())
                {
                    StringClass b = new StringClass();
                    b.StringValue = "0123456789a";
                    s.Save(b);
                    s.Flush();
                }
            }
            catch
            {
                dbThrewError = true;
            }

            Assert.That(dbThrewError, "Database did not throw an error when trying to put too large a value into a column");
        }
		public void DbThrowsOnTooLong()
		{
			bool dbThrewError = false;

			try
			{
				using (ISession s = OpenSession())
				{
					StringClass b = new StringClass();
					b.StringValue = "0123456789a";
					s.Save(b);
					s.Flush();
				}
			}
			catch
			{
				dbThrewError = true;
			}

			Assert.That(dbThrewError, "Database did not throw an error when trying to put too large a value into a column");
		}
Esempio n. 5
0
        public Task ShouldPreventInsertionOfVeryLongStringThatWouldBeTruncatedAsync()
        {
            try
            {
                // This test case is for when the current driver will use a parameter size
                // that is significantly larger than the mapped column size (e.g. SqlClientDriver currently).

                // Note: This test could possible be written as
                //   "database must raise an error OR it must store and return the full value"
                // to avoid this dialect specific exception.
                if (Dialect is SQLiteDialect)
                {
                    Assert.Ignore("SQLite does not enforce specified string lengths.");
                }

                int maxStringLength = GetLongStringMappedLength();

                var ex = Assert.CatchAsync <Exception>(
                    async() =>
                {
                    using (ISession s = OpenSession())
                    {
                        StringClass b = new StringClass {
                            LongStringValue = new string('x', maxStringLength + 1)
                        };
                        await(s.SaveAsync(b));
                        await(s.FlushAsync());
                    }
                });

                return(AssertFailedInsertExceptionDetailsAndEmptyTableAsync(ex));
            }
            catch (Exception ex)
            {
                return(Task.FromException <object>(ex));
            }
        }
        public async Task CanCompareShortValueWithLongStringAsync()
        {
            var maxStringLength = GetLongStringMappedLength();
            var longString      = new string('x', maxStringLength);

            using (var s = OpenSession())
            {
                var b = new StringClass {
                    LongStringValue = longString
                };
                await(s.SaveAsync(b));
                await(s.FlushAsync());
            }

            using (var s = OpenSession())
            {
                var q = s.CreateQuery("from StringClass s where s.LongStringValue != :shortString")
                        // Do not replace with SetString, otherwise length will be unspecified.
                        .SetParameter("shortString", "aaa");
                var sc = await(q.UniqueResultAsync <StringClass>());
                Assert.That(sc, Is.Not.Null);
                Assert.That(sc.LongStringValue, Is.EqualTo(longString));
            }
        }