Example #1
0
        public void TestPersistenceOfClassWithUnknownSerializableType()
        {
            Assembly assembly = Assembly.Load(MappingsAssembly);
            var      stream   = assembly.GetManifestResourceStream("NHibernate.Test.NHSpecificTest.NH2484.food-photo.jpg");
            var      image    = Bitmap.FromStream(stream);

            var model = new ClassWithImage()
            {
                Image = image
            };
            var imageSize = model.Image.Size;
            int id        = -1;

            using (ISession session = OpenSession())
            {
                session.SaveOrUpdate(model);
                session.Flush();
                id = model.Id;
                Assert.That(id, Is.GreaterThan(-1));
            }
            using (ISession session = OpenSession())
            {
                model = session.Get <ClassWithImage>(id);
                Assert.That(model.Image.Size, Is.EqualTo(imageSize));                 // Ensure type is not truncated
            }
            using (ISession session = OpenSession())
            {
                session.CreateQuery("delete from ClassWithImage").ExecuteUpdate();
                session.Flush();
            }

            stream.Dispose();
        }
Example #2
0
        public async Task TestPersistenceOfClassWithUnknownSerializableTypeAsync()
        {
            var stream = typeof(FixtureAsync).Assembly.GetManifestResourceStream("NHibernate.Test.NHSpecificTest.NH2484.food-photo.jpg");
            var image  = Image.FromStream(stream);

            var model = new ClassWithImage()
            {
                Image = image
            };
            var imageSize = model.Image.Size;
            int id        = -1;

            using (ISession session = OpenSession())
            {
                await(session.SaveOrUpdateAsync(model));
                await(session.FlushAsync());
                id = model.Id;
                Assert.That(id, Is.GreaterThan(-1));
            }
            using (ISession session = OpenSession())
            {
                model = await(session.GetAsync <ClassWithImage>(id));
                Assert.That(model.Image.Size, Is.EqualTo(imageSize));                 // Ensure type is not truncated
            }
            using (ISession session = OpenSession())
            {
                await(session.CreateQuery("delete from ClassWithImage").ExecuteUpdateAsync());
                await(session.FlushAsync());
            }

            stream.Dispose();
        }
Example #3
0
		public void TestPersistenceOfClassWithUnknownSerializableType()
		{
			Assembly assembly = Assembly.Load(MappingsAssembly);
			var stream = assembly.GetManifestResourceStream("NHibernate.Test.NHSpecificTest.NH2484.food-photo.jpg");
			var image = Bitmap.FromStream(stream);
			
			var model = new ClassWithImage() { Image = image };
			var imageSize = model.Image.Size;
			int id = -1;
			
			using (ISession session = OpenSession())
			{
				session.SaveOrUpdate(model);
				session.Flush();
				id = model.Id;
				Assert.That(id, Is.GreaterThan(-1));
			}
			using (ISession session = OpenSession())
			{
				model = session.Get<ClassWithImage>(id);
				Assert.That(model.Image.Size, Is.EqualTo(imageSize)); // Ensure type is not truncated
			}
			using (ISession session = OpenSession())
			{
				session.CreateQuery("delete from ClassWithImage").ExecuteUpdate();
				session.Flush();
			}
			
			stream.Dispose();
		}