public void Initialize()
        {


            var session = ApplicationManager.SessionFactory.OpenSession();
            var user = new User { Username="******", Name = "my name", Email = "*****@*****.**", Password = "******", Address = new Address { City = "São paulo", StreetName="name", Number="123B", State="SP", ZipCode="03423-234" } };
            user.AddBlog(new WebLog { Title = "My blog", Creator=user });
            session.Save(user);
            session.Flush();
            session.Close();

            session = ApplicationManager.SessionFactory.OpenSession();
            ThreadStaticSessionContext.Bind(session);
        }
Ejemplo n.º 2
0
        public void Initialize()
        {
            var context = new EntityFrameworkRepositoryContext(new BlogContext());
            WebLogs = new GenericRepository<WebLog>(context);

            var title = Guid.NewGuid().ToString();

            var user = new User { Name = "user " + title };
            var webLog = new WebLog { Title = webLogID, CreatedAt = DateTime.Now };
            var post = new Post { Title = postID, Text = "oi", CreatedAt = DateTime.Now, LastUpdatedAt = DateTime.Now, PublishedAt = DateTime.Now };

            webLog.Collaborators.Add(user);
            user.AddBlog(webLog);
            webLog.Posts.Add(post);
            post.WebLog = webLog;

            WebLogs.SaveOrUpdate(webLog);
        }
		public void SelectWithLambdaExpressions()
		{
            var title = Guid.NewGuid().ToString();
            var user = new User { Name = "user " + title };
            var webLog = new WebLog { Title = "weblog " + title, CreatedAt = DateTime.Now };
            var post = new Post { Title = title, Text = "oi", CreatedAt = DateTime.Now, LastUpdatedAt = DateTime.Now, PublishedAt = DateTime.Now };

            webLog.Collaborators.Add(user);
            user.AddBlog(webLog);
            webLog.Posts.Add(post);
            post.WebLog = webLog;

            webLogRepository.SaveOrUpdate(webLog);
            webLogRepository.SaveChanges();

            var posts = (from w in webLogRepository.Query()
                            from p in w.Posts
                            where p.Title == title
                            select p).ToList(); 
            Assert.AreEqual(1, posts.Count);
		}