Ejemplo n.º 1
0
		private void PersistReport(Report report)
		{
			using (var session = OpenSession())
			using (session.BeginTransaction())
			{
				session.Save(report);
				session.Flush();
				// No commit to avoid DB pollution (test success means we should throw and never insert anyway).
			}
		}
Ejemplo n.º 2
0
		public void ShouldThrowWhenImageAsISerializableTooLarge()
		{
			Assembly assembly = Assembly.Load(MappingsAssembly);
			var stream = assembly.GetManifestResourceStream("NHibernate.Test.NHSpecificTest.NH2484.food-photo.jpg");
			var image = Bitmap.FromStream(stream);

			var report = new Report { SerializableImage = image };

			var ex = Assert.Throws<PropertyValueException>(() => PersistReport(report));

			Assert.That(ex.Message, Is.StringContaining("Report.SerializableImage"));
			Assert.That(ex.InnerException, Is.TypeOf<HibernateException>());
			Assert.That(ex.InnerException.Message,
						Is.EqualTo("The length of the byte[] value exceeds the length configured in the mapping/parameter."));
		}
Ejemplo n.º 3
0
		public void ShouldThrowWhenByteArrayTooLong()
		{
			// For SQL Server only the SqlClientDriver sets parameter lengths
			// even when there is no length specified in the mapping. The ODBC
			// driver won't cause the truncation issue and hence not the exception.
			if (!(sessions.ConnectionProvider.Driver is SqlClientDriver))
				Assert.Ignore("Test limited to drivers that sets parameter length even with no length specified in the mapping.");

			const int reportSize = 17158;
			var random = new Random();

			var reportImage = new Byte[reportSize];
			random.NextBytes(reportImage);

			var report = new Report { UnsizedArray = reportImage };

			var ex = Assert.Throws<PropertyValueException>(() => PersistReport(report));

			Assert.That(ex.Message, Is.StringContaining("Report.UnsizedArray"));
			Assert.That(ex.InnerException, Is.TypeOf<HibernateException>());
			Assert.That(ex.InnerException.Message,
						Is.EqualTo("The length of the byte[] value exceeds the length configured in the mapping/parameter."));
		}