示例#1
0
        public void createBook_withFirst3LinesOfInferno_shouldCreate()
        {
            Line line1 = new Line
            {
                Number = 1,
                Text   = "Halfway along our journey to life's end"
            };
            Line line2 = new Line
            {
                Number = 2,
                Text   = "I found myself astray in a darkwood,"
            };
            Line line3 = new Line
            {
                Number = 3,
                Text   = "Since the rightway was no where to be found."
            };
            Canto canto1 = new Canto
            {
                Number = 1
            };

            canto1.AddLine(line1);
            canto1.AddLine(line2);
            canto1.AddLine(line3);

            Book inferno = new Book
            {
                Number = 1,
                Name   = "Inferno"
            };

            inferno.AddCanto(canto1);


            using (ISession session = sqliteSessionFactory.Session)
            {
                using (ITransaction transaction = session.BeginTransaction())
                {
                    Assert.That(inferno.Id == 0);

                    session.SaveOrUpdate(inferno);

                    transaction.Commit();

                    Assert.That(inferno.Id > 0);
                }

                using (session.BeginTransaction())
                {
                    var resbooks  = session.CreateCriteria(typeof(Book)).List <Book>();
                    var resbook   = resbooks[0];
                    var rescantos = resbooks[0].Cantos;
                    var text      = rescantos[0].ToString();
                    Assert.That(resbook.Name == "Inferno");
                    Assert.That(text.StartsWith("Halfway"));
                }
            }
        }
示例#2
0
        public void createCanto_withGivenLine_shouldCreate()
        {
            Line line = new Line
            {
                Number = 1,
                Text   = "In the middle of life"
            };
            Canto f = new Canto
            {
            };

            f.AddLine(line);

            using (ISession session = sqliteSessionFactory.Session)
            {
                using (ITransaction transaction = session.BeginTransaction())
                {
                    Assert.That(f.Id == 0);

                    session.SaveOrUpdate(f);

                    transaction.Commit();

                    Assert.That(f.Id > 0);
                }
            }
        }
示例#3
0
        public void createNote_fromTheFirst3LinesOfInferno()
        {
            Line line1 = new Line
            {
                Number = 1,
                Text   = "Halfway along our journey to life's end"
            };
            Line line2 = new Line
            {
                Number = 2,
                Text   = "I found myself astray in a dark wood,"
            };
            Line line3 = new Line
            {
                Number = 3,
                Text   = "Since the rightway was no where to be found."
            };
            Line line4 = new Line
            {
                Number = 4,
                Text   = "How hard a thing it is to express the horr"
            };
            Line line5 = new Line
            {
                Number = 5,
                Text   = "of that wild wood, so difficult, so dense"
            };
            Line line6 = new Line
            {
                Number = 6,
                Text   = "Even to think of it renews my terror."
            };
            Canto canto1 = new Canto
            {
                Number = 1
            };

            canto1.AddLine(line1);
            canto1.AddLine(line2);
            canto1.AddLine(line3);
            canto1.AddLine(line4);
            canto1.AddLine(line5);
            canto1.AddLine(line6);

            Book inferno = new Book
            {
                Number = 1,
                Name   = "Inferno"
            };

            inferno.AddCanto(canto1);

            Note note = new Note
            {
                Commentary = "Life span is 70 years, at the midpoint is 1300 CE, Dante was 35 years old."
            };

            note.Loc = new Loc
            {
                Book  = "Inferno",
                Canto = 1,
                Start = 1
            };

            using (ISession session = sqliteSessionFactory.Session)
            {
                using (ITransaction transaction = session.BeginTransaction())
                {
                    Assert.That(note.Id == 0);
                    session.SaveOrUpdate(inferno);
                    session.SaveOrUpdate(note);

                    transaction.Commit();

                    Assert.That(note.Id > 0);
                }

                using (session.BeginTransaction())
                {
                    var resnotes = session.CreateCriteria(typeof(Note)).List <Note>();
                    var resnote  = resnotes[0];

                    var resCanto = session.CreateCriteria(typeof(Canto))
                                   .CreateCriteria("Book")
                                   .Add(Restrictions.Eq("Id", 1))
                                   .List <Canto>();
                    var resCanto2 = session.CreateCriteria(typeof(Canto))
                                    .CreateCriteria("Book")
                                    .Add(Restrictions.InsensitiveLike("Name", "Inferno"))
                                    .List <Canto>();

                    var search = session.CreateCriteria(typeof(Line))
                                 .Add(Restrictions.Eq("Number", 2))
                                 .CreateCriteria("Canto")
                                 .CreateCriteria("Book")
                                 .Add(Restrictions.InsensitiveLike("Name", "Inferno"))
                                 .Add(Restrictions.Eq("Number", 1))

                                 .List <Line>();
                    Assert.That(search[0].Text.Contains("wood") == true);
                }
            }
        }
示例#4
0
        public void init()
        {
            sqliteSessionFactory = new InMemorySqLiteSessionFactory();


            Line line1 = new Line
            {
                Number = 1,
                Text   = "Halfway along our journey to life's end"
            };
            Line line2 = new Line
            {
                Number = 2,
                Text   = "I found myself astray in a dark wood,"
            };
            Line line3 = new Line
            {
                Number = 3,
                Text   = "Since the rightway was no where to be found."
            };
            Line line4 = new Line
            {
                Number = 4,
                Text   = "How hard a thing it is to express the horr"
            };
            Line line5 = new Line
            {
                Number = 5,
                Text   = "of that wild wood, so difficult, so dense"
            };
            Line line6 = new Line
            {
                Number = 6,
                Text   = "Even to think of it renews my terror."
            };
            Canto canto1 = new Canto
            {
                Number = 1
            };

            canto1.AddLine(line1);
            canto1.AddLine(line2);
            canto1.AddLine(line3);
            canto1.AddLine(line4);
            canto1.AddLine(line5);
            canto1.AddLine(line6);

            Book inferno = new Book
            {
                Number = 1,
                Name   = "Inferno"
            };

            inferno.AddCanto(canto1);

            Note note = new Note
            {
                Loc = new Loc
                {
                    Book  = "Inferno",
                    Canto = 1,
                    Start = 2,
                    End   = 2
                }
            };

            Term wildness = new Term
            {
                Name  = "wood",
                Alias = "forest,wildness"
            };

            wildness.AddNote(note);
            wildness.SetMetaphorItem("metaphor", "");

            session = sqliteSessionFactory.Session;
            {
                using (ITransaction transaction = session.BeginTransaction())
                {
                    Assert.That(note.Id == 0);
                    session.SaveOrUpdate(inferno);
                    session.SaveOrUpdate(note);
                    session.SaveOrUpdate(wildness);

                    transaction.Commit();
                }
            }
        }