Exemple #1
0
        public TTreeForm( string dotPath, int min, int max )
        {
            InitializeComponent();

            DeleteOldFiles();

            m_dotPath = dotPath;
            m_root = new TTree<int>( min, max );
            m_oldDot = m_root.ToDot();
            Redraw();
        }
Exemple #2
0
        public void InsertIntoRootWithSpace()
        {
            var tree = new TTree <int>(5, 5);

            tree.Add(10);
            tree.Add(5);
            tree.Add(15);
            tree.Add(7);
            tree.Add(3);

            CheckTree <int>(tree.RootNode, 0, new[] { 3, 5, 7, 10, 15 }, false, false, null, 3);
        }
Exemple #3
0
        public void Delete_From_HalfLeaf_Merges()
        {
            var tree = new TTree <int>(3, 3);

            tree.Add(10);
            tree.Add(11);
            tree.Add(12);
            tree.Add(5);

            tree.Remove(12);

            CheckTree <int>(tree.RootNode, 0, new[] { 5, 10, 11 }, false, false, null, 5);
        }
        public void ShouldGetProductByIdBackOrderable()
        {
            // Arrange
            var stockInfo = new StockInformation {
                Product = new InventoryProduct {
                    ProductId = "1001"
                }, Status = StockStatus.BackOrderable, AvailabilityDate = new DateTime(2014, 3, 12)
            };
            var orderableInfo = new OrderableInformation {
                Product = new InventoryProduct {
                    ProductId = "1001"
                }, Status = StockStatus.BackOrderable, InStockDate = new DateTime(2014, 3, 12)
            };

            using (new SiteContextSwitcher(new TSiteContext("shopname")))
            {
                using (var tree = new TTree {
                    new TItem("T-800", new NameValueCollection {
                        { "ExternalID", "1001" }
                    })
                })
                {
                    Item productItem = tree.Database.GetItem("/sitecore/content/home/T-800");
                    this.productService.ReadProduct("1001").Returns(productItem);
                    this.pricingService.GetProductPrice("1001").Returns(5000);
                    this._inventoryService
                    .GetStockInformation("shopname", Arg.Is <IEnumerable <string> >(ids => ids.Contains("1001") && ids.Count() == 1), StockDetailsLevel.All, string.Empty, string.Empty)
                    .Returns(new List <StockInformation> {
                        stockInfo
                    });
                    this._inventoryService
                    .GetBackOrderableInformation("shopname", Arg.Is <IEnumerable <string> >(ids => ids.Contains("1001") && ids.Count() == 1), string.Empty, string.Empty)
                    .Returns(new List <OrderableInformation> {
                        orderableInfo
                    });

                    GlassMapperService.Current.CreateClass <ProductModel, decimal, StockInformation, OrderableInformation>(false, false, Arg.Is <Item>(item => item.ID == productItem.ID), 5000, stockInfo, orderableInfo)
                    .Returns(new ProductModel(5000, stockInfo, orderableInfo));

                    // Act
                    var result = this.controller.Index("1001");

                    // Assert
                    var productModel = (ProductModel)((ViewResult)result).Model;
                    productModel.Price.Should().Be(5000);
                    productModel.Status.Should().Be(StockStatus.BackOrderable);
                    productModel.AvailabilityDate.Should().Be(new DateTime(2014, 3, 12));
                    productModel.InStockDate.Should().Be(new DateTime(2014, 3, 12));
                }
            }
        }
Exemple #5
0
        public void Insert_FullRoot_OverflowLeftToNewNode_LastNodeIsNotBounding()
        {
            var tree = new TTree <int>(4, 4);

            tree.Add(10);
            tree.Add(5);
            tree.Add(15);
            tree.Add(7);
            CheckTree <int>(tree.RootNode, 0, new[] { 5, 7, 10, 15 }, false, false, null, 5);

            tree.Add(2);
            CheckTree <int>(tree.RootNode, 1, new[] { 5, 7, 10, 15 }, true, false, null, 5);
            CheckTree <int>(tree.RootNode.Left, 0, new[] { 2 }, false, false, tree.RootNode, 5);
        }
Exemple #6
0
        /// <summary>
        /// The create sections.
        /// </summary>
        /// <param name="tree">
        /// The tree.
        /// </param>
        /// <param name="template">
        /// The template.
        /// </param>
        private static void CreateSections(TTree tree, TTemplate template)
        {
            foreach (TSection section in template)
              {
            Item item = tree.Database.GetItem(section.ID);

            if (item == null)
            {
              tree.Database.CreateItem(section.ID, section.Name, new TemplateID(TemplateIDs.TemplateSection), template.ID);
            }

            CreateFields(tree, section);
              }
        }
Exemple #7
0
        public void Clear()
        {
            var tree = new TTree <int>(2, 2);

            tree.Add(10);
            tree.Add(11);
            tree.Add(1);
            tree.Add(20);
            tree.Clear();

            Assert.AreEqual(0, tree.Count, "Invalid count");
            Assert.AreEqual(0, tree.Count, "Invalid item count");
            Assert.AreEqual(0, tree.Height, "Invalid height");
        }
Exemple #8
0
        public void CheckThatAllInsertedItemsExist()
        {
            var tree = new TTree <int>(20, 23);

            for (int i = 0; i < 1000; ++i)
            {
                tree.Add(i);
            }

            for (int i = 0; i < 1000; ++i)
            {
                Assert.AreEqual(i, tree.Search(i));
            }
        }
Exemple #9
0
        public void Delete_From_NodeNoUnderflow_RemovesItem()
        {
            var tree = new TTree <int>(2, 3);

            tree.Add(10);
            tree.Add(11);
            tree.Add(12);
            tree.Add(4);
            tree.Add(5);

            tree.Remove(11);

            CheckTree <int>(tree.RootNode, 1, new[] { 10, 12 }, true, false, null, 10);
            CheckTree <int>(tree.RootNode.Left, 0, new[] { 4, 5 }, false, false, tree.RootNode, 10);
        }
Exemple #10
0
        public void Delete_From_HalfLeaf_RemovesItem()
        {
            var tree = new TTree <int>(3, 3);

            tree.Add(10);
            tree.Add(11);
            tree.Add(12);
            tree.Add(4);
            tree.Add(5);

            tree.Remove(12);

            CheckTree <int>(tree.RootNode, 1, new[] { 10, 11 }, true, false, null, 10);
            CheckTree <int>(tree.RootNode.Left, 0, new[] { 4, 5 }, false, false, tree.RootNode, 10);
        }
Exemple #11
0
        public void Delete_From_InternalNode_BorrowTheGreatestLowerBound_WhenLeafBecomesEmpty()
        {
            var tree = new TTree <int>(3, 3);

            tree.Add(10);
            tree.Add(11);
            tree.Add(12);
            tree.Add(4);
            tree.Add(15);

            tree.Remove(11);

            CheckTree <int>(tree.RootNode, 1, new[] { 4, 10, 12 }, false, true, null, 4);
            CheckTree <int>(tree.RootNode.Right, 0, new[] { 15 }, false, false, tree.RootNode, 4);
        }
        public void ShouldReturnEmptyCollectionIfNoRenderingFound()
        {
            // Arrange
            var helper = new ContentSearchHelper();

            using (var tree = new TTree())
            {
                var item = tree.Database.GetItem("/sitecore/content/home");

                // Act
                var query = helper.GetDataSourceQuery(item, new DeviceItem(item), ID.NewID.ToString());

                // Assert
                query.Should().BeEmpty();
            }
        }
Exemple #13
0
        public void Insert_FullRoot_OverflowLeftToNewNode_LastNodeIsBounding()
        {
            var tree = new TTree <int>(4, 4)
            {
                10,
                2,
                15,
                7
            };

            CheckTree <int>(tree.RootNode, 0, new[] { 2, 7, 10, 15 }, false, false, null, 2);

            tree.Add(8);
            CheckTree <int>(tree.RootNode, 1, new[] { 7, 8, 10, 15 }, true, false, null, 7);
            CheckTree <int>(tree.RootNode.Left, 0, new[] { 2 }, false, false, tree.RootNode, 7);
        }
Exemple #14
0
        public void Rotate_LR()
        {
            var tree = new TTree <int>(1, 1);

            tree.Add(5);
            CheckTree <int>(tree.RootNode, 0, new[] { 5 }, false, false, null, 5);

            tree.Add(3);
            CheckTree <int>(tree.RootNode, 1, new[] { 5 }, true, false, null, 5);
            CheckTree <int>(tree.RootNode.Left, 0, new[] { 3 }, false, false, tree.RootNode, 5);

            tree.Add(4);
            CheckTree <int>(tree.RootNode, 1, new[] { 4 }, true, true, null, 4);
            CheckTree <int>(tree.RootNode.Left, 0, new[] { 3 }, false, false, tree.RootNode, 4);
            CheckTree <int>(tree.RootNode.Right, 0, new[] { 5 }, false, false, tree.RootNode, 4);
        }
Exemple #15
0
        public void CustomSearch()
        {
            var tree = new TTree <string>(1, 1);

            tree.Add("70");
            tree.Add("20");
            tree.Add("10");
            tree.Add("50");
            tree.Add("90");

            Assert.AreEqual("90", tree.Search(90, (x, y) => x.ToString().CompareTo(y)));
            Assert.AreEqual("70", tree.Search(70, (x, y) => x.ToString().CompareTo(y)));
            Assert.AreEqual("50", tree.Search(50, (x, y) => x.ToString().CompareTo(y)));
            Assert.AreEqual("20", tree.Search(20, (x, y) => x.ToString().CompareTo(y)));
            Assert.AreEqual("10", tree.Search(10, (x, y) => x.ToString().CompareTo(y)));
        }
Exemple #16
0
        public void Search()
        {
            var tree = new TTree <int>(1, 1);

            tree.Add(70);
            tree.Add(20);
            tree.Add(10);
            tree.Add(50);
            tree.Add(90);

            Assert.AreEqual(90, tree.Search(90));
            Assert.AreEqual(70, tree.Search(70));
            Assert.AreEqual(50, tree.Search(50));
            Assert.AreEqual(20, tree.Search(20));
            Assert.AreEqual(10, tree.Search(10));
        }
Exemple #17
0
        /// <summary>
        /// The create template.
        /// </summary>
        /// <param name="tree">
        /// The tree.
        /// </param>
        /// <param name="template">
        /// The template.
        /// </param>
        /// <param name="parentId">
        /// The parent id.
        /// </param>
        public static void CreateTemplate(TTree tree, TTemplate template, ID parentId)
        {
            Assert.ArgumentNotNull(tree, "database");
              Assert.ArgumentNotNull(template, "template");
              Assert.ArgumentNotNull(parentId, "parentId");

              Item item = tree.Database.GetItem(template.ID);

              if (item == null)
              {
            tree.Database.CreateItem(template.ID, template.Name, new TemplateID(TemplateIDs.Template), parentId);
              }

              CreateSections(tree, template);

              tree.Database.Engines.TemplateEngine.Reset();
        }
Exemple #18
0
        private static void InsertLoop()
        {
            Console.WriteLine("Number of iteration? ");
            int max = int.Parse(Console.ReadLine());

            Console.WriteLine("Tree min order (max = min + 3)?");
            int orderMin = int.Parse(Console.ReadLine());

            TTree <string> root = new TTree <string>(orderMin, orderMin + 3);

            for (int i = 0; i < max; ++i)
            {
                string item = Guid.NewGuid().ToString();
                root.Add(item);
                root.Search(item);
            }
        }
        public void SetUp()
        {
            this.TemplateId = ID.NewID;
            this.ItemId     = new ID("{F8530460-A50F-44A6-B352-F548C8313544}");

            this.Tree = new TTree("master")
            {
                new TTemplate(this.TemplateId)
                {
                    new TSection("Data")
                    {
                        { "Field1", ID.NewID },
                    }
                },
                new TItem(this.ItemId, new TemplateID(this.TemplateId))
            };
        }
Exemple #20
0
        public void Delete_From_InternalNode_BorrowTheGreatestLowerBound()
        {
            var tree = new TTree <int>(3, 3);

            tree.Add(10);
            tree.Add(11);
            tree.Add(12);
            tree.Add(4);
            tree.Add(5);
            tree.Add(15);

            tree.Remove(11);

            CheckTree <int>(tree.RootNode, 1, new[] { 5, 10, 12 }, true, true, null, 5);
            CheckTree <int>(tree.RootNode.Left, 0, new[] { 4 }, false, false, tree.RootNode, 5);
            CheckTree <int>(tree.RootNode.Right, 0, new[] { 15 }, false, false, tree.RootNode, 5);
        }
Exemple #21
0
        public void Delete_From_RightLeaf_BecomesEmpty()
        {
            var tree = new TTree <int>(2, 3);

            tree.Add(1);
            tree.Add(2);
            tree.Add(3);
            tree.Add(4);
            tree.Add(5);
            tree.Add(6);
            tree.Add(7);

            tree.Remove(7);

            CheckTree <int>(tree.RootNode, 1, new[] { 4, 5, 6 }, true, false, null, 4);
            CheckTree <int>(tree.RootNode.Left, 0, new[] { 1, 2, 3 }, false, false, tree.RootNode, 4);
        }
Exemple #22
0
        /// <summary>
        /// The create fields.
        /// </summary>
        /// <param name="tree">
        /// The tree.
        /// </param>
        /// <param name="section">
        /// The section.
        /// </param>
        private static void CreateFields(TTree tree, TSection section)
        {
            foreach (TField field in section)
              {
            Item item = tree.Database.GetItem(field.ID);

            if (item == null)
            {
              tree.Database.CreateItem(field.ID, field.Name, new TemplateID(TemplateIDs.TemplateField), section.ID);
            }

            item = tree.Database.GetItem(field.ID, Language.Invariant, Version.Latest);

            item.Edit(i => i.Fields[TemplateFieldIDs.Type].Value = field.Type);
            item.Edit(i => i.Fields[TemplateFieldIDs.Shared].Value = field.Shared ? "1" : "0");
            item.Edit(i => i.Fields[TemplateFieldIDs.Unversioned].Value = field.Unversioned ? "1" : "0");
              }
        }
Exemple #23
0
        public void CopyItems()
        {
            var tree = new TTree <int>(2, 2);

            tree.Add(10);
            tree.Add(11);
            tree.Add(1);
            tree.Add(20);

            var items = new int[20];

            tree.CopyItems(items, 0);

            Assert.AreEqual(1, items[0], "Invalid value at 0");
            Assert.AreEqual(10, items[1], "Invalid value at 1");
            Assert.AreEqual(11, items[2], "Invalid value at 2");
            Assert.AreEqual(20, items[3], "Invalid value at 3");
        }
Exemple #24
0
        public void Contains()
        {
            var tree = new TTree <int>(2, 2);

            tree.Add(10);
            tree.Add(11);
            tree.Add(1);
            tree.Add(20);

            Assert.IsTrue(tree.Contains(1), "Should contain 1");
            Assert.IsTrue(tree.Contains(10), "Should contain 10");
            Assert.IsTrue(tree.Contains(11), "Should contain 11");
            Assert.IsTrue(tree.Contains(20), "Should contain 20");

            Assert.IsFalse(tree.Contains(5), "Should not contain 5");
            Assert.IsFalse(tree.Contains(3), "Should not contain 3");
            Assert.IsFalse(tree.Contains(7), "Should not contain 7");
        }
Exemple #25
0
        public void Delete_ShouldRebalance()
        {
            var tree = new TTree <int>(2, 3);

            tree.Add(10);
            tree.Add(11);
            tree.Add(12);
            tree.Add(1);
            tree.Add(13);
            tree.Add(14);
            tree.Add(15);
            tree.Add(16);

            tree.Remove(1);

            CheckTree <int>(tree.RootNode, 1, new[] { 13, 14, 15 }, true, true, null, 13);
            CheckTree <int>(tree.RootNode.Left, 0, new[] { 10, 11, 12 }, false, false, tree.RootNode, 13);
            CheckTree <int>(tree.RootNode.Right, 0, new[] { 16 }, false, false, tree.RootNode, 13);
        }
        public void ShouldTryToRetrieveRendering()
        {
            // arrange
            using (var ttree = new TTree {
                new TItem("Products list")
            })
            {
                var productsItem = ttree.Database.GetItem("/sitecore/content/home/Products list");

                // act
                using (new ContextItemSwitcher(productsItem))
                {
                    this.controller.List();
                }

                // assert
                this.contentSearchHelper.Received().GetDataSourceQuery(productsItem, Context.Device, ProductController.ProductListRenderingId);
            }
        }
Exemple #27
0
    void Choose()
    {
        if (chosen)
        {
            return;
        }

        if (selected != null)
        {
            selected.Selected = false;
        }

        RaycastHit hit;

        if (Physics.Raycast(Cam.recorder.ScreenPointToRay(Input.mousePosition), out hit, Mathf.Infinity, GameManager.gm.trees))
        {
            //if (selected != null) selected.Selected = false;
            TTree tree = hit.collider.GetComponent <TTree>();
            selected      = tree;
            tree.Selected = true;
            if (Input.GetMouseButtonDown(0))
            {
                TTree.TryCutAll();
                //GameManager.GState = GameManager.State.Play;
                //////Console.Print("Use the arrow keys to move");
                //////Console.Print("Use R to restart", 15);

                chosen = true;
            }
        }

        //if(Physics.Raycast(Cam.recorder.ScreenPointToRay(Input.mousePosition), out hit, Mathf.Infinity, mask);)

        //if (InputManager.Finger(InputManager.IType.Down))
        //{

        //    RaycastHit hit;
        //    if (InputManager.FingerRaycast(out hit, GameManager.gm.ground))
        //    {

        //    }
        //}
    }
Exemple #28
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ProductExtensionsTest"/> class.
 /// </summary>
 public ProductExtensionsTest()
 {
     new Glass.Sitecore.Mapper.Context();
     GlassMapperService.Current = Substitute.For <Glass.Sitecore.Mapper.ISitecoreService>();
     this.tree = new TTree {
         new TItem("T-800")
         {
             new TItem("Resources")
             {
                 new TItem("ProductResource1")
                 {
                     { "Type", "Image" }
                 }
             }
         }
     };
     this.productItem          = this.tree.Database.GetItem("/sitecore/content/home/T-800");
     this.productResourceItem1 = this.tree.Database.GetItem("/sitecore/content/home/T-800/Resources/ProductResource1");
     this.productModel         = new ProductModel(5000, new StockInformation());
 }
Exemple #29
0
        public void Rotate_RL_SlidingRotate()
        {
            var tree = new TTree <int>(3, 3);

            tree.Add(30);
            tree.Add(31);
            tree.Add(32);
            CheckTree <int>(tree.RootNode, 0, new[] { 30, 31, 32 }, false, false, null, 30);

            tree.Add(50);
            tree.Add(51);
            tree.Add(52);
            CheckTree <int>(tree.RootNode, 1, new[] { 30, 31, 32 }, false, true, null, 30);
            CheckTree <int>(tree.RootNode.Right, 0, new[] { 50, 51, 52 }, false, false, tree.RootNode, 30);

            tree.Add(40);
            CheckTree <int>(tree.RootNode, 1, new[] { 40, 50, 51 }, true, true, null, 40);
            CheckTree <int>(tree.RootNode.Left, 0, new[] { 30, 31, 32 }, false, false, tree.RootNode, 40);
            CheckTree <int>(tree.RootNode.Right, 0, new[] { 52 }, false, false, tree.RootNode, 40);
        }
Exemple #30
0
        public void Rotate_LR_SlidingRotate()
        {
            var tree = new TTree <int>(3, 3);

            tree.Add(20);
            tree.Add(21);
            tree.Add(22);
            CheckTree <int>(tree.RootNode, 0, new[] { 20, 21, 22 }, false, false, null, 20);

            tree.Add(10);
            tree.Add(11);
            tree.Add(12);
            CheckTree <int>(tree.RootNode, 1, new[] { 20, 21, 22 }, true, false, null, 20);
            CheckTree <int>(tree.RootNode.Left, 0, new[] { 10, 11, 12 }, false, false, tree.RootNode, 20);

            tree.Add(15);
            CheckTree <int>(tree.RootNode, 1, new[] { 11, 12, 15 }, true, true, null, 11);
            CheckTree <int>(tree.RootNode.Left, 0, new[] { 10 }, false, false, tree.RootNode, 11);
            CheckTree <int>(tree.RootNode.Right, 0, new[] { 20, 21, 22 }, false, false, tree.RootNode, 11);
        }
        public void ShouldReturnNullIfNoProductFound()
        {
            using (var tree = new TTree("web")
            {
                new TItem("Product Repository", ID.NewID, ID.NewID, ItemIDs.ContentRoot)
            })
            {
                var searchContext = Substitute.For <IProviderSearchContext>();
                searchContext.GetQueryable <SearchResultItem>().Returns((new SearchResultItem[] { }).AsQueryable());

                this.index.CreateSearchContext().Returns(searchContext);

                var service = new ProductService(tree.Database, Language.Parse("en"));

                // Act
                var product = service.ReadProduct("t-800");

                // Assert
                product.Should().BeNull();
            }
        }
        public void UpdateFieldShouldbeCalled(bool needUpdate)
        {
            var templateId = ID.NewID;
            var itemId     = ID.NewID;

            using (
                var tree = new TTree("master")
            {
                new TTemplate(templateId)
                {
                    new TSection("Data")
                    {
                        { "Field1", ID.NewID }
                    }
                },
                new TItem(itemId, new TemplateID(templateId))
            })
            {
                var item = tree.Database.GetItem(itemId);

                var mock = new Mock <NodeFieldMigrator <XmlDocument, XmlNode> > {
                    CallBase = true
                };

                mock.Protected()
                .Setup <IEnumerable <XmlNode> >("GetNodes", new object[] { ItExpr.IsAny <XmlDocument>() })
                .Returns(new[] { It.IsAny <XmlDocument>(), It.IsAny <XmlDocument>() });

                mock.Protected()
                .Setup <bool>("MigrateNode", new object[] { ItExpr.IsAny <Field>(), ItExpr.IsAny <XmlNode>() })
                .Returns(needUpdate);

                mock.Object.MigrateField(item.Fields["Field1"]);

                mock.Protected().Verify(
                    "UpdateField",
                    needUpdate ? Times.Once() : Times.Never(),
                    new object[] { ItExpr.IsAny <Field>(), ItExpr.IsAny <XmlDocument>() });
            }
        }
        public void MigrateNodeShouldBeCalledForEachNode(int count)
        {
            var templateId = ID.NewID;
            var itemId     = ID.NewID;

            var nodes = count > 0 ? Enumerable.Repeat(It.IsAny <XmlDocument>(), count).ToList() : null;

            using (
                var tree = new TTree("master")
            {
                new TTemplate(templateId)
                {
                    new TSection("Data")
                    {
                        { "Field1", ID.NewID }
                    }
                },
                new TItem(itemId, new TemplateID(templateId))
            })
            {
                var item = tree.Database.GetItem(itemId);

                var mock = new Mock <NodeFieldMigrator <XmlDocument, XmlNode> > {
                    CallBase = true
                };

                mock.Protected()
                .Setup <IEnumerable <XmlNode> >("GetNodes", new object[] { ItExpr.IsAny <XmlDocument>() })
                .Returns(
                    nodes);


                mock.Object.MigrateField(item.Fields["Field1"]);

                mock.Protected().Verify(
                    "MigrateNode",
                    Times.Exactly(nodes != null ? nodes.Count : 0),
                    new object[] { ItExpr.IsAny <Field>(), ItExpr.IsAny <XmlNode>() });
            }
        }
Exemple #34
0
        public void CheckHeightAfterMultiLevelInsert()
        {
            var tree = new TTree <int>(2, 2);

            tree.Add(10);
            tree.Add(20);
            tree.Add(30);
            tree.Add(40);
            tree.Add(50);
            tree.Add(60);
            tree.Add(70);
            tree.Add(80);
            tree.Add(90);

            CheckTree <int>(tree.RootNode, 2, new[] { 30, 40 }, true, true, null, 30);

            CheckTree <int>(tree.RootNode.Left, 0, new[] { 10, 20 }, false, false, tree.RootNode, 30);
            CheckTree <int>(tree.RootNode.Right, 1, new[] { 70, 80 }, true, true, tree.RootNode, 30);

            CheckTree <int>(tree.RootNode.Right.Left, 0, new[] { 50, 60 }, false, false, tree.RootNode.Right, 30);
            CheckTree <int>(tree.RootNode.Right.Right, 0, new[] { 90 }, false, false, tree.RootNode.Right, 30);
        }
Exemple #35
0
        public void ShouldApplySecurityCheck()
        {
            // Arrange
              using (var tree = new TTree())
              {
            User user = AuthenticationManager.BuildVirtualUser("User", true);
            user.RuntimeSettings.IsAdministrator = false;

            var rules = new AccessRuleCollection
            {
               AccessRule.Create(user, AccessRight.ItemRead, PropagationType.Any, AccessPermission.Deny)
            };

            const string Path = "/sitecore/content/home";
            var item = tree.Database.GetItem(Path);
            item.Security.SetAccessRules(rules);

            // Act & Assert
            using (var switcher = new UserSwitcher(user))
            {
              tree.Database.GetItem(Path).Should().BeNull();
            }
              }
        }
Exemple #36
0
        public void ShouldCreateItemHierarchyAndReadRootAndChildren()
        {
            // Arrange
              using (
            var tree = new TTree
            {
              new TItem("Products")
              {
             new TItem("Camera") { { "Price", "$1000" } }, new TItem("Laptop") { { "Price", "$2000" } }
              }
            })
              {
            // Act
            var products = tree.Database.GetItem("/sitecore/content/home/products");

            // Assert
            products.Children["Camera"]["Price"].Should().Be("$1000");
            products.Children["Laptop"]["Price"].Should().Be("$2000");
              }
        }
Exemple #37
0
 /// <summary>
 /// Initializes a new instance of the <see cref="TContext"/> class.
 /// </summary>
 /// <param name="tree">
 /// The tree.
 /// </param>
 public TContext(TTree tree)
     : this()
 {
     this.Tree = tree;
 }
Exemple #38
0
        public void ShouldCreateFewItemsOnTheSameTemplateAndReadFields()
        {
            // Arrange
              ID templateId = ID.NewID;
              using (
            var tree = new TTree
            {
              new TTemplate("Product", templateId) { new TSection("Data") { new Collection<string> { "Title", "Price" } } },
              new TItem("My Camera", new TemplateID(templateId)) { { "Title", "My Camera" }, { "Price", "$1000" } },
              new TItem("My Laptop", new TemplateID(templateId)) { { "Title", "My Laptop" }, { "Price", "$1200" } }
            })
              {
            // Act
            var camera = tree.Database.GetItem("/sitecore/content/home/my camera");
            var laptop = tree.Database.GetItem("/sitecore/content/home/my laptop");

            // Assert
            camera.TemplateID.Guid.Should().Be(templateId.Guid);
            camera.Fields["Title"].Value.Should().Be("My Camera");
            camera.Fields["Price"].Value.Should().Be("$1000");

            laptop.TemplateID.Guid.Should().Be(templateId.Guid);
            laptop.Fields["Title"].Value.Should().Be("My Laptop");
            laptop.Fields["Price"].Value.Should().Be("$1200");
              }
        }
Exemple #39
0
        public void ShouldCreateTestTreeAndReadDefaultDatabase()
        {
            // Arrange
              using (var tree = new TTree("master"))
              {
            // Act
            Database database = tree.Database;

            // Assert
            database.Name.Should().Be("master");
              }
        }
Exemple #40
0
        public void ShouldCreateTestTreeAndReadDefaultHomeItem()
        {
            // Arrange
              using (var tree = new TTree())
              {
            // Act
            var home = tree.Database.GetItem("/sitecore/content/home");

            // Assert
            home.Name.Should().Be("home");
              }
        }
Exemple #41
0
        public void ShouldCreateTestTreeAndReadTestItem()
        {
            // Arrange
              using (var tree = new TTree { new TItem("Sample") { { "Title", "Sample item" } } })
              {
            // Act
            var result = tree.Database.GetItem("/sitecore/content/home/sample");

            // Assert
            result.Should().NotBeNull();
            result["Title"].Should().Be("Sample item");
              }
        }
Exemple #42
0
        public void ShouldCreateTestTreeWithCustomDatabase()
        {
            // Arrange
              using (var tree = new TTree("core"))
              {
            // Act
            Database database = tree.Database;

            // Assert
            database.Name.Should().Be("core");
              }
        }
Exemple #43
0
        public void TestPath()
        {
            using (var tree = new TTree("master") { new TTemplate(TemplateIDs.Folder) })
              {
            tree.Database.GetItem("/sitecore/system/").Add("publishing targets", new TemplateID(TemplateIDs.Folder));

            tree.Database.GetItem("/sitecore/System/publishing targets").Paths.FullPath.Should().Be("/sitecore/System/publishing targets");
              }
        }