public void UpdatePersonTest()
        {
            using (var context = new ObjectContextAdapter(new AdventureWorks2008R2Entities()))
            {
                using (var unitOfWork = new UnitOfWork(context))
                {
                    var dateNow = DateTime.Now;

                    var personRepo = new Repository <Person>(context);

                    var predicate = PredicateBuilder.True <Person>();
                    predicate = predicate.And(p => p.LastName.Equals("Grangeau"));
                    predicate = predicate.And(p => p.BusinessEntityID == 20780);

                    var person = personRepo.Single(predicate);

                    person.ModifiedDate = dateNow;

                    personRepo.Update(person);
                    unitOfWork.Commit();

                    Assert.IsNull(person.BusinessEntity);
                    Assert.IsTrue(person.BusinessEntityID == 20780);
                    Assert.IsTrue(person.FirstName.Equals("Laurent"));
                    Assert.IsTrue(person.LastName.Equals("Grangeau"));
                    Assert.IsTrue(person.PersonType.Equals("GC"));
                    Assert.IsTrue(person.ModifiedDate.Equals(dateNow));
                }
            }
        }
        public void FirstPersonTest()
        {
            using (var context = new ObjectContextAdapter(new AdventureWorks2008R2Entities()))
            {
                var personRepo = new Repository <Person>(context);
                var predicate  = PredicateBuilder.True <Person>();

                var person = personRepo.First(predicate);
            }
        }
        public void TestGetDBDataWithOutDI()
        {
            var dbcontext         = new TestPerformaceDBEntities();
            var contextAdapter    = new ObjectContextAdapter(dbcontext);
            var productRepository = new ProductsRepository(
                new EFRepository <Products>(contextAdapter), new EFUnitOfWork(contextAdapter));

            IEnumerable <Products> resultset = productRepository.Repository.Find(p => p.ProductID == 1);

            Assert.IsNotNull(resultset);
            Assert.IsNotNull(resultset.FirstOrDefault().ProductName);
        }
        public void AddPersonTest()
        {
            using (var context = new ObjectContextAdapter(new AdventureWorks2008R2Entities()))
            {
                using (var unitOfWork = new UnitOfWork(context))
                {
                    var dateNow = DateTime.Now;

                    var personRepo         = new Repository <Person>(context);
                    var businessEntityRepo = new Repository <BusinessEntity>(context);

                    var businessEntity = new BusinessEntity()
                    {
                        rowguid      = Guid.NewGuid(),
                        ModifiedDate = dateNow
                    };

                    var person = new Person()
                    {
                        BusinessEntity = businessEntity,
                        FirstName      = "Laurent",
                        LastName       = "Grangeau",
                        PersonType     = "GC",
                        rowguid        = Guid.NewGuid(),
                        ModifiedDate   = dateNow
                    };

                    businessEntityRepo.Create(businessEntity);
                    personRepo.Create(person);

                    unitOfWork.Commit();

                    Assert.IsNotNull(businessEntity.BusinessEntityID);
                    Assert.IsNotNull(person.BusinessEntityID);
                    Assert.IsNotNull(person.BusinessEntity);
                    Assert.IsTrue(person.FirstName.Equals("Laurent"));
                    Assert.IsTrue(person.LastName.Equals("Grangeau"));
                    Assert.IsTrue(person.PersonType.Equals("GC"));
                    Assert.IsTrue(person.ModifiedDate.Equals(dateNow));
                    Assert.IsTrue(businessEntity.ModifiedDate.Equals(dateNow));
                }
            }
        }
        public void SinglePersonTest()
        {
            using (var context = new ObjectContextAdapter(new AdventureWorks2008R2Entities()))
            {
                var personRepo = new Repository <Person>(context);

                var predicate = PredicateBuilder.True <Person>();
                predicate = predicate.And(p => p.LastName.Equals("Grangeau"));
                predicate = predicate.And(p => p.BusinessEntityID == 20780);

                var person = personRepo.Single(predicate, p => p.BusinessEntity);

                Assert.IsNotNull(person.BusinessEntity);
                Assert.IsTrue(person.BusinessEntityID == 20780);
                Assert.IsTrue(person.FirstName.Equals("Laurent"));
                Assert.IsTrue(person.LastName.Equals("Grangeau"));
                Assert.IsTrue(person.PersonType.Equals("GC"));
            }
        }
Beispiel #6
0
        /// <summary>
        /// Gets the home page
        /// </summary>
        /// <param name="page">Requested page number</param>
        /// <returns>The home page</returns>
        public ActionResult Index(int? page)
        {
            int count;
            int maxRecords = BlogUtility.GetPageSize();
            int skip = (int)(!page.HasValue ? 0 : (page - 1) * maxRecords);
            Guid blogId = BlogUtility.GetBlogId();
            HomeViewModel model;
            List<BlogPost> posts;
            List<Keyword> tags;
            IObjectContext context = new ObjectContextAdapter(DatabaseUtility.GetContext());
            Dictionary<Guid, int> blogPostCommentCount = new Dictionary<Guid, int>();

            using (IBlogPostRepository blogPostRepository = ObjectFactory.With(context).GetInstance<IBlogPostRepository>())
            using (IKeywordRepository keywordRepository = ObjectFactory.With(context).GetInstance<IKeywordRepository>())
            {
                posts = (from m in blogPostRepository.Fetch()
                         where m.BlogId == blogId
                         orderby m.PostedDate descending
                         select m).Skip(skip).Take(maxRecords).ToList();

                tags = (from t in keywordRepository.Fetch()
                        where t.BlogId == blogId
                        select t).Take(maxRecords).ToList();

                // Get the total blog post count
                count = (from m in blogPostRepository.Fetch()
                         where m.BlogId == blogId
                         select m).Count();

                // Determine the comment count for each blog post
                foreach (BlogPost post in posts)
                {
                    blogPostCommentCount.Add(post.BlogPostId, post.UserComments.Count);
                }

                model = new HomeViewModel(posts, tags, blogPostCommentCount, count, page ?? 1, skip + maxRecords < count, skip - maxRecords >= 0);
            }

            return View(model);
        }
        public void TestGetDBDataWithOutDI()
        {
            var dbcontext = new TestPerformaceDBEntities();
            var contextAdapter = new ObjectContextAdapter(dbcontext);
            var productRepository = new ProductsRepository(
                new EFRepository<Products>(contextAdapter), new EFUnitOfWork(contextAdapter));

            IEnumerable<Products> resultset = productRepository.Repository.Find(p => p.ProductID == 1);

            Assert.IsNotNull(resultset);
            Assert.IsNotNull(resultset.FirstOrDefault().ProductName);
        }
Beispiel #8
0
        /// <summary>
        /// Searches the database for blog posts containing the specified tags
        /// </summary>
        /// <param name="tag">Search term for which to query the model against</param>
        /// <returns>The search results of the query</returns>
        public ActionResult SearchByTag(string tag)
        {
            Guid blogId = BlogUtility.GetBlogId();
            BlogListBase model;
            List<BlogPost> posts;
            IObjectContext context = new ObjectContextAdapter(DatabaseUtility.GetContext());

            using (IBlogPostRepository blogPostRepository = ObjectFactory.With(context).GetInstance<IBlogPostRepository>())
            using (IKeywordRepository keywordRepository = ObjectFactory.With(context).GetInstance<IKeywordRepository>())
            {
                // TODO: There must be a better way to do this
                posts = (from k in keywordRepository.Fetch()
                         where k.BlogId == blogId && k.Keyword1 == tag
                         select k.BlogPosts).ToList()[0].ToList();
            }

            model = new BlogListBase(posts);

            return View("Search", model);
        }