Tuesday, September 11, 2012

Unit test



 [TestMethod]
        public void can_save_and_read_pbentity2()
        {
            object id;

            // Save to database using PbPlatsannonsEntity
            using ( var tx = CurrentSession.BeginTransaction())
            {
                id =
                    CurrentSession.Save(
                        new PbPlatsannonsEntity
                            {   Annonsrubrik = "Rubrik annons",
                                AnnonstextXml = "XML annonstext",
                                AntalPlatser = 12
                               
                            });
                    tx.Commit();
            }
            CurrentSession.Clear();

            //Read from database
            using ( var tx = CurrentSession.BeginTransaction() )
            {
                var pbPlatsannonsEntity = CurrentSession.Get<PbPlatsannonsEntity>(id);
                Assert.Equals("Rubrik annons", pbPlatsannonsEntity.Annonsrubrik);
                Assert.Equals("XML annonstext", pbPlatsannonsEntity.AnnonstextXml);
                Assert.Equals(12, pbPlatsannonsEntity.AntalPlatser);
                //Assert.Equals(new DateTime(2000, 1, 1), pbPlatsannonsEntity.Created);
                tx.Commit();

            }

        }

No comments:

Post a Comment