public void GetRenderingContextItems_MatchingTemplateInterface_PageItemNotNull() { using (ShimsContext.Create()) { // Context Item var scBaseTemplateType = typeof(IScTemplate); var templateAttribute = (TemplateMappingAttribute)scBaseTemplateType.GetCustomAttributes(typeof(TemplateMappingAttribute), false).First(); var templateId = templateAttribute.Id; var testItem = FakesHelpers.CreateTestItem(templateId: templateId); Template templateItem = new ShimTemplate() { DescendsFromID = id => true, }; ShimTemplateManager.GetTemplateItem = id => { return(templateItem); }; _mockContextProvider.Setup(c => c.PageContextItem).Returns(testItem); _mockContextProvider.Setup(c => c.RenderingContextItem).Returns((Item)null); _mockContextProvider.Setup(c => c.RenderingItem).Returns((Item)null); _mockContextProvider.Setup(c => c.RenderingParameters).Returns(new Dictionary <string, string>()); var renderingModel = _itemFactory.GetRenderingContextItems <IScTemplate, IItemWrapper, IRenderingParameterWrapper>(); Assert.IsNotNull(renderingModel.PageItem); } }
public TwitterService GetTwitterService() { //var ScreenName = RenderingContext.Current.Rendering.Parameters["ScreenName"]; //var NoOfFeeds = RenderingContext.Current.Rendering.Parameters["NoOfFeeds"]; // Item[] items = Sitecore.Context.Database.SelectItems("/sitecore/system/Modules/TwitterFeed/TwitterFeedSettings"); //IItemWrapper item = this._itemFactory.Select<IItemWrapper>("/sitecore/system/Sitecore Play/TwitterSettings"); // IItemWrapper contextItem = this._itemFactory.GetContextItem<ITwitterSettings>(); var contextItem = _itemFactory.GetRenderingContextItems <ITwitterSettings, ITwitterSettings>(); ConsumerKey = contextItem.RenderingItem.ConsumerKeyValue; ConsumerSecret = contextItem.RenderingItem.ConsumerSecretValue; AccessToken = contextItem.RenderingItem.AccessTokenValue; AccessTokenSecret = contextItem.RenderingItem.AccessTokenSecretValue; ScreenName = contextItem.RenderingItem.ScreenNameValue; NoOfFeeds = contextItem.RenderingItem.NoOfFeedsValue.ToString(); var service = new TwitterService(ConsumerKey, ConsumerSecret, AccessToken, AccessTokenSecret); return(service); }