コード例 #1
0
        public void Should_map_Visitor()
        {
            new DatabaseTester().Clean();
            var visitor = new Visitor
            {
                Browser = "1",
                IpAddress = "2",
                LoginName = "3",
                PathAndQuerystring = "4",
                VisitDate =
                    new DateTime(2000, 1, 1),
                FirstName = "Jones"
            };

            var repository = new VisitorRepository();
            repository.Save(visitor);

            Visitor loadedVisitor;
            using (ISession session = DataContext.GetSession())
            {
                loadedVisitor = session.Load<Visitor>(visitor.Id);
            }

            loadedVisitor.ShouldNotBeNull();
            loadedVisitor.Browser.ShouldEqual("1");
            loadedVisitor.IpAddress.ShouldEqual("2");
            loadedVisitor.LoginName.ShouldEqual("3");
            loadedVisitor.PathAndQuerystring.ShouldEqual("4");
            loadedVisitor.VisitDate.ShouldEqual(new DateTime(2000, 1, 1));
            loadedVisitor.FirstName.ShouldEqual("Jones");
        }
コード例 #2
0
        public void Should_get_two_most_recent_visitors()
        {
            new DatabaseTester().Clean();
            Visitor visitor1 =
                CreateVisitor(new DateTime(2000, 1, 1));
            Visitor visitor2 =
                CreateVisitor(new DateTime(2000, 1, 2));
            Visitor visitor3 =
                CreateVisitor(new DateTime(2000, 1, 3));
            using (ISession session1 = DataContext.GetSession())
            {
                session1.BeginTransaction();
                session1.SaveOrUpdate(visitor1);
                session1.SaveOrUpdate(visitor2);
                session1.SaveOrUpdate(visitor3);
                session1.Transaction.Commit();
            }

            var repository = new VisitorRepository();
            Visitor[] recentVisitors =
                repository.GetRecentVisitors(2);

            recentVisitors.Length.ShouldEqual(2);
            IEnumerable<Guid> idList = recentVisitors.Select(x => x.Id);
            idList.Contains(visitor3.Id).ShouldBeTrue();
            idList.Contains(visitor2.Id).ShouldBeTrue();
            idList.Contains(visitor1.Id).ShouldBeFalse();
        }
コード例 #3
0
        public void When_saving_should_write_to_database()
        {
            new DatabaseTester().Clean();
            Visitor visitor = CreateVisitor(Convert.ToDateTime("1/2/2345"));

            var repository = new VisitorRepository();
            repository.Save(visitor);

            Visitor loadedVisitor;
            using (ISession session = DataContext.GetSession())
            {
                loadedVisitor = session.Load<Visitor>(
                    visitor.Id);
            }

            loadedVisitor.ShouldNotBeNull();
            loadedVisitor.VisitDate.ToShortDateString().ShouldEqual("1/2/2345");
        }