当前位置: 首页>>代码示例>>C#>>正文


C# Sites.FakeSiteContext类代码示例

本文整理汇总了C#中Sitecore.FakeDb.Sites.FakeSiteContext的典型用法代码示例。如果您正苦于以下问题:C# FakeSiteContext类的具体用法?C# FakeSiteContext怎么用?C# FakeSiteContext使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


FakeSiteContext类属于Sitecore.FakeDb.Sites命名空间,在下文中一共展示了FakeSiteContext类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: OnActionExecuting_RedirectEqualsCurrent_ShouldRedirectToRootPage

    public void OnActionExecuting_RedirectEqualsCurrent_ShouldRedirectToRootPage(Database db, [Content] DbItem item, string afterLoginLink, [Frozen]IAccountsSettingsService accountsSettingsService, [Substitute]ActionExecutingContext filterContext, [Greedy]AccountsRedirectAuthenticatedAttribute redirectAuthenticatedAttribute)
    {
      //Arrange
      var siteContext = new FakeSiteContext(new StringDictionary
      {
        {
          "rootPath", "/sitecore/content"
        },
        {
          "startItem", item.Name
        }
      }) as SiteContext;
      siteContext.Database = db;

      accountsSettingsService.GetPageLinkOrDefault(Arg.Any<Item>(), Templates.AccountsSettings.Fields.AfterLoginPage, Arg.Any<Item>()).Returns(afterLoginLink);
      filterContext.HttpContext.Request.RawUrl.Returns(afterLoginLink);

      //Act
      using (new SiteContextSwitcher(siteContext))
      using (new Sitecore.Security.Accounts.UserSwitcher(@"extranet\John", true))
      {
        redirectAuthenticatedAttribute.OnActionExecuting(filterContext);
      }

      //Assert      
      filterContext.Result.Should().BeOfType<RedirectResult>().Which.Url.Should().NotBe(afterLoginLink);
    }
开发者ID:robearlam,项目名称:Habitat,代码行数:27,代码来源:AccountsRedirectAuthenticatedAttributeTests.cs

示例2: LoadProfiles_SettingsIsEmpty_ShouldReturnExistentProfilesEnumerable

    public void LoadProfiles_SettingsIsEmpty_ShouldReturnExistentProfilesEnumerable([Content] Item item, CurrentInteraction currentInteraction, ITracker tracker, Profile profile)
    {
      var profileSettingItem = item.Add("profileSetting", new TemplateID(Templates.ProfilingSettings.ID));
      var profileItem = item.Add("profile", new TemplateID(ProfileItem.TemplateID));


      var provider = new ProfileProvider();

      var fakeSiteContext = new FakeSiteContext(new StringDictionary
      {
        {
          "rootPath", "/sitecore"
        },
        {
          "startItem", profileSettingItem.Paths.FullPath.Remove(0, "/sitecore".Length)
        }
      });

      fakeSiteContext.Database = item.Database;

      using (new SiteContextSwitcher(fakeSiteContext))
      {
        provider.GetSiteProfiles().Count().Should().Be(0);
      }
    }
开发者ID:robearlam,项目名称:Habitat,代码行数:25,代码来源:ProfileProviderTests.cs

示例3: LoadProfiles_NoSetProfiles_ShouldReturnEmptyProfilesEnumerable

    public void LoadProfiles_NoSetProfiles_ShouldReturnEmptyProfilesEnumerable(Database db, [Content] Item item, ITracker tracker, IProfileProvider provider)
    {
      //arrange
      tracker.IsActive.Returns(true);

      var fakeSiteContext = new FakeSiteContext(new StringDictionary
      {
        {
          "rootPath", "/sitecore"
        },
        {
          "startItem", item.Paths.FullPath.Remove(0, "/sitecore".Length)
        }
      });
      fakeSiteContext.Database = db;

      using (new SiteContextSwitcher(fakeSiteContext))
      {
        using (new TrackerSwitcher(tracker))
        {
          var model = new VisitInformation(provider);
          model.LoadProfiles().Count().Should().Be(0);
        }
      }
    }
开发者ID:robearlam,项目名称:Habitat,代码行数:25,代码来源:VisitInformationTests.cs

示例4: LoadProfiles_SettingWithProfiles_ShouldReturnExistentProfilesEnumerable

    public void LoadProfiles_SettingWithProfiles_ShouldReturnExistentProfilesEnumerable(Db db, CurrentInteraction currentInteraction, ITracker tracker, Analytics.Tracking.Profile profile)
    {
      var profileItem = new DbItem("profile", ID.NewID, new TemplateID(ProfileItem.TemplateID));
      db.Add(profileItem);
      var profileSettingItem = new DbItem("profileSetting", ID.NewID, new TemplateID(Templates.ProfilingSettings.ID))
                               {
                                 {Templates.ProfilingSettings.Fields.SiteProfiles, profileItem.ID.ToString()}
                               };
      db.Add(profileSettingItem);

      var provider = new ProfileProvider();

      var fakeSiteContext = new FakeSiteContext(new StringDictionary
                                                {
                                                  {"rootPath", "/sitecore"},
                                                  {"startItem", profileSettingItem.FullPath.Remove(0, "/sitecore".Length)}
                                                })
                            {
                              Database = db.Database
                            };


      using (new SiteContextSwitcher(fakeSiteContext))
      {
        var siteProfiles = provider.GetSiteProfiles();
        siteProfiles.Count().Should().Be(1);
      }
    }
开发者ID:Sitecore,项目名称:Habitat,代码行数:28,代码来源:ProfileProviderTests.cs

示例5: ShouldCreateSimpleFakeSiteContext

    public void ShouldCreateSimpleFakeSiteContext()
    {
      // arrange & act
      var siteContext = new FakeSiteContext("mywebsite");

      // assert
      siteContext.Name.Should().Be("mywebsite");
      siteContext.Database.Should().BeNull();
    }
开发者ID:dharnitski,项目名称:Sitecore.FakeDb,代码行数:9,代码来源:FakeSiteContextTest.cs

示例6: ShouldCreateAdvancedFakeSiteContext

    public void ShouldCreateAdvancedFakeSiteContext()
    {
      // arrange & act
      var siteContext = new FakeSiteContext(new StringDictionary { { "name", "mywebsite" }, { "database", "web" } });

      // assert
      siteContext.Name.Should().Be("mywebsite");
      siteContext.Database.Name.Should().Be("web");
    }
开发者ID:dharnitski,项目名称:Sitecore.FakeDb,代码行数:9,代码来源:FakeSiteContextTest.cs

示例7: FakeSite

        public FakeSite()
        {
            _fakeSiteContext = new Sitecore.FakeDb.Sites.FakeSiteContext(
                new Sitecore.Collections.StringDictionary
                {
                    {"name", "website"},
                    {"database", "web"}
                });

            _switcher = new FakeSiteContextSwitcher(_fakeSiteContext);
        }
开发者ID:mikeedwards83,项目名称:Glass.Mapper,代码行数:11,代码来源:FakeSite.cs

示例8: ShouldSwitchContextSite

    public void ShouldSwitchContextSite()
    {
      // arrange
      var site = new FakeSiteContext("mywebsite");

      // act
      using (new SiteContextSwitcher(site))
      {
        // assert
        Context.Site.Name.Should().Be("mywebsite");
      }

      Context.Site.Should().BeNull();
    }
开发者ID:dharnitski,项目名称:Sitecore.FakeDb,代码行数:14,代码来源:SiteContextSwitcherTest.cs

示例9: OnActionExecuting_NotNormalMode_ShouldNotRedirect

    public void OnActionExecuting_NotNormalMode_ShouldNotRedirect(FakeSiteContext siteContext, [Substitute]ActionExecutingContext filterContext, RedirectAuthenticatedAttribute redirectAuthenticatedAttribute)
    {
      //Arrange
      typeof(SiteContext).GetField("displayMode", BindingFlags.Instance | BindingFlags.NonPublic).SetValue(siteContext, DisplayMode.Edit);

      //Act
      using (new SiteContextSwitcher(siteContext))
      {
        redirectAuthenticatedAttribute.OnActionExecuting(filterContext);
      }

      //Assert
      filterContext.Result.Should().BeNull();
    }
开发者ID:GoranHalvarsson,项目名称:Habitat,代码行数:14,代码来源:RedirectAuthenticatedAttributeTests.cs

示例10: PageEditorError_EditMode_RenderErrorViewFriendlyMessage

    public void PageEditorError_EditMode_RenderErrorViewFriendlyMessage(string errorMessage, string friendlyMessage, FakeSiteContext siteContext, [RegisterView(Constants.InfoMessageView)] IView view, HtmlHelper helper)
    {
      //Arrange
      typeof(SiteContext).GetField("displayMode", BindingFlags.Instance | BindingFlags.NonPublic).SetValue(siteContext, DisplayMode.Edit);

      //Act
      MvcHtmlString result;
      using (new SiteContextSwitcher(siteContext))
      {
        result = helper.PageEditorError(errorMessage, friendlyMessage, ID.NewID, ID.NewID);

        //Assert
        view.Received().Render(Arg.Is<ViewContext>(v => v.ViewData.Model.As<InfoMessage>().Type == InfoMessage.MessageType.Error), Arg.Any<TextWriter>());
      }
    }
开发者ID:alinulms,项目名称:Habitat,代码行数:15,代码来源:AlertHtmlHelpersTests.cs

示例11: Process_HandledException_DontSetView

    public void Process_HandledException_DontSetView(FakeSiteContext siteContext, InvalidDatasourceItemExceptionProcessor processor, [Modest] ExceptionContext exceptionContext, [Substitute] ExceptionArgs exceptionArgs)
    {
      //Arrange
      typeof(SiteContext).GetField("displayMode", BindingFlags.Instance | BindingFlags.NonPublic).SetValue(siteContext, DisplayMode.Edit);
      exceptionArgs.ExceptionContext.ExceptionHandled = true;

      //Act
      using (new SiteContextSwitcher(siteContext))
      {
        processor.Process(exceptionArgs);

        //Assert
        exceptionArgs.ExceptionContext.Result.Should().BeOfType<EmptyResult>();
      }
    }
开发者ID:alinulms,项目名称:Habitat,代码行数:15,代码来源:InvalidDatasourceItemExceptionProcessorTests.cs

示例12: Get_DictionaryRootItemExists_ThrowConfigurationErrorException

    public void Get_DictionaryRootItemExists_ThrowConfigurationErrorException(Db db, [Content]DbItem item, DictionaryRepository repository)
    {
      //Arrange
      var siteContext = new FakeSiteContext(new StringDictionary()
      {
        ["dictionaryPath"] = item.FullPath,
        ["database"] = "master"
      });

      //Assert
      using (new SiteContextSwitcher(siteContext))
      {
        repository.Get(siteContext).Root.ID.Should().Be(item.ID);
      }
    }
开发者ID:GoranHalvarsson,项目名称:Habitat,代码行数:15,代码来源:DictionaryRepositoryTests.cs

示例13: Get_NotDictionaryRootItem_ThrowConfigurationErrorException

    public void Get_NotDictionaryRootItem_ThrowConfigurationErrorException(Db db, DictionaryRepository repository)
    {
      //Arrange
      var siteContext = new FakeSiteContext(new StringDictionary()
      {
        ["dictionaryPath"] = "/sitecore/content/dictionaryPath",
        ["database"] = "master"
      });

      //Assert
      using (new SiteContextSwitcher(siteContext))
      {
        repository.Invoking(x => x.Get(siteContext)).ShouldThrow<ConfigurationErrorsException>();
      }
    }
开发者ID:GoranHalvarsson,项目名称:Habitat,代码行数:15,代码来源:DictionaryRepositoryTests.cs

示例14: OnActionExecuting_NotAuthenticatedUser_ShouldNotRedirect

    public void OnActionExecuting_NotAuthenticatedUser_ShouldNotRedirect(FakeSiteContext siteContext, [Substitute]ActionExecutingContext filterContext, RedirectAuthenticatedAttribute redirectAuthenticatedAttribute)
    {
      //Arrange
      typeof(SiteContext).GetField("displayMode", BindingFlags.Instance | BindingFlags.NonPublic).SetValue(siteContext, DisplayMode.Normal);

      //Act
      using (new SiteContextSwitcher(siteContext))
      using (new Sitecore.Security.Accounts.UserSwitcher(@"extranet\John", false))
      {
        redirectAuthenticatedAttribute.OnActionExecuting(filterContext);
      }

      //Assert
      filterContext.Result.Should().BeNull();
    }
开发者ID:GoranHalvarsson,项目名称:Habitat,代码行数:15,代码来源:RedirectAuthenticatedAttributeTests.cs

示例15: Logout_ShouldCallSitecoreLogout

 public void Logout_ShouldCallSitecoreLogout(Database db, [Content] DbItem item, IAccountRepository repo, INotificationService ns, IAccountsSettingsService acc)
 {
     var fakeSite = new FakeSiteContext(new StringDictionary
                                        {
                                            {"rootPath", "/sitecore/content"},
                                            {"startItem", item.Name}
                                        }) as SiteContext;
     fakeSite.Database = db;
     using (new SiteContextSwitcher(fakeSite))
     {
         var ctrl = new AccountsController(repo, ns, acc, null, null);
         ctrl.Logout();
         repo.Received(1).Logout();
     }
 }
开发者ID:Sitecore,项目名称:Habitat,代码行数:15,代码来源:AccountsControllerTests.cs


注:本文中的Sitecore.FakeDb.Sites.FakeSiteContext类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。