Sitecore FakeDb

  0 rating
7/28/2014 1:13:34 AM
4/17/2015 1:39:24 PM
Source: GitHub
Provider: Sitecore

About

FakeDb substitutes real Sitecore providers with fake "in-memory" providers to avoid calls to database or configuration. The providers does not replicate real Sitecore behavior but used mainly as stubs with minimal logic. They can be replaced with mocks in unit tests using provider switchers.

 

Sitecore FakeDb does not set goal to run entire Sitecore instance in-memory. It is a unit testing framework which is not supposed to be used for integration testing.

 

Features:

 

Content Management: In-memory item management using simplified API. Allows to create content tree, configure fields, languages, versions, security, locking, templates hierarchy and standard values.

 

Security: Mocking and substituting Authentication, Authorization, Role and RolesInRoles providers; switching Context User.

 

Pipelines: Configuring pipeline call expectations; checking expected calls including arguments.

 

Configuration: configuring Sitecore Settings in memory.

 

Globalization: Receiving fake localized texts when calling Translate.Text() methods.

 

Content Search: Mocking and configuring Content Search Manager; mocking Search Indexes.

 

Media: Mocking and substituting Media Provider.

 

Links (Tasks): Mocking and substituting Link (Task) Database.

Documentation

Documentation
  • Documentation > Installation
    Installation

     

    Sitecore FakeDb is available on NuGet. To install the framework:
    1. Create a new Class Library project.
    2. Add references to Sitecore.Kernel and Sitecore.Nexus assemblies.
    3. Run the following command in the NuGet Package Manager Console:

        Install-Package Sitecore.FakeDb

    4. Open App.config file added by the package and update path to the license.xml file using LicenseFile setting if necessary. By default the license file path is set to the root folder of the project:

        <setting name="LicenseFile" value="..\..\license.xml" />

     

    0
Back
Release notes
Version 1 was released
Read more Back
Code examples
  • Code examples > Configuration: How to configure settings
    Configuration: How to configure settings

    [Xunit.Fact]

    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);

       }

    }

    100
  • Code examples > Configuration: How to get item from Sitecore Database
    Configuration: How to get item from Sitecore Database

    [Xunit.Fact]

    public void HowToGetItemFromSitecoreDatabase()

    {

       using (new Sitecore.FakeDb.Db

         {

           new Sitecore.FakeDb.DbItem("Home")

         })

       {

         Sitecore.Data.Database database =

           Sitecore.Configuration.Factory.GetDatabase("master");

     

         Xunit.Assert.NotNull(database.GetItem("/sitecore/content/home"));

       }

    }

    100
  • Code examples > Content Search: How to mock Content Search
    Content Search: How to mock Content Search

    [Xunit.Fact]

    public void HowToMockContentSearchLogic()

    {

       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();

     

     

           Xunit.Assert.Equal("/sitecore/content/home", result.Paths.FullPath);

         }

       }

       finally

       {

         Sitecore.ContentSearch.ContentSearchManager.SearchConfiguration.Indexes

           .Remove("my_index");

       }

    }

    100
  • Code examples > Content: How to create a multilingual item
    Content: How to create a multilingual item

    [Xunit.Fact]

    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"]);

       }

    }

    100
  • Code examples > Content: How to create a simple item
    Content: How to create a simple item

    [Xunit.Fact]

    public void HowToCreateSimpleItem()

    {

       using (Sitecore.FakeDb.Db db = new Sitecore.FakeDb.Db

         {

            new Sitecore.FakeDb.DbItem("Home") { { "Title", "Welcome!" } }

         })

       {

         Sitecore.Data.Items.Item homeItem = db.GetItem("/sitecore/content/home");

         Xunit.Assert.Equal("Welcome!", homeItem["Title"]);

       }

    }

    100
  • Code examples > Content: How to create an item under System
    Content: How to create item under System

    [Xunit.Fact]

    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);

       }

    }

    100
  • Code examples > Content: How to create item hierarchy
    Content: How to create item hierarchy

    [Xunit.Fact]

    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["Getting Started"]);

         Xunit.Assert.NotNull(articles["Troubleshooting"]);

      }

    }

    100
  • Code examples > Content: How to create item with specific template
    Content: How to create item with specific template

    [Xunit.Fact]

    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"]);

       }

    }

    100
  • Code examples > Content: How to create template hierarchy
    Content: How to create template hierarchy

    [Xunit.Fact]

    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));

       }

    }

    100
  • Code examples > Content: How to create template with standard values
    Content: How to create template with standard values

    [Xunit.Fact]

    public void HowToCreateTemplateWithStandardValues()

    {

       var templateId = new Sitecore.Data.TemplateID(Sitecore.Data.ID.NewID);

       using (Sitecore.FakeDb.Db db = new Sitecore.FakeDb.Db

         {

           new Sitecore.FakeDb.DbTemplate("sample", templateId) { { "Title", "$name" } }

         })

       {

         Sitecore.Data.Items.Item contentRoot = db.GetItem(Sitecore.ItemIDs.ContentRoot);

         Sitecore.Data.Items.Item item = contentRoot.Add("Home", templateId);

           

         Xunit.Assert.Equal("Home", item["Title"]);

       }

    }

    100
  • Code examples > Content: How to create versioned item
    Content: How to create versioned item

    [Xunit.Fact]

    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"]);

       }

    }

    100
  • Code examples > Globalization: How to translate texts
    Globalization: How to translate texts

    /// <summary>

    /// FakeDb supports simple localization mechanism. You can call Translate.Text() or

    /// Translate.TextByLanguage() method to get a 'translated' version of the original text.

    /// The translated version has got language name added to the initial phrase.

    /// </summary>

    [Xunit.Fact]

    public void HowToTranslateTexts()

    {

       // init languages

       Sitecore.Globalization.Language en = Sitecore.Globalization.Language.Parse("en");

       Sitecore.Globalization.Language da = Sitecore.Globalization.Language.Parse("da");

         

       const string Phrase = "Welcome!";

         

       // 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);

    }

    100
  • Code examples > Links: How to work with Link Database
    Links: How to work with Link Database

    [Xunit.Fact]

    public void HowToWorkWithLinkDatabase()

    {

       // arrange your database and items

       Sitecore.Data.ID sourceId = 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", Sitecore.Data.ID.NewID, Sitecore.TemplateIDs.Alias)

             {

               // not really needed but this is how aliases look in the real world

               new Sitecore.FakeDb.DbField("Linked item")

                 {

                   Type = "Link",

                   Value = string.Format("<link linktype='internal' id='{0}' />", sourceId)

                 }

             }

         })

       {

         // 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");

           

         behavior.GetReferrers(source).Returns(new[]

           {

             new Sitecore.Links.ItemLink(alias, alias.Fields["Linked item"].ID, source, source.Paths.FullPath),

             new Sitecore.Links.ItemLink(clone, Sitecore.FieldIDs.Source, source, source.Paths.FullPath)

           });

     

         // act & assert

         // 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);

       }

    }

    100
  • Code examples > Media: How to mock Media Provider
    Media: How to mock Media Provider

    [Xunit.Fact]

    public void HowToMockMediaProvider()

    {

       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);

         }

       }

    }

    100
  • Code examples > Pipelines: How to configure the pipeline behavior
    Pipelines: How to configure the pipeline behavior

    /// <summary>

    /// How to configure the pipeline behaviour.

    /// The code sample above checks that the pipeline is called with proper arguments.

    /// The next scenario would be to validate the pipeline call results.

    /// In the code below we configure pipeline proressor behaviour to return an expected

    /// product only if the product id is set to "1".

    /// </summary>

    [Xunit.Fact]

    public void HowToConfigurePipelineBehaviour()

    {

       using (Sitecore.FakeDb.Db db = new Sitecore.FakeDb.Db())

       {

         // create a product to get from the repository

         object expectedProduct = new object();

           

         // configure processing of the pipeline arguments. Will set the 'expectedProduct'

         // instance to CustomData["Product"] property only when the CustomData["ProductId"]

         // is "1"

         string productId = "1";

           

         // configure a pipeline watcher to expect a pipeline call where the args custom data

         // contains ProductId. Once the args received the pipeline result is set into

         // 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);

       }

    }

     

    private partial class ProductRepository

    {

       public object GetProductById(string id)

       {

         var args = new Sitecore.Pipelines.PipelineArgs();

         args.CustomData["ProductId"] = id;

           

         Sitecore.Pipelines.CorePipeline.Run("findProductById", args);

     

         return args.CustomData["Product"];

       }

    }

    100
  • Code examples > Pipelines: How to ensure the  pipeline is called with specific arguments
    Pipelines: How to ensure the pipeline is called with specific arguments

    /// <summary>

    /// How to ensure the pipeline is called.

    /// Imagine you have a product repository. The repository should be able to get a product

    /// by id. The implementation of the repository is 'thin' and does nothing than calling a

    /// corresponding pipeline with proper arguments. The next example shows how to unit test

    /// the pipeline call (please note that the pipeline is not defined in the tests assembly

    /// config file):

    /// </summary>

    [Xunit.Fact]

    public void HowToEnsurePipelineIsCalledWithSpecificArgs()

    {

       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();

       }

    }

     

    private partial class ProductRepository

    {

       public void CreateProduct(string name)

       {

         var args = new Sitecore.Pipelines.PipelineArgs();

         args.CustomData["ProductName"] = name;

         Sitecore.Pipelines.CorePipeline.Run("createProduct", args);

       }

    }

    100
  • Code examples > Security: How to configure item access
    Security: How to configure item access

    [Xunit.Fact]

    public void HowToConfigureItemAccess()

    {

       using (Sitecore.FakeDb.Db db = new Sitecore.FakeDb.Db

         {

           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);

       }

    }

    100
  • Code examples > Security: How to mock Authentication provider
    Security: How to mock Authentication provider

    [Xunit.Fact]

    public void HowToMockAuthenticationProvider()

    {

       // create and configure authentication provider mock

       var provider = Substitute.For<Sitecore.Security.Authentication.AuthenticationProvider>();

       provider.Login("John", true).Returns(true);

     

       // switch the authentication provider so the mocked version is used

       using (new Sitecore.Security.Authentication.AuthenticationSwitcher(provider))

       {

         // the authentication manager is called with the expected parameters. It returns 'true'

         Xunit.Assert.True(Sitecore.Security.Authentication.AuthenticationManager.Login("John", true));

         // the authentication manager is called with some unexpected parameters. It returns 'false'

         Xunit.Assert.False(Sitecore.Security.Authentication.AuthenticationManager.Login("Robber", true));

       }

    }

    100
  • Code examples > Security: How to switch Context user
    Security: How to switch Context user

    [Xunit.Fact]

    public void HowToSwitchContextUser()

    {

       using (new Sitecore.Security.Accounts.UserSwitcher(@"extranet\John", true))

       {

         Xunit.Assert.Equal(@"extranet\John", Sitecore.Context.User.Name);

       }

    }

    100
  • Code examples > Security: How to mock Role Provider
    Security: How to mock Role Provider
        [Fact]
        public void HowToMockRoleProvider()
        {
          // create and configure role provider mock
          string[] roles = { @"sitecore/Authors", @"sitecore/Editors" };

          var provider = Substitute.For<System.Web.Security.RoleProvider>();
          provider.GetAllRoles().Returns(roles);

          // switch the role provider so the mocked version is used
          using (new Sitecore.FakeDb.Security.Web.RoleProviderSwitcher(provider))
          {
            string[] resultRoles = System.Web.Security.Roles.GetAllRoles();

            Xunit.Assert.True(resultRoles.Contains(@"sitecore/Authors"));
            Xunit.Assert.True(resultRoles.Contains(@"sitecore/Editors"));
          }
        }

    200
  • Code examples > Security: How to mock Authorization Provider
    Security: How to mock Authorization Provider
        [Fact]
        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);
            }
          }
        }
    300
  • Code examples > Security: How to unit test item security with fake provider
    Security: How to unit test item security with fake provider
        [Fact]
        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));
          }
        }

    400
  • Code examples > Security: How to unit test item security with mocked provider
    Security: How to unit test item security with mocked provider
        [Fact]
        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"));
            }
          }
        }

    500

Solution screenshots(0)

Upload

Reviews (0)

Sort by: Date Most votes
  • Profile Avatar
    [fullName]

    Level: 0

    x0 x0 x0

    [date]

    [title]

    [text]

    Was this helpful?

    0

Comments (0)

Sort by: Date  Most votes

Leave a Comment

Comment must be field in
Post comment
loader

Write a review

Title can't be empty
Review can't be empty
Post review

Download

Title Description Download Action

Add File