本文整理汇总了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);
}
示例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);
}
}
示例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);
}
}
}
示例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);
}
}
示例5: ShouldCreateSimpleFakeSiteContext
public void ShouldCreateSimpleFakeSiteContext()
{
// arrange & act
var siteContext = new FakeSiteContext("mywebsite");
// assert
siteContext.Name.Should().Be("mywebsite");
siteContext.Database.Should().BeNull();
}
示例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");
}
示例7: FakeSite
public FakeSite()
{
_fakeSiteContext = new Sitecore.FakeDb.Sites.FakeSiteContext(
new Sitecore.Collections.StringDictionary
{
{"name", "website"},
{"database", "web"}
});
_switcher = new FakeSiteContextSwitcher(_fakeSiteContext);
}
示例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();
}
示例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();
}
示例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>());
}
}
示例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>();
}
}
示例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);
}
}
示例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>();
}
}
示例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();
}
示例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();
}
}