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

            var model = new ClassWithSerializableType()
            {
                Image = image
            };
            var imageSize = ((Image)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 <ClassWithSerializableType>(id);
                Assert.That(((Image)model.Image).Size, Is.EqualTo(imageSize));                 // Ensure type is not truncated
            }
            using (ISession session = OpenSession())
            {
                session.CreateQuery("delete from ClassWithSerializableType").ExecuteUpdate();
                session.Flush();
            }

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

            var model = new ClassWithSerializableType()
            {
                Image = image
            };
            var imageSize = ((Image)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 <ClassWithSerializableType>(id));
                Assert.That(((Image)model.Image).Size, Is.EqualTo(imageSize));                 // Ensure type is not truncated
            }
            using (ISession session = OpenSession())
            {
                await(session.CreateQuery("delete from ClassWithSerializableType").ExecuteUpdateAsync());
                await(session.FlushAsync());
            }

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