Ejemplo n.º 1
0
        public void Can_Write_Simple_Parent_Entity()
        {
            using (ISession session = SessionFactory.OpenSession())
                using (ITransaction transaction = session.BeginTransaction())
                {
                    var parent = new TestEntityParent
                    {
                        Name        = "Can_Write_Simple_Parent_Entity",
                        Description = "Desc: Can_Write_Simple_Parent_Entity"
                    };

                    session.Save(parent);
                    transaction.Commit();
                    Assert.That(parent.Id, Is.Not.Null);
                }
        }
Ejemplo n.º 2
0
        public void Can_Read_Parent_Entity_With_Child_No_Null_Check()
        {
            Guid parentId;

            using (ISession session = SessionFactory.OpenSession())
                using (ITransaction transaction = session.BeginTransaction())
                {
                    var parent = new TestEntityParent
                    {
                        Name        = "Can_Read_Parent_Entity_With_Child_No_Null_Check",
                        Description = "Desc: Can_Read_Parent_Entity_With_Child_No_Null_Check",
                        Child       = new TestEntityChild
                        {
                            Name           = "Can_Read_Parent_Entity_With_Child_No_Null_Check - Child",
                            Description    = "Desc: Can_Read_Parent_Entity_With_Child_No_Null_Check - Child",
                            NumberOfApples = 62256897
                        }
                    };

                    session.Save(parent);
                    transaction.Commit();
                    parentId = parent.Id;
                    Assert.That(parent.Id, Is.Not.Null);
                }

            using (ISession session = SessionFactory.OpenSession())
                using (ITransaction transaction = session.BeginTransaction())
                {
                    var query = session.Query <TestEntityParent>()
                                .Where(x => x.Id == parentId)
                                .Select(m => new ParentModel
                    {
                        Id    = m.Id,
                        Name  = m.Name,
                        Child = new ChildModel {
                            Id = m.Child.Id, NumberOfApples = m.Child.NumberOfApples
                        }
                    });

                    ParentModel parentModel = query.Single();
                    Assert.That(parentModel.Id, Is.Not.Null);
                    Assert.That(parentModel.Child.NumberOfApples, Is.GreaterThan(0));

                    transaction.Commit();
                }
        }
Ejemplo n.º 3
0
        public void Can_Read_Parent_Entity_Without_Child_IsNotNull_Extension()
        {
            Guid parentId;

            using (ISession session = SessionFactory.OpenSession())
                using (ITransaction transaction = session.BeginTransaction())
                {
                    var parent = new TestEntityParent
                    {
                        Name        = "Can_Read_Parent_Entity_Without_Child_IsNotNull_Extension",
                        Description = "Desc: Can_Read_Parent_Entity_Without_Child_IsNotNull_Extension"
                    };

                    session.Save(parent);
                    transaction.Commit();
                    parentId = parent.Id;
                    Assert.That(parent.Id, Is.Not.Null);
                }

            using (ISession session = SessionFactory.OpenSession())
                using (ITransaction transaction = session.BeginTransaction())
                {
                    var query = session.Query <TestEntityParent>()
                                .Where(x => x.Id == parentId)
                                .Select(m => new ParentModel
                    {
                        Id    = m.Id,
                        Name  = m.Name,
                        Child = m.Child.IsNotNull() ? new ChildModel {
                            Id = m.Child.Id, NumberOfApples = m.Child.NumberOfApples
                        } : null
                    });

                    ParentModel parentModel = query.Single();
                    Assert.That(parentModel.Id, Is.Not.Null);
                    Assert.That(parentModel.Child, Is.Null);

                    transaction.Commit();
                }
        }
Ejemplo n.º 4
0
        public void Can_Write_Parent_Entity_With_Child()
        {
            using (ISession session = SessionFactory.OpenSession())
                using (ITransaction transaction = session.BeginTransaction())
                {
                    var parent = new TestEntityParent
                    {
                        Name        = "Can_Write_Parent_Entity_With_Child",
                        Description = "Desc: Can_Write_Parent_Entity_With_Child",
                        Child       = new TestEntityChild
                        {
                            Name           = "Can_Write_Parent_Entity_With_Child - Child",
                            Description    = "Desc: Can_Write_Parent_Entity_With_Child - Child",
                            NumberOfApples = 58256897
                        }
                    };

                    session.Save(parent);
                    transaction.Commit();
                    Assert.That(parent.Id, Is.Not.Null);
                }
        }