|
| 1 | +using System.Collections.Generic; |
| 2 | +using System.Linq; |
| 3 | +using System.Text; |
| 4 | +using NHibernate.Cfg; |
| 5 | +using NUnit.Framework; |
| 6 | + |
| 7 | +namespace NHibernate.Test.CfgTest |
| 8 | +{ |
| 9 | + [TestFixture] |
| 10 | + public class DefaultFlushModeFixture |
| 11 | + { |
| 12 | + [Test] |
| 13 | + public void CanSetDefaultFlushModeThroughXmlConfiguration() |
| 14 | + { |
| 15 | + var cfg = new Configuration().Configure(); |
| 16 | + |
| 17 | + using (var sessionFactory = cfg.BuildSessionFactory()) |
| 18 | + { |
| 19 | + using (var session = sessionFactory.OpenSession()) |
| 20 | + { |
| 21 | + Assert.AreEqual(session.FlushMode, FlushMode.Commit); |
| 22 | + } |
| 23 | + } |
| 24 | + } |
| 25 | + |
| 26 | + [Test] |
| 27 | + public void CanSetDefaultFlushModeThroughStandardConfiguration() |
| 28 | + { |
| 29 | + var cfg = new Configuration().Configure(); |
| 30 | + cfg.Properties[Environment.DefaultFlushMode] = FlushMode.Always.ToString(); |
| 31 | + |
| 32 | + using (var sessionFactory = cfg.BuildSessionFactory()) |
| 33 | + { |
| 34 | + using (var session = sessionFactory.OpenSession()) |
| 35 | + { |
| 36 | + Assert.AreEqual(session.FlushMode, FlushMode.Always); |
| 37 | + } |
| 38 | + } |
| 39 | + |
| 40 | + cfg.Properties[Environment.DefaultFlushMode] = FlushMode.Commit.ToString(); |
| 41 | + |
| 42 | + using (var sessionFactory = cfg.BuildSessionFactory()) |
| 43 | + { |
| 44 | + using (var session = sessionFactory.OpenSession()) |
| 45 | + { |
| 46 | + Assert.AreEqual(session.FlushMode, FlushMode.Commit); |
| 47 | + } |
| 48 | + } |
| 49 | + } |
| 50 | + |
| 51 | + [Test] |
| 52 | + public void CanSetDefaultFlushModeThroughLoquaciousConfiguration() |
| 53 | + { |
| 54 | + var cfg = new Configuration() |
| 55 | + .Configure(); |
| 56 | + |
| 57 | + cfg |
| 58 | + .SessionFactory() |
| 59 | + .DefaultFlushMode(FlushMode.Always); |
| 60 | + |
| 61 | + using (var sessionFactory = cfg.BuildSessionFactory()) |
| 62 | + { |
| 63 | + using (var session = sessionFactory.OpenSession()) |
| 64 | + { |
| 65 | + Assert.AreEqual(session.FlushMode, FlushMode.Always); |
| 66 | + } |
| 67 | + } |
| 68 | + |
| 69 | + cfg.Configure() |
| 70 | + .SessionFactory() |
| 71 | + .DefaultFlushMode(FlushMode.Commit); |
| 72 | + |
| 73 | + using (var sessionFactory = cfg.BuildSessionFactory()) |
| 74 | + { |
| 75 | + using (var session = sessionFactory.OpenSession()) |
| 76 | + { |
| 77 | + Assert.AreEqual(session.FlushMode, FlushMode.Commit); |
| 78 | + } |
| 79 | + } |
| 80 | + } |
| 81 | + } |
| 82 | +} |
0 commit comments