Beispiel #1
0
        public FakeTemplate(string templateName = null, ID templateId = null, Database database = null, TemplateEngine engine = null)
        {
            string   name = string.IsNullOrEmpty(templateName) ? "fakeTemplate" : templateName;
            ID       id   = templateId ?? ID.NewID;
            Database db   = database ?? FakeUtil.FakeDatabase();

            this.Database = db;

            templateEngine  = engine ?? Substitute.For <TemplateEngine>(db);
            templateBuilder = new Template.Builder(name, id, templateEngine);
            templateBuilder.SetName(name);
            templateBuilder.SetID(id);

            templateEngine.GetTemplate(id).Returns(this);
            templateEngine.GetTemplate(name).Returns(this);
        }
Beispiel #2
0
        /// <summary>
        /// Initializes a new instance of <see cref="FakeItem"/> optionally providing item <paramref name="id"/> and <paramref name="database"/>.
        /// <para>Sets <see cref="Data.Items.Item.Language"/> (to <see cref="Language.Invariant"/>) and <see cref="Data.Items.Item.Version"/> (to <see cref="Version.First"/>).</para>
        /// <para>Fakes <see cref="Data.Items.Item.Paths"/>, <see cref="Data.Items.Item.Fields"/>, and <see cref="Data.Items.Item.Children"/> out-of-the-box.</para>
        /// <para>Configures <paramref name="database"/> to return this instance for GetItem calls.</para>
        /// </summary>
        /// <param name="id">The optional item id to use; otherwise random <see cref="Sitecore.Data.ID"/> is picked.</param>
        /// <param name="database">The optional database item belongs to; otherwise random <see cref="Database"/> is set as item owner.</param>
        public FakeItem(ID id = null, Database database = null)
        {
            Item = FakeUtil.FakeItem(id ?? ID.NewID, "fakeItem", database ?? FakeUtil.FakeDatabase());
            FakeUtil.FakeItemFields(Item);
            FakeUtil.FakeItemPath(Item);

            var templateItem = Substitute.For <TemplateItem>(Item);

            Item.Template.Returns(templateItem);
            Item.Language.Returns(Globalization.Language.Invariant);
            Item.Version.Returns(Version.First);

            Item.Children.Returns(Substitute.For <ChildList>(Item, childList));
            Item.GetChildren(Arg.Any <ChildListOptions>()).Returns(Substitute.For <ChildList>(Item, childList));
            Item.GetChildren().Returns(Substitute.For <ChildList>(Item, childList));
            Item.HasChildren.Returns(o => childList.Count > 0);
            Item.Database.GetItem(Item.ID).Returns(Item);
            Item.Database.GetItem(Item.ID.ToString()).Returns(Item);
            Item.Database.GetItem(Item.ID, Item.Language, Item.Version).Returns(Item);
            Item.Database.GetItem(Item.ID, Item.Language).Returns(Item);
        }
Beispiel #3
0
 public FakeItem WithSourceUri() => WithSourceUri(FakeUtil.FakeItemUri());
Beispiel #4
0
 public FakeItem WithItemAccess()
 {
     FakeUtil.FakeItemAccess(Item);
     return(this);
 }
 public FakeItem WithSourceUri()
 {
     return(this.WithSourceUri(FakeUtil.FakeItemUri()));
 }
Beispiel #6
0
 public static Item FakeItem(string name)
 {
     return(FakeItem(name, FakeUtil.FakeDatabase()));
 }