Пример #1
0
        public void ShouldUpdateCollection()
        {
            SessionFactory.EncloseInTransaction(session =>
            {
                var reptileFamily =
                    ReptileFamilyBuilder.StartRecording().WithChildren(2).Build();
                session.Save(reptileFamily);
            });

            Family <Reptile> reptil;

            SessionFactory.EncloseInTransaction(session =>
            {
                reptil =
                    session.CreateQuery("from ReptilesFamily").SetMaxResults(1).UniqueResult
                    <Family <Reptile> >();

                reptil.Children.Remove(reptil.Children.First());
                session.Update(reptil);
            });

            SessionFactory.EncloseInTransaction(session =>
            {
                reptil =
                    session.CreateQuery("from ReptilesFamily").SetMaxResults(1).UniqueResult
                    <Family <Reptile> >();

                reptil.Children.Count.Should().Be.EqualTo(1);
            });

            CleanDb();
        }
Пример #2
0
        public void FillDb()
        {
            SessionFactory.EncloseInTransaction(session =>
            {
                for (int i = 0; i < 10; i++)
                {
                    var reptileFamily =
                        ReptileFamilyBuilder.StartRecording().WithChildren(2).Build();

                    session.Save(reptileFamily);
                }

                for (int i = 0; i < 10; i++)
                {
                    var humanFamily = HumanFamilyBuilder.StartRecording().WithChildren(1).Build();

                    session.Save(humanFamily);
                }
            });
        }
Пример #3
0
        public void ShouldDelete()
        {
            SessionFactory.EncloseInTransaction(session =>
            {
                var reptileFamily =
                    ReptileFamilyBuilder.StartRecording().WithChildren(2).Build();
                session.Save(reptileFamily);
            });

            SessionFactory.EncloseInTransaction(session =>
            {
                var reptil =
                    session.CreateQuery("from ReptilesFamily").SetMaxResults(1).UniqueResult
                    <Family <Reptile> >();

                session.Delete(reptil);
            });

            IList instancesInDb = null;

            SessionFactory.EncloseInTransaction(session => instancesInDb = session.CreateQuery("from System.Object").List());

            instancesInDb.Count.Should().Be.EqualTo(0);
        }