|
| 1 | +using System; |
| 2 | +using System.Collections; |
| 3 | +using NHibernate.Cfg; |
| 4 | +using NHibernate.Engine; |
| 5 | +using NHibernate.SqlCommand; |
| 6 | +using NHibernate.SqlTypes; |
| 7 | +using NHibernate.Type; |
| 8 | +using NUnit.Framework; |
| 9 | + |
| 10 | +namespace NHibernate.Test.Stateless |
| 11 | +{ |
| 12 | + [TestFixture] |
| 13 | + public class StatelessSessionFixture : TestCase |
| 14 | + { |
| 15 | + protected override string MappingsAssembly |
| 16 | + { |
| 17 | + get { return "NHibernate.Test"; } |
| 18 | + } |
| 19 | + |
| 20 | + protected override IList Mappings |
| 21 | + { |
| 22 | + get { return new string[] { "Stateless.Document.hbm.xml" }; } |
| 23 | + } |
| 24 | + |
| 25 | + [Test, Ignore("Porting in progress")] |
| 26 | + public void CreateUpdateReadDelete() |
| 27 | + { |
| 28 | + IStatelessSession ss = sessions.OpenStatelessSession(); |
| 29 | + ITransaction tx = ss.BeginTransaction(); |
| 30 | + Document doc = new Document("blah blah blah", "Blahs"); |
| 31 | + ss.Insert(doc); |
| 32 | + Assert.IsNotNull(doc.LastModified); |
| 33 | + DateTime? initVersion = doc.LastModified; |
| 34 | + Assert.IsTrue(initVersion.HasValue); |
| 35 | + tx.Commit(); |
| 36 | + |
| 37 | + tx = ss.BeginTransaction(); |
| 38 | + doc.Text = "blah blah blah .... blah"; |
| 39 | + ss.Update(doc); |
| 40 | + Assert.IsTrue(initVersion.HasValue); |
| 41 | + Assert.AreSame(initVersion, doc.LastModified); |
| 42 | + tx.Commit(); |
| 43 | + |
| 44 | + tx = ss.BeginTransaction(); |
| 45 | + doc.Text = "blah blah blah .... blah blay"; |
| 46 | + ss.Update(doc); |
| 47 | + tx.Commit(); |
| 48 | + |
| 49 | + Document doc2 = (Document) ss.Get<Document>("Blahs"); |
| 50 | + Assert.AreEqual("Blahs", doc2.Name); |
| 51 | + Assert.AreEqual(doc.Text, doc2.Text); |
| 52 | + |
| 53 | + doc2 = (Document) ss.CreateQuery("from Document where text is not null").UniqueResult(); |
| 54 | + Assert.AreEqual("Blahs", doc2.Name); |
| 55 | + Assert.AreEqual(doc.Text, doc2.Text); |
| 56 | + |
| 57 | + doc2 = (Document) ss.CreateSQLQuery("select * from Document").AddEntity(typeof (Document)).UniqueResult(); |
| 58 | + Assert.AreEqual("Blahs", doc2.Name); |
| 59 | + Assert.AreEqual(doc.Text, doc2.Text); |
| 60 | + |
| 61 | + doc2 = (Document) ss.CreateCriteria<Document>().UniqueResult(); |
| 62 | + Assert.AreEqual("Blahs", doc2.Name); |
| 63 | + Assert.AreEqual(doc.Text, doc2.Text); |
| 64 | + |
| 65 | + tx = ss.BeginTransaction(); |
| 66 | + ss.Delete(doc); |
| 67 | + tx.Commit(); |
| 68 | + ss.Close(); |
| 69 | + } |
| 70 | + |
| 71 | + [Test, Ignore("Not supported yet")] |
| 72 | + public void HqlBulk() |
| 73 | + { |
| 74 | + //IStatelessSession ss = sessions.OpenStatelessSession(); |
| 75 | + //ITransaction tx = ss.BeginTransaction(); |
| 76 | + //Document doc = new Document("blah blah blah", "Blahs"); |
| 77 | + //ss.Insert(doc); |
| 78 | + //Paper paper = new Paper(); |
| 79 | + //paper.Color="White"; |
| 80 | + //ss.Insert(paper); |
| 81 | + //tx.Commit(); |
| 82 | + |
| 83 | + //tx = ss.BeginTransaction(); |
| 84 | + //int count = ss.CreateQuery("update Document set name = :newName where name = :oldName") |
| 85 | + // .SetString("newName", "Foos") |
| 86 | + // .SetString("oldName", "Blahs") |
| 87 | + // .ExecuteUpdate(); |
| 88 | + //Assert.AreEqual(1, count, "hql-delete on stateless session"); |
| 89 | + //count = ss.CreateQuery("update Paper set color = :newColor") |
| 90 | + // .SetString("newColor", "Goldenrod") |
| 91 | + // .ExecuteUpdate(); |
| 92 | + //Assert.AreEqual(1, count, "hql-delete on stateless session"); |
| 93 | + //tx.Commit(); |
| 94 | + |
| 95 | + //tx = ss.BeginTransaction(); |
| 96 | + //count = ss.CreateQuery("delete Document").ExecuteUpdate(); |
| 97 | + //Assert.AreEqual(1, count, "hql-delete on stateless session"); |
| 98 | + //count = ss.CreateQuery("delete Paper").ExecuteUpdate(); |
| 99 | + //Assert.AreEqual(1, count, "hql-delete on stateless session"); |
| 100 | + //tx.Commit(); |
| 101 | + //ss.Close(); |
| 102 | + } |
| 103 | + |
| 104 | + [Test, Ignore("Porting in progress")] |
| 105 | + public void InitId() |
| 106 | + { |
| 107 | + IStatelessSession ss = sessions.OpenStatelessSession(); |
| 108 | + ITransaction tx = ss.BeginTransaction(); |
| 109 | + Paper paper = new Paper(); |
| 110 | + paper.Color = "White"; |
| 111 | + ss.Insert(paper); |
| 112 | + Assert.IsTrue(paper.Id != 0); |
| 113 | + tx.Commit(); |
| 114 | + |
| 115 | + tx = ss.BeginTransaction(); |
| 116 | + ss.Delete(ss.Get<Paper>(paper.Id)); |
| 117 | + tx.Commit(); |
| 118 | + ss.Close(); |
| 119 | + } |
| 120 | + |
| 121 | + [Test, Ignore("Porting in progress")] |
| 122 | + public void Refresh() |
| 123 | + { |
| 124 | + IStatelessSession ss = sessions.OpenStatelessSession(); |
| 125 | + ITransaction tx = ss.BeginTransaction(); |
| 126 | + Paper paper = new Paper(); |
| 127 | + paper.Color = "whtie"; |
| 128 | + ss.Insert(paper); |
| 129 | + tx.Commit(); |
| 130 | + ss.Close(); |
| 131 | + |
| 132 | + ss = sessions.OpenStatelessSession(); |
| 133 | + tx = ss.BeginTransaction(); |
| 134 | + Paper p2 = (Paper) ss.Get<Paper>(paper.Id); |
| 135 | + p2.Color = "White"; |
| 136 | + ss.Update(p2); |
| 137 | + tx.Commit(); |
| 138 | + ss.Close(); |
| 139 | + |
| 140 | + ss = sessions.OpenStatelessSession(); |
| 141 | + tx = ss.BeginTransaction(); |
| 142 | + Assert.AreEqual("whtie", paper.Color); |
| 143 | + ss.Refresh(paper); |
| 144 | + Assert.AreEqual("White", paper.Color); |
| 145 | + ss.Delete(paper); |
| 146 | + tx.Commit(); |
| 147 | + ss.Close(); |
| 148 | + } |
| 149 | + } |
| 150 | +} |
0 commit comments