예제 #1
1
    public void HowToMockAuthorizationProvider()
    {
      // create sample user
      var user = Sitecore.Security.Accounts.User.FromName(@"extranet\John", true);

      using (Sitecore.FakeDb.Db db = new Sitecore.FakeDb.Db
        {
          new Sitecore.FakeDb.DbItem("home")
        })
      {
        Sitecore.Data.Items.Item home = db.GetItem("/sitecore/content/home");

        // configure authorization provider mock to deny item read for the user
        var provider =
          Substitute.For<Sitecore.Security.AccessControl.AuthorizationProvider>();

        provider
          .GetAccess(home, user, Sitecore.Security.AccessControl.AccessRight.ItemRead)
          .Returns(new Sitecore.FakeDb.Security.AccessControl.DenyAccessResult());

        // switch the authorization provider
        using (new Sitecore.FakeDb.Security.AccessControl.AuthorizationSwitcher(provider))
        {
          // check the user cannot read the item
          bool canRead =
            Sitecore.Security.AccessControl.AuthorizationManager.IsAllowed(
              home,
              Sitecore.Security.AccessControl.AccessRight.ItemRead,
              user);

          Xunit.Assert.False(canRead);
        }
      }
    }
        public void HowToSetAndGetBlobStream()
        {
            // arrange
            var stream = new System.IO.MemoryStream();

            using (Sitecore.FakeDb.Db db = new Sitecore.FakeDb.Db
            {
                new Sitecore.FakeDb.DbItem("home")
                {
                    new Sitecore.FakeDb.DbField("field")
                }
            })
            {
                Sitecore.Data.Items.Item   item  = db.GetItem("/sitecore/content/home");
                Sitecore.Data.Fields.Field field = item.Fields["field"];

                using (new Sitecore.Data.Items.EditContext(item))
                {
                    // act
                    field.SetBlobStream(stream);
                }

                // assert
                Xunit.Assert.Equal(stream.ToArray(),
                                   ((System.IO.MemoryStream)field.GetBlobStream()).ToArray());
            }
        }
        public void HowToMockContentSearchLogic()
        {
            var index = Substitute.For <Sitecore.ContentSearch.ISearchIndex>();

            // don't forget to clean up.
            Sitecore.ContentSearch
            .ContentSearchManager.SearchConfiguration.Indexes["my_index"] = index;

            using (Sitecore.FakeDb.Db db = new Sitecore.FakeDb.Db
            {
                new Sitecore.FakeDb.DbItem("home")
            })
            {
                // configure a search result item behavior.
                var searchResultItem =
                    Substitute.For <Sitecore.ContentSearch.SearchTypes.SearchResultItem>();

                var expectedItem = db.GetItem("/sitecore/content/home");
                searchResultItem.GetItem().Returns(expectedItem);

                // configure a search ndex behavior.
                index.CreateSearchContext()
                .GetQueryable <Sitecore.ContentSearch.SearchTypes.SearchResultItem>()
                .Returns((new[] { searchResultItem }).AsQueryable());

                // get the item from the search index and check the expectations.
                Sitecore.Data.Items.Item actualItem =
                    index.CreateSearchContext()
                    .GetQueryable <Sitecore.ContentSearch.SearchTypes.SearchResultItem>()
                    .Single()
                    .GetItem();

                Xunit.Assert.Equal(expectedItem, actualItem);
            }
        }
        public void HowToMockAuthorizationProvider()
        {
            // create sample user
            var user = Sitecore.Security.Accounts.User.FromName(@"extranet\John", true);

            using (Sitecore.FakeDb.Db db = new Sitecore.FakeDb.Db
            {
                new Sitecore.FakeDb.DbItem("home")
            })
            {
                Sitecore.Data.Items.Item home = db.GetItem("/sitecore/content/home");

                // configure authorization provider mock to deny item read for the user
                var provider =
                    Substitute.For <Sitecore.Security.AccessControl.AuthorizationProvider>();

                provider
                .GetAccess(home, user, Sitecore.Security.AccessControl.AccessRight.ItemRead)
                .Returns(new Sitecore.FakeDb.Security.AccessControl.DenyAccessResult());

                // switch the authorization provider
                using (new Sitecore.FakeDb.Security.AccessControl.AuthorizationSwitcher(provider))
                {
                    // check the user cannot read the item
                    bool canRead =
                        Sitecore.Security.AccessControl.AuthorizationManager.IsAllowed(
                            home,
                            Sitecore.Security.AccessControl.AccessRight.ItemRead,
                            user);

                    Xunit.Assert.False(canRead);
                }
            }
        }
        public void HowToUnitTestItemSecurityWithFakeProvider()
        {
            // create sample item
            using (Sitecore.FakeDb.Db db = new Sitecore.FakeDb.Db
            {
                new Sitecore.FakeDb.DbItem("home")
            })
            {
                Sitecore.Data.Items.Item home = db.GetItem("/sitecore/content/home");

                // call your business logic that changes the item security, e.g. denies Read
                // for Editors
                var account         = Sitecore.Security.Accounts.Role.FromName(@"sitecore\Editors");
                var accessRight     = Sitecore.Security.AccessControl.AccessRight.ItemRead;
                var propagationType = Sitecore.Security.AccessControl.PropagationType.Entity;
                var permission      = Sitecore.Security.AccessControl.AccessPermission.Deny;

                Sitecore.Security.AccessControl.AccessRuleCollection rules =
                    new Sitecore.Security.AccessControl.AccessRuleCollection
                {
                    Sitecore.Security.AccessControl.AccessRule.Create
                        (account, accessRight, propagationType, permission)
                };
                Sitecore.Security.AccessControl.AuthorizationManager.SetAccessRules(home, rules);

                // check the account cannot read the item
                Xunit.Assert.False(home.Security.CanRead(account));
            }
        }
        public void HowToMockMediaItemProvider()
        {
            const string MyImageUrl = "~/media/myimage.ashx";

            Sitecore.Data.ID mediaItemId = Sitecore.Data.ID.NewID;

            // create some media item. Location, fields and template are not important
            using (Sitecore.FakeDb.Db db = new Sitecore.FakeDb.Db
            {
                new Sitecore.FakeDb.DbItem("my-image", mediaItemId)
            })
            {
                Sitecore.Data.Items.Item mediaItem = db.GetItem(mediaItemId);

                // create media provider mock and configure behaviour
                Sitecore.Resources.Media.MediaProvider mediaProvider =
                    NSubstitute.Substitute.For <Sitecore.Resources.Media.MediaProvider>();

                mediaProvider
                .GetMediaUrl(Arg.Is <Sitecore.Data.Items.MediaItem>(i => i.ID == mediaItemId))
                .Returns(MyImageUrl);

                // substitute the original provider with the mocked one
                using (new Sitecore.FakeDb.Resources.Media.MediaProviderSwitcher(mediaProvider))
                {
                    string mediaUrl = Sitecore.Resources.Media.MediaManager.GetMediaUrl(mediaItem);
                    Xunit.Assert.Equal(MyImageUrl, mediaUrl);
                }
            }
        }
        public void HowToCreateTemplateHierarchy()
        {
            var baseTemplateIdOne = Sitecore.Data.ID.NewID;
            var baseTemplateIdTwo = Sitecore.Data.ID.NewID;
            var templateId        = Sitecore.Data.ID.NewID;

            using (Sitecore.FakeDb.Db db = new Sitecore.FakeDb.Db
            {
                new Sitecore.FakeDb.DbTemplate("base one", baseTemplateIdOne),
                new Sitecore.FakeDb.DbTemplate("base two", baseTemplateIdTwo),
                new Sitecore.FakeDb.DbTemplate("Main", templateId)
                {
                    BaseIDs = new[] { baseTemplateIdOne, baseTemplateIdTwo }
                }
            })
            {
                var template =
                    Sitecore.Data.Managers.TemplateManager.GetTemplate(templateId, db.Database);

                Xunit.Assert.Contains(baseTemplateIdOne, template.BaseIDs);
                Xunit.Assert.Contains(baseTemplateIdTwo, template.BaseIDs);

                Xunit.Assert.True(template.InheritsFrom(baseTemplateIdOne));
                Xunit.Assert.True(template.InheritsFrom(baseTemplateIdTwo));
            }
        }
        public void HowToSwitchLinkProvider()
        {
            // arrange
            using (Sitecore.FakeDb.Db db = new Sitecore.FakeDb.Db
            {
                new Sitecore.FakeDb.DbItem("home")
            })
            {
                Sitecore.Data.Items.Item home = db.GetItem("/sitecore/content/home");

                Sitecore.Links.LinkProvider provider = Substitute.For <Sitecore.Links.LinkProvider>();
                provider.GetItemUrl(home, Arg.Is <Sitecore.Links.UrlOptions>(x => x.AlwaysIncludeServerUrl))
                .Returns("http://myawesomeurl.com");

                using (new Sitecore.FakeDb.Links.LinkProviderSwitcher(provider))
                {
                    // act
                    var result = Sitecore.Links.LinkManager.GetItemUrl(home,
                                                                       new Sitecore.Links.UrlOptions {
                        AlwaysIncludeServerUrl = true
                    });

                    // assert
                    Xunit.Assert.Equal("http://myawesomeurl.com", result);
                }
            }
        }
예제 #9
0
 public void HowToCreateSimpleItem()
 {
   using (Sitecore.FakeDb.Db db = new Sitecore.FakeDb.Db
     {
       new Sitecore.FakeDb.DbItem("Home") { { "Title", "Welcome!" } }
     })
   {
     Sitecore.Data.Items.Item home = db.GetItem("/sitecore/content/home");
     Xunit.Assert.Equal("Welcome!", home["Title"]);
   }
 }
 public void HowToCreateItemUnderSystem()
 {
   using (Sitecore.FakeDb.Db db = new Sitecore.FakeDb.Db
     {
       new Sitecore.FakeDb.DbItem("Home") { ParentID = Sitecore.ItemIDs.SystemRoot }
     })
   {
     Sitecore.Data.Items.Item home = db.GetItem("/sitecore/system/home");
     Xunit.Assert.Equal("home", home.Key);
   }
 }
 public void HowToCreateSimpleItem()
 {
   using (Sitecore.FakeDb.Db db = new Sitecore.FakeDb.Db
     {
       new Sitecore.FakeDb.DbItem("Home") { { "Title", "Welcome!" } }
     })
   {
     Sitecore.Data.Items.Item home = db.GetItem("/sitecore/content/home");
     Xunit.Assert.Equal("Welcome!", home["Title"]);
   }
 }
예제 #12
0
 public void HowToCreateItemUnderSystem()
 {
   using (Sitecore.FakeDb.Db db = new Sitecore.FakeDb.Db
     {
       new Sitecore.FakeDb.DbItem("Home") { ParentID = Sitecore.ItemIDs.SystemRoot }
     })
   {
     Sitecore.Data.Items.Item home = db.GetItem("/sitecore/system/home");
     Xunit.Assert.Equal("home", home.Key);
   }
 }
        public void HowToConfigureSettings()
        {
            using (Sitecore.FakeDb.Db db = new Sitecore.FakeDb.Db())
            {
                // set the setting value in unit test using db instance
                db.Configuration.Settings["MySetting"] = "1234";

                // get the setting value in your code using regular Sitecore API
                var value = Sitecore.Configuration.Settings.GetSetting("MySetting");
                Xunit.Assert.Equal("1234", value);
            }
        }
예제 #14
0
        public void HowToWorkWithLinkDatabase()
        {
            // arrange your database and items
            Sitecore.Data.ID sourceId     = Sitecore.Data.ID.NewID;
            Sitecore.Data.ID aliasId      = Sitecore.Data.ID.NewID;
            Sitecore.Data.ID linkedItemId = Sitecore.Data.ID.NewID;

            using (Sitecore.FakeDb.Db db = new Sitecore.FakeDb.Db
            {
                new Sitecore.FakeDb.DbItem("source", sourceId),
                new Sitecore.FakeDb.DbItem("clone"),
                new Sitecore.FakeDb.DbItem("alias", aliasId, Sitecore.TemplateIDs.Alias)
                {
                    new Sitecore.FakeDb.DbField("Linked item", linkedItemId)
                }
            })
            {
                // arrange desired LinkDatabase behavior
                var behavior = Substitute.For <Sitecore.Links.LinkDatabase>();

                Sitecore.Data.Items.Item source = db.GetItem("/sitecore/content/source");
                Sitecore.Data.Items.Item alias  = db.GetItem("/sitecore/content/alias");
                Sitecore.Data.Items.Item clone  = db.GetItem("/sitecore/content/clone");

                string sourcePath = source.Paths.FullPath;
                behavior.GetReferrers(source).Returns(new[]
                {
                    new Sitecore.Links.ItemLink(alias, linkedItemId, source, sourcePath),
                    new Sitecore.Links.ItemLink(clone, Sitecore.FieldIDs.Source, source, sourcePath)
                });

                // link database is clean
                Xunit.Assert.Empty(Sitecore.Globals.LinkDatabase.GetReferrers(source));

                using (new Sitecore.FakeDb.Links.LinkDatabaseSwitcher(behavior))
                {
                    Sitecore.Links.ItemLink[] referrers =
                        Sitecore.Globals.LinkDatabase.GetReferrers(source);

                    const int expected = 2;
                    Xunit.Assert.Equal(referrers.Count(), expected);
                    Xunit.Assert.Single(referrers.Where(r => r.SourceItemID == clone.ID &&
                                                        r.TargetItemID == source.ID));
                    Xunit.Assert.Single(referrers.Where(r => r.SourceItemID == alias.ID &&
                                                        r.TargetItemID == source.ID));
                }

                // link database is clean again
                Xunit.Assert.Empty(Sitecore.Globals.LinkDatabase.GetReferrers(source));
            }
        }
예제 #15
0
 public void HowToDeserializeItem()
 {
   using (Sitecore.FakeDb.Db db = new Sitecore.FakeDb.Db
     {
       new Sitecore.FakeDb.Serialization.DsDbTemplate(
         "/sitecore/templates/Sample/Sample Item"),
       new Sitecore.FakeDb.Serialization.DsDbItem(
         "/sitecore/content/home", true)
     })
   {
     var home = db.GetItem("/sitecore/content/home");
     Assert.Equal("Sitecore", home["Title"]);
   }
 }
    public void HowToConfigureItemAccess()
    {
      using (Sitecore.FakeDb.Db db = new Sitecore.FakeDb.Db
        {
          // set Access.CanRead to False
          new Sitecore.FakeDb.DbItem("home") { Access = { CanRead = false } }
        })
      {
        Sitecore.Data.Items.Item item = db.GetItem("/sitecore/content/home");

        // item is null because read is denied
        Xunit.Assert.Null(item);
      }
    }
        public void HowToWorkWithFastQueryApi()
        {
            const string Query = "fast:/sitecore/content/*[@@key = 'home']";

            using (Sitecore.FakeDb.Db db = new Sitecore.FakeDb.Db
            {
                new Sitecore.FakeDb.DbItem("home")
            })
            {
                Sitecore.Data.Items.Item homeItem = db.Database.SelectSingleItem(Query);

                Xunit.Assert.Equal(homeItem.Key, "home");
            }
        }
 public void HowToDeserializeItem()
 {
     using (Sitecore.FakeDb.Db db = new Sitecore.FakeDb.Db
     {
         new Sitecore.FakeDb.Serialization.DsDbTemplate(
             "/sitecore/templates/Sample/Sample Item"),
         new Sitecore.FakeDb.Serialization.DsDbItem(
             "/sitecore/content/home", true)
     })
     {
         var home = db.GetItem("/sitecore/content/home");
         Assert.Equal("Sitecore", home["Title"]);
     }
 }
예제 #19
0
    public void HowDoICreateAnItemOfSpecificTemplate()
    {
      Sitecore.Data.ID templateId = Sitecore.Data.ID.NewID;

      using (Sitecore.FakeDb.Db db = new Sitecore.FakeDb.Db
        {
          new Sitecore.FakeDb.DbTemplate("products", templateId) { "Name" },
          new Sitecore.FakeDb.DbItem("Apple") { TemplateID = templateId }
        })
      {
        Sitecore.Data.Items.Item item = db.GetItem("/sitecore/content/apple");
        Assert.Equal(templateId, item.TemplateID);
        Assert.NotNull(item.Fields["Name"]);
      }
    }
    public void HowToCreateItemWithSpecificTemplate()
    {
      Sitecore.Data.ID templateId = Sitecore.Data.ID.NewID;

      using (Sitecore.FakeDb.Db db = new Sitecore.FakeDb.Db
        {
          new Sitecore.FakeDb.DbTemplate("products", templateId) { "Name" },
          new Sitecore.FakeDb.DbItem("Apple") { TemplateID = templateId }
        })
      {
        Sitecore.Data.Items.Item item = db.GetItem("/sitecore/content/apple");

        Xunit.Assert.Equal(templateId, item.TemplateID);
        Xunit.Assert.NotNull(item.Fields["Name"]);
      }
    }
예제 #21
0
 public void HowDoICreateAnItemHierarchy()
 {
   using (Sitecore.FakeDb.Db db = new Sitecore.FakeDb.Db
     {
       new Sitecore.FakeDb.DbItem("Articles")
         {
           new Sitecore.FakeDb.DbItem("Getting Started"),
           new Sitecore.FakeDb.DbItem("Troubleshooting")
         }
     })
   {
     Sitecore.Data.Items.Item articles = db.GetItem("/sitecore/content/Articles");
     Assert.NotNull(articles["Getting Started"]);
     Assert.NotNull(articles["Troubleshooting"]);
   }
 }
    public void HowToCreateMultilingualItem()
    {
      using (Sitecore.FakeDb.Db db = new Sitecore.FakeDb.Db
        {
          new Sitecore.FakeDb.DbItem("home")
            {
              new Sitecore.FakeDb.DbField("Title") { { "en", "Hello!" }, { "da", "Hej!" } }
            }
        })
      {
        Sitecore.Data.Items.Item homeEn = db.GetItem("/sitecore/content/home", "en");
        Xunit.Assert.Equal("Hello!", homeEn["Title"]);

        Sitecore.Data.Items.Item homeDa = db.GetItem("/sitecore/content/home", "da");
        Xunit.Assert.Equal("Hej!", homeDa["Title"]);
      }
    }
        public void HowToUnitTestPipelineCallWithMockedProcessor()
        {
            var args = new Sitecore.Pipelines.PipelineArgs();

            using (Sitecore.FakeDb.Db db = new Sitecore.FakeDb.Db())
            {
                // create pipeline processor mock and register it in the Pipeline Watcher
                var processor = Substitute.For <Sitecore.FakeDb.Pipelines.IPipelineProcessor>();
                db.PipelineWatcher.Register("mypipeline", processor);

                // call the pipeline
                Sitecore.Pipelines.CorePipeline.Run("mypipeline", args);

                // and check the mocked processor received the Process method call with proper arguments
                processor.Received().Process(args);
            }
        }
        public void HowToCreateItemHierarchy()
        {
            using (Sitecore.FakeDb.Db db = new Sitecore.FakeDb.Db
            {
                new Sitecore.FakeDb.DbItem("Articles")
                {
                    new Sitecore.FakeDb.DbItem("Getting Started"),
                    new Sitecore.FakeDb.DbItem("Troubleshooting")
                }
            })
            {
                Sitecore.Data.Items.Item articles = db.GetItem("/sitecore/content/Articles");

                Xunit.Assert.NotNull(articles.Children["Getting Started"]);
                Xunit.Assert.NotNull(articles.Children["Troubleshooting"]);
            }
        }
예제 #25
0
    public void HowToCreateMultilingualItem()
    {
      using (Sitecore.FakeDb.Db db = new Sitecore.FakeDb.Db
        {
          new Sitecore.FakeDb.DbItem("home")
            {
              new Sitecore.FakeDb.DbField("Title") { { "en", "Hello!" }, { "da", "Hej!" } }
            }
        })
      {
        Sitecore.Data.Items.Item homeEn = db.GetItem("/sitecore/content/home", "en");
        Xunit.Assert.Equal("Hello!", homeEn["Title"]);

        Sitecore.Data.Items.Item homeDa = db.GetItem("/sitecore/content/home", "da");
        Xunit.Assert.Equal("Hej!", homeDa["Title"]);
      }
    }
예제 #26
0
        public void HowToUnitTestItemSecurityWithMockedProvider()
        {
            // create sample item
            using (Sitecore.FakeDb.Db db = new Sitecore.FakeDb.Db
            {
                new Sitecore.FakeDb.DbItem("home")
            })
            {
                Sitecore.Data.Items.Item home = db.GetItem("/sitecore/content/home");

                // substitute the authorization provider
                var provider =
                    Substitute.For <Sitecore.Security.AccessControl.AuthorizationProvider>();

#pragma warning disable 618
                using (new Sitecore.FakeDb.Security.AccessControl.AuthorizationSwitcher(provider))
#pragma warning restore 618
                {
                    // call your business logic that changes the item security, e.g. denies Read
                    // for Editors
                    var account         = Sitecore.Security.Accounts.Role.FromName(@"sitecore\Editors");
                    var accessRight     = Sitecore.Security.AccessControl.AccessRight.ItemRead;
                    var propagationType = Sitecore.Security.AccessControl.PropagationType.Entity;
                    var permission      = Sitecore.Security.AccessControl.AccessPermission.Deny;

                    Sitecore.Security.AccessControl.AccessRuleCollection rules =
                        new Sitecore.Security.AccessControl.AccessRuleCollection
                    {
                        Sitecore.Security.AccessControl.AccessRule.Create
                            (account, accessRight, propagationType, permission)
                    };
                    Sitecore.Security.AccessControl.AuthorizationManager.SetAccessRules(home, rules);

                    // check the provider is called with proper arguments
                    provider
                    .Received()
                    .SetAccessRules(
                        home,
                        NSubstitute.Arg.Is <Sitecore.Security.AccessControl.AccessRuleCollection>(
                            r => r[0].Account.Name == @"sitecore\Editors" &&
                            r[0].AccessRight.Name == "item:read" &&
                            r[0].PropagationType.ToString() == "Entity" &&
                            r[0].SecurityPermission.ToString() == "DenyAccess"));
                }
            }
        }
        public void HowToUnitTestPipelineCall()
        {
            using (Sitecore.FakeDb.Db db = new Sitecore.FakeDb.Db())
            {
                // configure a pipeline watcher to expect the "createProduct" pipeline call with
                // product name passed to the arguments custom data
                db.PipelineWatcher
                .Expects("createProduct", a => a.CustomData["ProductName"].Equals("MyProduct"));

                // create a repository and call the create product method
                var repository = new ProductRepository();
                repository.CreateProduct("MyProduct");

                // assert the expected pipeline is called and the product name is passed
                db.PipelineWatcher.EnsureExpectations();
            }
        }
        public void HowToCreateLinkFieldUsingRawValue()
        {
            using (Sitecore.FakeDb.Db db = new Sitecore.FakeDb.Db
            {
                new Sitecore.FakeDb.DbItem("home")
                {
                    { "link", "<link linktype=\"external\" url=\"http://google.com\" />" }
                }
            })
            {
                var item = db.GetItem("/sitecore/content/home");

                var linkField = (Sitecore.Data.Fields.LinkField)item.Fields["link"];

                Xunit.Assert.Equal("external", linkField.LinkType);
                Xunit.Assert.Equal("http://google.com", linkField.Url);
            }
        }
        public void HowToCheckTranslateTextIsCalled()
        {
            const string Phrase = "Welcome!";

            // Enable the 'FakeDb.AutoTranslate' setting.
            // It can be done either statically in the 'App.config' file or
            // dynamically in a particular test.
            using (Sitecore.FakeDb.Db db = new Sitecore.FakeDb.Db())
            {
                db.Configuration.Settings.AutoTranslate = true;

                // translate
                string translatedPhrase = Sitecore.Globalization.Translate.Text(Phrase);

                // note the '*' symbol at the end of the translated phrase
                Xunit.Assert.Equal("Welcome!*", translatedPhrase);
            }
        }
    public void HowToCreateTemplateWithStandardValues()
    {
      var templateId = new Sitecore.Data.TemplateID(Sitecore.Data.ID.NewID);

      using (Sitecore.FakeDb.Db db = new Sitecore.FakeDb.Db
        {
          // create template with field Title and standard value $name
          new Sitecore.FakeDb.DbTemplate("Sample", templateId) { { "Title", "$name" } }
        })
      {
        // add item based on the template to the content root
        Sitecore.Data.Items.Item contentRoot = db.GetItem(Sitecore.ItemIDs.ContentRoot);
        Sitecore.Data.Items.Item item = contentRoot.Add("Home", templateId);

        // the Title field is set to 'Home'
        Xunit.Assert.Equal("Home", item["Title"]);
      }
    }
        public void HowToUnitTestLocalization()
        {
            // init languages
            Sitecore.Globalization.Language en = Sitecore.Globalization.Language.Parse("en");
            Sitecore.Globalization.Language da = Sitecore.Globalization.Language.Parse("da");

            const string Phrase = "Welcome!";

            using (Sitecore.FakeDb.Db db = new Sitecore.FakeDb.Db())
            {
                db.Configuration.Settings.AutoTranslate       = true;
                db.Configuration.Settings.AutoTranslatePrefix = "{lang}:";

                // translate
                string enTranslation = Sitecore.Globalization.Translate.TextByLanguage(Phrase, en);
                string daTranslation = Sitecore.Globalization.Translate.TextByLanguage(Phrase, da);

                Xunit.Assert.Equal("en:Welcome!", enTranslation);
                Xunit.Assert.Equal("da:Welcome!", daTranslation);
            }
        }
        public void HowToCreateLinkFieldUsingDbLinkField()
        {
            using (Sitecore.FakeDb.Db db = new Sitecore.FakeDb.Db
            {
                new Sitecore.FakeDb.DbItem("home")
                {
                    new Sitecore.FakeDb.DbLinkField("link")
                    {
                        LinkType = "external", Url = "http://google.com"
                    }
                }
            })
            {
                var item = db.GetItem("/sitecore/content/home");

                var linkField = (Sitecore.Data.Fields.LinkField)item.Fields["link"];

                Xunit.Assert.Equal("external", linkField.LinkType);
                Xunit.Assert.Equal("http://google.com", linkField.Url);
            }
        }
        public void HowToCreateVersionedItem()
        {
            using (Sitecore.FakeDb.Db db = new Sitecore.FakeDb.Db
            {
                new Sitecore.FakeDb.DbItem("home")
                {
                    new Sitecore.FakeDb.DbField("Title")
                    {
                        { "en", 1, "Hello!" },
                        { "en", 2, "Welcome!" }
                    }
                }
            })
            {
                Sitecore.Data.Items.Item home1 = db.GetItem("/sitecore/content/home", "en", 1);
                Xunit.Assert.Equal("Hello!", home1["Title"]);

                Sitecore.Data.Items.Item home2 = db.GetItem("/sitecore/content/home", "en", 2);
                Xunit.Assert.Equal("Welcome!", home2["Title"]);
            }
        }
        public void HowToUnitTestAdvancedPipelineCallWithMockedProcessor()
        {
            var args = new Sitecore.Pipelines.PipelineArgs();

            using (Sitecore.FakeDb.Db db = new Sitecore.FakeDb.Db())
            {
                // create pipeline processor mock and register it in the Pipeline Watcher
                var processor = Substitute.For <Sitecore.FakeDb.Pipelines.IPipelineProcessor>();
                processor
                .When(p => p.Process(args))
                .Do(ci => ci.Arg <Sitecore.Pipelines.PipelineArgs>().CustomData["Result"] = "Ok");

                db.PipelineWatcher.Register("mypipeline", processor);

                // call the pipeline
                Sitecore.Pipelines.CorePipeline.Run("mypipeline", args);

                // and check the result
                Assert.Equal("Ok", args.CustomData["Result"]);
            }
        }
        public void HowToConfigurePipelineBehaviour()
        {
            using (Sitecore.FakeDb.Db db = new Sitecore.FakeDb.Db())
            {
                // create a product to get from the repository
                object expectedProduct = new object();
                string productId       = "1";

                // configure Pipeline Watcher to expect a pipeline call where the args Custom Data
                // contains ProductId equals "1". Once the args received the pipeline result is set
                // to the Product Custom Data property
                db.PipelineWatcher
                .WhenCall("findProductById")
                .WithArgs(a => a.CustomData["ProductId"].Equals(productId))
                .Then(a => a.CustomData["Product"] = expectedProduct);

                // create a repository and call get product method
                ProductRepository repository = new ProductRepository();
                var actualProduct            = repository.GetProductById(productId);

                // assert the received product is the same as the expected one
                Xunit.Assert.Equal(expectedProduct, actualProduct);
            }
        }
예제 #36
0
    public void HowToConfigureSettings()
    {
      using (Sitecore.FakeDb.Db db = new Sitecore.FakeDb.Db())
      {
        // set the setting value in unit test using db instance
        db.Configuration.Settings["MySetting"] = "1234";

        // get the setting value in your code using regular Sitecore API
        var value = Sitecore.Configuration.Settings.GetSetting("MySetting");
        Xunit.Assert.Equal("1234", value);
      }
    }
예제 #37
0
    public void HowDoICreateATemplateWithStandardValues()
    {
      var templateId = Sitecore.Data.ID.NewID;

      using (Sitecore.FakeDb.Db db = new Sitecore.FakeDb.Db
        {
          new Sitecore.FakeDb.DbTemplate("sample", templateId) { { "Title", "$name"} }
        })
      {
        var root = db.GetItem(Sitecore.ItemIDs.ContentRoot);
        var item = Sitecore.Data.Managers.ItemManager.CreateItem("Home", root, templateId);
        Assert.Equal("Home", item["Title"]);
      }
    }
예제 #38
0
    public void HowToUnitTestPipelineCall()
    {
      using (Sitecore.FakeDb.Db db = new Sitecore.FakeDb.Db())
      {
        // configure a pipeline watcher to expect the "createProduct" pipeline call with
        // product name passed to the arguments custom data
        db.PipelineWatcher
          .Expects("createProduct", a => a.CustomData["ProductName"].Equals("MyProduct"));

        // create a repository and call the create product method
        var repository = new ProductRepository();
        repository.CreateProduct("MyProduct");

        // assert the expected pipeline is called and the product name is passed
        db.PipelineWatcher.EnsureExpectations();
      }
    }
예제 #39
0
    public void HowToConfigurePipelineBehaviour()
    {
      using (Sitecore.FakeDb.Db db = new Sitecore.FakeDb.Db())
      {
        // create a product to get from the repository
        object expectedProduct = new object();
        string productId = "1";

        // configure Pipeline Watcher to expect a pipeline call where the args Custom Data
        // contains ProductId equals "1". Once the args received the pipeline result is set
        // to the Product Custom Data property
        db.PipelineWatcher
          .WhenCall("findProductById")
          .WithArgs(a => a.CustomData["ProductId"].Equals(productId))
          .Then(a => a.CustomData["Product"] = expectedProduct);

        // create a repository and call get product method
        ProductRepository repository = new ProductRepository();
        var actualProduct = repository.GetProductById(productId);

        // assert the received product is the same as the expected one
        Xunit.Assert.Equal(expectedProduct, actualProduct);
      }
    }
예제 #40
0
    public void HowToCreateVersionedItem()
    {
      using (Sitecore.FakeDb.Db db = new Sitecore.FakeDb.Db
        {
          new Sitecore.FakeDb.DbItem("home")
            {
              new Sitecore.FakeDb.DbField("Title")
                {
                  { "en", 1, "Hello!" },
                  { "en", 2, "Welcome!" }
                }
            }
        })
      {
        Sitecore.Data.Items.Item home1 = db.GetItem("/sitecore/content/home", "en", 1);
        Xunit.Assert.Equal("Hello!", home1["Title"]);

        Sitecore.Data.Items.Item home2 = db.GetItem("/sitecore/content/home", "en", 2);
        Xunit.Assert.Equal("Welcome!", home2["Title"]);
      }
    }
예제 #41
0
    public void HowToCreateTemplateWithStandardValues()
    {
      var templateId = new Sitecore.Data.TemplateID(Sitecore.Data.ID.NewID);

      using (Sitecore.FakeDb.Db db = new Sitecore.FakeDb.Db
        {
          // create template with field Title and standard value $name
          new Sitecore.FakeDb.DbTemplate("Sample", templateId) { { "Title", "$name" } }
        })
      {
        // add item based on the template to the content root
        Sitecore.Data.Items.Item contentRoot = db.GetItem(Sitecore.ItemIDs.ContentRoot);
        Sitecore.Data.Items.Item item = contentRoot.Add("Home", templateId);

        // the Title field is set to 'Home'
        Xunit.Assert.Equal("Home", item["Title"]);
      }
    }
예제 #42
0
    public void HowToMockContentSearchLogic()
    {
      var index = Substitute.For<Sitecore.ContentSearch.ISearchIndex>();

      // don't forget to clean up.
      Sitecore.ContentSearch
        .ContentSearchManager.SearchConfiguration.Indexes["my_index"] = index;

      using (Sitecore.FakeDb.Db db = new Sitecore.FakeDb.Db
        {
          new Sitecore.FakeDb.DbItem("home")
        })
      {
        // configure a search result item behavior.
        var searchResultItem =
          Substitute.For<Sitecore.ContentSearch.SearchTypes.SearchResultItem>();

        var expectedItem = db.GetItem("/sitecore/content/home");
        searchResultItem.GetItem().Returns(expectedItem);

        // configure a search ndex behavior.
        index.CreateSearchContext()
          .GetQueryable<Sitecore.ContentSearch.SearchTypes.SearchResultItem>()
          .Returns((new[] { searchResultItem }).AsQueryable());

        // get the item from the search index and check the expectations.
        Sitecore.Data.Items.Item actualItem =
          index.CreateSearchContext()
            .GetQueryable<Sitecore.ContentSearch.SearchTypes.SearchResultItem>()
            .Single()
            .GetItem();

        Xunit.Assert.Equal(expectedItem, actualItem);
      }
    }
예제 #43
0
    public void HowToCheckTranslateTextIsCalled()
    {
      const string Phrase = "Welcome!";

      // Enable the 'FakeDb.AutoTranslate' setting.
      // It can be done either statically in the 'App.config' file or 
      // dynamically in a particular test.
      using (Sitecore.FakeDb.Db db = new Sitecore.FakeDb.Db())
      {
        db.Configuration.Settings.AutoTranslate = true;

        // translate
        string translatedPhrase = Sitecore.Globalization.Translate.Text(Phrase);

        // note the '*' symbol at the end of the translated phrase
        Xunit.Assert.Equal("Welcome!*", translatedPhrase);
      }
    }
예제 #44
0
    public void HowToMockMediaItemProvider()
    {
      const string MyImageUrl = "~/media/myimage.ashx";
      Sitecore.Data.ID mediaItemId = Sitecore.Data.ID.NewID;

      // create some media item. Location, fields and template are not important
      using (Sitecore.FakeDb.Db db = new Sitecore.FakeDb.Db
      {
        new Sitecore.FakeDb.DbItem("my-image", mediaItemId)
      })
      {
        Sitecore.Data.Items.Item mediaItem = db.GetItem(mediaItemId);

        // create media provider mock and configure behaviour
        Sitecore.Resources.Media.MediaProvider mediaProvider =
          NSubstitute.Substitute.For<Sitecore.Resources.Media.MediaProvider>();

        mediaProvider
          .GetMediaUrl(Arg.Is<Sitecore.Data.Items.MediaItem>(i => i.ID == mediaItemId))
          .Returns(MyImageUrl);

        // substitute the original provider with the mocked one
        using (new Sitecore.FakeDb.Resources.Media.MediaProviderSwitcher(mediaProvider))
        {
          string mediaUrl = Sitecore.Resources.Media.MediaManager.GetMediaUrl(mediaItem);
          Xunit.Assert.Equal(MyImageUrl, mediaUrl);
        }
      }
    }
예제 #45
0
    public void HowToWorkWithLinkDatabase()
    {
      // arrange your database and items
      Sitecore.Data.ID sourceId = Sitecore.Data.ID.NewID;
      Sitecore.Data.ID aliasId = Sitecore.Data.ID.NewID;
      Sitecore.Data.ID linkedItemId = Sitecore.Data.ID.NewID;

      using (Sitecore.FakeDb.Db db = new Sitecore.FakeDb.Db
      {
        new Sitecore.FakeDb.DbItem("source", sourceId),
        new Sitecore.FakeDb.DbItem("clone"),
        new Sitecore.FakeDb.DbItem("alias", aliasId, Sitecore.TemplateIDs.Alias)
        {
          new Sitecore.FakeDb.DbField("Linked item", linkedItemId)
        }
      })
      {
        // arrange desired LinkDatabase behavior
        var behavior = Substitute.For<Sitecore.Links.LinkDatabase>();

        Sitecore.Data.Items.Item source = db.GetItem("/sitecore/content/source");
        Sitecore.Data.Items.Item alias = db.GetItem("/sitecore/content/alias");
        Sitecore.Data.Items.Item clone = db.GetItem("/sitecore/content/clone");

        string sourcePath = source.Paths.FullPath;
        behavior.GetReferrers(source).Returns(new[]
        {
          new Sitecore.Links.ItemLink(alias, linkedItemId, source, sourcePath),
          new Sitecore.Links.ItemLink(clone, Sitecore.FieldIDs.Source, source, sourcePath)
        });

        // link database is clean
        Xunit.Assert.Equal(Sitecore.Globals.LinkDatabase.GetReferrers(source).Count(), 0);

        using (new Sitecore.FakeDb.Links.LinkDatabaseSwitcher(behavior))
        {
          Sitecore.Links.ItemLink[] referrers =
            Sitecore.Globals.LinkDatabase.GetReferrers(source);

          Xunit.Assert.Equal(referrers.Count(), 2);
          Xunit.Assert.Equal(referrers.Count(r => r.SourceItemID == clone.ID
            && r.TargetItemID == source.ID), 1);
          Xunit.Assert.Equal(referrers.Count(r => r.SourceItemID == alias.ID
            && r.TargetItemID == source.ID), 1);
        }

        // link database is clean again
        Xunit.Assert.Equal(Sitecore.Globals.LinkDatabase.GetReferrers(source).Count(), 0);
      }
    }
예제 #46
0
    public void HowToCreateTemplateHierarchy()
    {
      var baseTemplateIdOne = Sitecore.Data.ID.NewID;
      var baseTemplateIdTwo = Sitecore.Data.ID.NewID;
      var templateId = Sitecore.Data.ID.NewID;

      using (Sitecore.FakeDb.Db db = new Sitecore.FakeDb.Db
      {
        new Sitecore.FakeDb.DbTemplate("base one", baseTemplateIdOne),
        new Sitecore.FakeDb.DbTemplate("base two", baseTemplateIdTwo),
        new Sitecore.FakeDb.DbTemplate("Main", templateId)
          {
            BaseIDs = new[] { baseTemplateIdOne, baseTemplateIdTwo }
          }
      })
      {
        var template =
          Sitecore.Data.Managers.TemplateManager.GetTemplate(templateId, db.Database);

        Xunit.Assert.Contains(baseTemplateIdOne, template.BaseIDs);
        Xunit.Assert.Contains(baseTemplateIdTwo, template.BaseIDs);

        Xunit.Assert.True(template.InheritsFrom(baseTemplateIdOne));
        Xunit.Assert.True(template.InheritsFrom(baseTemplateIdTwo));
      }
    }
예제 #47
0
    public void HowToCreateLinkFieldUsingDbLinkField()
    {
      using (Sitecore.FakeDb.Db db = new Sitecore.FakeDb.Db
        {
          new Sitecore.FakeDb.DbItem("home")
            {
              new Sitecore.FakeDb.DbLinkField("link")
                {
                  LinkType = "external", Url = "http://google.com"
                }
            }
        })
      {
        var item = db.GetItem("/sitecore/content/home");

        var linkField = (Sitecore.Data.Fields.LinkField)item.Fields["link"];

        Xunit.Assert.Equal("external", linkField.LinkType);
        Xunit.Assert.Equal("http://google.com", linkField.Url);
      }
    }
예제 #48
0
    public void HowToCreateLinkFieldUsingRawValue()
    {
      using (Sitecore.FakeDb.Db db = new Sitecore.FakeDb.Db
        {
          new Sitecore.FakeDb.DbItem("home")
            {
              { "link", "<link linktype=\"external\" url=\"http://google.com\" />" }
            }
        })
      {
        var item = db.GetItem("/sitecore/content/home");

        var linkField = (Sitecore.Data.Fields.LinkField)item.Fields["link"];

        Xunit.Assert.Equal("external", linkField.LinkType);
        Xunit.Assert.Equal("http://google.com", linkField.Url);
      }
    }
예제 #49
0
    public void HowToSwitchLinkProvider()
    {
      // arrange
      using (Sitecore.FakeDb.Db db = new Sitecore.FakeDb.Db
        {
          new Sitecore.FakeDb.DbItem("home")
        })
      {
        Sitecore.Data.Items.Item home = db.GetItem("/sitecore/content/home");

        Sitecore.Links.LinkProvider provider = Substitute.For<Sitecore.Links.LinkProvider>();
        provider.GetItemUrl(home, Arg.Is<Sitecore.Links.UrlOptions>(x => x.AlwaysIncludeServerUrl))
          .Returns("http://myawesomeurl.com");

        using (new Sitecore.FakeDb.Links.LinkProviderSwitcher(provider))
        {
          // act
          var result = Sitecore.Links.LinkManager.GetItemUrl(home,
            new Sitecore.Links.UrlOptions { AlwaysIncludeServerUrl = true });

          // assert
          Xunit.Assert.Equal("http://myawesomeurl.com", result);
        }
      }
    }
예제 #50
0
    public void HowToUnitTestItemSecurityWithFakeProvider()
    {
      // create sample item
      using (Sitecore.FakeDb.Db db = new Sitecore.FakeDb.Db
        {
          new Sitecore.FakeDb.DbItem("home")
        })
      {
        Sitecore.Data.Items.Item home = db.GetItem("/sitecore/content/home");

        // call your business logic that changes the item security, e.g. denies Read
        // for Editors
        var account = Sitecore.Security.Accounts.Role.FromName(@"sitecore\Editors");
        var accessRight = Sitecore.Security.AccessControl.AccessRight.ItemRead;
        var propagationType = Sitecore.Security.AccessControl.PropagationType.Entity;
        var permission = Sitecore.Security.AccessControl.AccessPermission.Deny;

        Sitecore.Security.AccessControl.AccessRuleCollection rules =
          new Sitecore.Security.AccessControl.AccessRuleCollection
              {
                Sitecore.Security.AccessControl.AccessRule.Create
                  (account, accessRight, propagationType, permission)
              };
        Sitecore.Security.AccessControl.AuthorizationManager.SetAccessRules(home, rules);

        // check the account cannot read the item
        Xunit.Assert.False(home.Security.CanRead(account));
      }
    }
예제 #51
0
    public void HowToWorkWithFastQueryApi()
    {
      const string Query = "fast:/sitecore/content/*[@@key = 'home']";

      using (Sitecore.FakeDb.Db db = new Sitecore.FakeDb.Db
        {
          new Sitecore.FakeDb.DbItem("home")
        })
      {
        Sitecore.Data.Items.Item homeItem = db.Database.SelectSingleItem(Query);

        Xunit.Assert.Equal(homeItem.Key, "home");
      }
    }
예제 #52
0
    public void HowToConfigureItemAccess()
    {
      using (Sitecore.FakeDb.Db db = new Sitecore.FakeDb.Db
        {
          // set Access.CanRead to False
          new Sitecore.FakeDb.DbItem("home") { Access = { CanRead = false } }
        })
      {
        Sitecore.Data.Items.Item item = db.GetItem("/sitecore/content/home");

        // item is null because read is denied
        Xunit.Assert.Null(item);
      }
    }
예제 #53
0
    public void HowToSetAndGetBlobStream()
    {
      // arrange
      var stream = new System.IO.MemoryStream();

      using (Sitecore.FakeDb.Db db = new Sitecore.FakeDb.Db
        {
          new Sitecore.FakeDb.DbItem("home")
            {
              new Sitecore.FakeDb.DbField("field")
            }
        })
      {
        Sitecore.Data.Items.Item item = db.GetItem("/sitecore/content/home");
        Sitecore.Data.Fields.Field field = item.Fields["field"];

        using (new Sitecore.Data.Items.EditContext(item))
        {
          // act
          field.SetBlobStream(stream);
        }

        // assert
        Xunit.Assert.Same(stream, field.GetBlobStream());
      }
    }
예제 #54
0
    public void HowToUnitTestPipelineCallWithMockedProcessor()
    {
      var args = new Sitecore.Pipelines.PipelineArgs();

      using (Sitecore.FakeDb.Db db = new Sitecore.FakeDb.Db())
      {
        // create pipeline processor mock and register it in the Pipeline Watcher
        var processor = Substitute.For<Sitecore.FakeDb.Pipelines.IPipelineProcessor>();
        db.PipelineWatcher.Register("mypipeline", processor);

        // call the pipeline
        Sitecore.Pipelines.CorePipeline.Run("mypipeline", args);

        // and check the mocked processor received the Process method call with proper arguments
        processor.Received().Process(args);
      }
    }
예제 #55
0
    public void HowToUnitTestLocalization()
    {
      // init languages
      Sitecore.Globalization.Language en = Sitecore.Globalization.Language.Parse("en");
      Sitecore.Globalization.Language da = Sitecore.Globalization.Language.Parse("da");

      const string Phrase = "Welcome!";

      using (Sitecore.FakeDb.Db db = new Sitecore.FakeDb.Db())
      {
        db.Configuration.Settings.AutoTranslate = true;
        db.Configuration.Settings.AutoTranslatePrefix = "{lang}:";

        // translate
        string enTranslation = Sitecore.Globalization.Translate.TextByLanguage(Phrase, en);
        string daTranslation = Sitecore.Globalization.Translate.TextByLanguage(Phrase, da);

        Xunit.Assert.Equal("en:Welcome!", enTranslation);
        Xunit.Assert.Equal("da:Welcome!", daTranslation);
      }
    }
예제 #56
0
    public void HowToUnitTestAdvancedPipelineCallWithMockedProcessor()
    {
      var args = new Sitecore.Pipelines.PipelineArgs();

      using (Sitecore.FakeDb.Db db = new Sitecore.FakeDb.Db())
      {
        // create pipeline processor mock and register it in the Pipeline Watcher
        var processor = Substitute.For<Sitecore.FakeDb.Pipelines.IPipelineProcessor>();
        processor
          .When(p => p.Process(args))
          .Do(ci => ci.Arg<Sitecore.Pipelines.PipelineArgs>().CustomData["Result"] = "Ok");

        db.PipelineWatcher.Register("mypipeline", processor);

        // call the pipeline
        Sitecore.Pipelines.CorePipeline.Run("mypipeline", args);

        // and check the result
        Assert.Equal("Ok", args.CustomData["Result"]);
      }
    }
예제 #57
0
    public void HowToUnitTestItemSecurityWithMockedProvider()
    {
      // create sample item
      using (Sitecore.FakeDb.Db db = new Sitecore.FakeDb.Db
        {
          new Sitecore.FakeDb.DbItem("home")
        })
      {
        Sitecore.Data.Items.Item home = db.GetItem("/sitecore/content/home");

        // substitute the authorization provider
        var provider =
          Substitute.For<Sitecore.Security.AccessControl.AuthorizationProvider>();

        using (new Sitecore.FakeDb.Security.AccessControl.AuthorizationSwitcher(provider))
        {
          // call your business logic that changes the item security, e.g. denies Read
          // for Editors
          var account = Sitecore.Security.Accounts.Role.FromName(@"sitecore\Editors");
          var accessRight = Sitecore.Security.AccessControl.AccessRight.ItemRead;
          var propagationType = Sitecore.Security.AccessControl.PropagationType.Entity;
          var permission = Sitecore.Security.AccessControl.AccessPermission.Deny;

          Sitecore.Security.AccessControl.AccessRuleCollection rules =
            new Sitecore.Security.AccessControl.AccessRuleCollection
              {
                Sitecore.Security.AccessControl.AccessRule.Create
                  (account, accessRight, propagationType, permission)
              };
          Sitecore.Security.AccessControl.AuthorizationManager.SetAccessRules(home, rules);

          // check the provider is called with proper arguments
          provider
            .Received()
            .SetAccessRules(
              home,
              NSubstitute.Arg.Is<Sitecore.Security.AccessControl.AccessRuleCollection>(
                r => r[0].Account.Name == @"sitecore\Editors"
                  && r[0].AccessRight.Name == "item:read"
                  && r[0].PropagationType.ToString() == "Entity"
                  && r[0].SecurityPermission.ToString() == "DenyAccess"));
        }
      }
    }
예제 #58
0
    public void HowDoIMockContentSearchLogic()
    {
      try
      {
        var index = Substitute.For<Sitecore.ContentSearch.ISearchIndex>();
        Sitecore.ContentSearch.ContentSearchManager.SearchConfiguration.Indexes.Add("my_index", index);

        using (Sitecore.FakeDb.Db db = new Sitecore.FakeDb.Db { new Sitecore.FakeDb.DbItem("home") })
        {
          var searchResultItem = Substitute.For<Sitecore.ContentSearch.SearchTypes.SearchResultItem>();
          searchResultItem.GetItem().Returns(db.GetItem("/sitecore/content/home"));
          index.CreateSearchContext().GetQueryable<Sitecore.ContentSearch.SearchTypes.SearchResultItem>().Returns((new[] { searchResultItem }).AsQueryable());

          Sitecore.Data.Items.Item result = index.CreateSearchContext().GetQueryable<Sitecore.ContentSearch.SearchTypes.SearchResultItem>().Single().GetItem();

          Assert.Equal("/sitecore/content/home", result.Paths.FullPath);
        }
      }
      finally
      {
        Sitecore.ContentSearch.ContentSearchManager.SearchConfiguration.Indexes.Remove("my_index");
      }
    }