Exemplo n.º 1
0
 public void DataContextMockTest_MockProvider()
 {
     var dataProvider = MockRepository.GenerateMock<UmbracoDataProvider>();
     using (var ctx = new MyUmbracoDataContext(dataProvider))
     {
     }
 }
Exemplo n.º 2
0
        public void DataContextTest_DefaultConstructorIsNodeProvider()
        {
            MockHelpers.SetupFakeHttpContext();

            var ctx = new MyUmbracoDataContext();

            Assert.IsInstanceOfType(ctx.DataProvider, typeof(NodeDataProvider));
        }
Exemplo n.º 3
0
 public void ParentTest_InvalidParentType()
 {
     MockHelpers.SetupFakeHttpContext();
     using (var ctx = new MyUmbracoDataContext())
     {
         var p = ctx.CWSPhotos.First().Parent<CWSHome>();
     }
 }
Exemplo n.º 4
0
 public void ParentTest_ParentIdExists()
 {
     MockHelpers.SetupFakeHttpContext();
     using (var ctx = new MyUmbracoDataContext())
     {
         var p = ctx.CWSTextpages.First();
         Assert.AreNotEqual(0, p.ParentNodeId);
     }
 }
Exemplo n.º 5
0
        public void DataContextTest_EnsureSchemaValidation()
        {
            var nodeProvider = new NodeDataProvider(Path.Combine(Environment.CurrentDirectory, "umbraco.config"), true);

            MyUmbracoDataContext ctx = new MyUmbracoDataContext(nodeProvider);

            var hp = ctx.CWSHomes.First();

            Assert.IsNotNull(hp);
        }
Exemplo n.º 6
0
        public void ChildTest_ChildToParent()
        {
            MockHelpers.SetupFakeHttpContext();
            using (var ctx = new MyUmbracoDataContext())
            {
                var page = ctx.CWSHomes.First().CWSTextpages.First();

                Assert.AreEqual(ctx.CWSHomes.First().Id, page.Parent<CWSHome>().Id);
            }
        }
Exemplo n.º 7
0
        public void DataContextMockTest_MockProviderThrowsException()
        {
            var dataProvider = MockRepository.GenerateMock<UmbracoDataProvider>();

            dataProvider.Stub(d => d.LoadTree<CwsHome>()).Throw(new NotImplementedException());
            using (var ctx = new MyUmbracoDataContext(dataProvider))
            {
                var homes = ctx.CwsHomes;
            }
        }
Exemplo n.º 8
0
        public void ChildTest_ChildExist()
        {
            MockHelpers.SetupFakeHttpContext();
            using (var ctx = new MyUmbracoDataContext())
            {
                var pages = ctx.CWSHomes.First().CWSTextpages;

                Assert.AreNotEqual(0, pages.Count());
            }
        }
Exemplo n.º 9
0
        public void AncestorTest_NoWhereCondition_NotExists()
        {
            MockHelpers.SetupFakeHttpContext();
            using (var ctx = new MyUmbracoDataContext())
            {
                var textPage = ctx.CWSTextpages.First();

                var a = textPage.AncestorOrDefault<CWSPhoto>();

                Assert.IsNull(a);
            }
        }
Exemplo n.º 10
0
        public void CacheTest_RequeryLoadFromCache()
        {
            MockHelpers.SetupFakeHttpContext();

            using (var ctx = new MyUmbracoDataContext())
            {
                var hps = ctx.CWSHomes;

                var requeriedHps = ctx.CWSHomes;

                Assert.AreSame(requeriedHps, hps, "Requeried objects should result in the same collection");
            }
        }
Exemplo n.º 11
0
        public void WhereTest_DateTimeGreaterThan_Query()
        {
            MockHelpers.SetupFakeHttpContext();

            using (var ctx = new MyUmbracoDataContext())
            {
                var pages = from page in ctx.CWSTextpages
                            where page.CreateDate > DateTime.MinValue
                            select page;

                Assert.IsNotNull(pages);
                Assert.IsTrue(pages.Count() > 0);
            }
        }
Exemplo n.º 12
0
        public void WhereTest_SingleParameter_Query()
        {
            MockHelpers.SetupFakeHttpContext();

            using (var ctx = new MyUmbracoDataContext())
            {
                var pages = from page in ctx.CWSTextpages
                            where page.BodyText.Length > 0
                            select page;

                Assert.IsNotNull(pages);
                Assert.IsTrue(pages.Count() > 0);
            }
        }
Exemplo n.º 13
0
        public void ParentTest_ParentCreated()
        {
            MockHelpers.SetupFakeHttpContext();
            using (var ctx = new MyUmbracoDataContext())
            {
                var page = ctx.CWSTextpages.Single(p => p.Id == 1099);

                Assert.AreEqual(1098, page.ParentNodeId);

                var parent = page.Parent<CWSHome>();

                Assert.AreEqual(page.ParentNodeId, parent.Id);
            }
        }
Exemplo n.º 14
0
        public void OrderingTest_Date()
        {
            MockHelpers.SetupFakeHttpContext();

            using (var orderedContext = new MyUmbracoDataContext())
            {
                var asc = orderedContext.CWSTextpages.OrderBy(p => p.CreateDate);

                var desc = orderedContext.CWSTextpages.OrderByDescending(p => p.CreateDate);

                Assert.AreEqual(asc.Count(), desc.Count());
                Assert.AreNotEqual(asc.First().Id, desc.First().Id);
                Assert.AreEqual(asc.First().Id, desc.Last().Id);
            }
        }
Exemplo n.º 15
0
        public void CacheTest_ForcedRefresh()
        {
            MockHelpers.SetupFakeHttpContext();

            using (var ctx = new MyUmbracoDataContext())
            {
                var hps = ctx.CWSHomes;

                ctx.CWSHomes.ReloadCache();

                var reloadedHps = ctx.CWSHomes;

                Assert.AreNotSame(reloadedHps, hps, "Force reload should result in a different object");
            }
        }
Exemplo n.º 16
0
        public void SelectTest_LoopTree_Query()
        {
            MockHelpers.SetupFakeHttpContext();

            using (var ctx = new MyUmbracoDataContext())
            {
                var homePages = from hp in ctx.CWSHomes
                                select hp;

                Assert.IsNotNull(homePages);
                foreach (var item in homePages)
                {
                    Assert.IsTrue(item.BodyText.Length > 0);
                }
            }
        }
Exemplo n.º 17
0
        public void SelectTest_Anonymous_Lambda()
        {
            MockHelpers.SetupFakeHttpContext();

            using (var ctx = new MyUmbracoDataContext())
            {
                var anon = ctx.CWSHomes.Select(hp => new
                           {
                               hp.BodyText,
                               CreatedDate = hp.CreateDate
                           });

                Assert.IsNotNull(anon);
                foreach (var item in anon)
                {
                    Assert.IsNotNull(item.BodyText);
                    Assert.AreNotEqual(DateTime.MinValue, item.CreatedDate);
                }
            }
        }
Exemplo n.º 18
0
        public void CwsReplicationTest_ListGalleries()
        {
            MockHelpers.SetupFakeHttpContext();
            using (var ctx = new MyUmbracoDataContext())
            {
                var galleryList = ctx.CWSGalleryLists.First(); //this would really be a Where(g => g.Id == umbracoContext.Current.PageId.Value) but since I'm not really on a page...

                var galleries = from g in galleryList.CWSGalleries
                                where g.CWSPhotos.Count() >= 1
                                orderby g.Name
                                select new
                                {
                                    g.Name,
                                    Url = umbraco.library.NiceUrl(g.Id),
                                    Thumbnail = (string.IsNullOrEmpty(g.GalleryThumbnail) ? "/Assets/Placeholders/gallery_placeholder.gif" : g.GalleryThumbnail),
                                    PhotoCount = g.CWSPhotos.Count(),
                                };

                Assert.AreEqual(3, galleries.Count());
            }
        }
Exemplo n.º 19
0
        public void SelectTest_SingleProperty_Query()
        {
            MockHelpers.SetupFakeHttpContext();

            using (var ctx = new MyUmbracoDataContext())
            {
                var homePageText = from hp in ctx.CWSHomes
                                   select hp.BodyText;

                Assert.IsNotNull(homePageText);
                foreach (var item in homePageText)
                {
                    Assert.IsNotNull(item);
                }
            }
        }
Exemplo n.º 20
0
 public void DataContextTest_ConstructFromExistingProvider()
 {
     var nodeProvider = new NodeDataProvider(Path.Combine(Environment.CurrentDirectory, "umbraco.config"));
     
     MyUmbracoDataContext ctx = new MyUmbracoDataContext(nodeProvider);
 }
Exemplo n.º 21
0
        public void DataContextTest_OfNodeTypes()
        {
            MockHelpers.SetupFakeHttpContext();
            using (var ctx = new MyUmbracoDataContext())
            {
                var tree = ctx.CWSHomes;

                Assert.IsInstanceOfType(tree, typeof(NodeTree<CWSHome>));
                Assert.IsInstanceOfType(tree.First().CWSTextpages, typeof(NodeAssociationTree<CWSTextpage>));
            }
        }
Exemplo n.º 22
0
        public void DataContextTest_FullCache()
        {
            MockHelpers.SetupFakeHttpContext();
            using (var ctx = new MyUmbracoDataContext())
            {
                var one = ctx.CWSHomes;
                var two = ctx.CWSHomes;

                Assert.AreSame(one, two);
            }
        }
Exemplo n.º 23
0
        public void DataContextTest_NodeCached()
        {
            MockHelpers.SetupFakeHttpContext();
            using (var ctx = new MyUmbracoDataContext())
            {
                var hp = ctx.CWSHomes.First();
                var hp2 = ctx.CWSHomes.First();

                Assert.AreSame(hp, hp2);
            }
        }
Exemplo n.º 24
0
 public void ParentTest_TopParentNull()
 {
     MockHelpers.SetupFakeHttpContext();
     using (var ctx = new MyUmbracoDataContext())
     {
         var hp = ctx.CWSHomes.First();
         Assert.IsNull(hp.Parent<CWSHome>());
     }
 }
Exemplo n.º 25
0
        public void ChildTest_AllChildren()
        {
            MockHelpers.SetupFakeHttpContext();
            using (var ctx = new MyUmbracoDataContext())
            {
                var hp = ctx.CWSHomes.First();

                Assert.IsTrue(hp.Children.Count() > 0);
                Assert.IsInstanceOfType(hp.Children.First(), typeof(CWSTextpage));
                Assert.IsInstanceOfType(hp.Children.Skip(1).First(), typeof(CWSGalleryList));
            }
        }
Exemplo n.º 26
0
        public void AncestorTest_Where_Exists()
        {
            MockHelpers.SetupFakeHttpContext();
            using (var ctx = new MyUmbracoDataContext())
            {
                var photo = ctx.CWSPhotos.First(p => p.Name.Contains("Umbraco"));
                var gallery = photo.AncestorOrDefault<CWSGallery>(g => g.Name.Contains("Codegarden"));

                Assert.IsNotNull(gallery);
            }
        }
Exemplo n.º 27
0
        public void WhereTest_ToAnonymous()
        {
            MockHelpers.SetupFakeHttpContext();
            using (var ctx = new MyUmbracoDataContext())
            {
                var pages = from page in ctx.CWSTextpages
                            where page.BodyText.Length > 0
                            select new
                            {
                                page.Id,
                                page.BodyText
                            };

                Assert.AreNotEqual(0, pages.Count());
            }
        }