public void GetMediaUrlOptions( SitecoreInfoMediaUrlOptions option, bool absolutePath, bool allowStretch, bool alwaysIncludeServerUrl, bool disableBrowserCache, bool disableMediaCache, bool ignoreAspectRatio, bool includeExtension, bool lowercaseUrls, bool thumbnail, bool useDefaultIcon, bool useItemPath) { //Arrange //Act var result = Utilities.GetMediaUrlOptions(option); //Assert Assert.AreEqual(result.AbsolutePath, absolutePath); Assert.AreEqual(result.AllowStretch, allowStretch); Assert.AreEqual(result.AlwaysIncludeServerUrl, alwaysIncludeServerUrl); Assert.AreEqual(result.DisableBrowserCache, disableBrowserCache); Assert.AreEqual(result.DisableMediaCache, disableMediaCache); Assert.AreEqual(result.IgnoreAspectRatio, ignoreAspectRatio); Assert.AreEqual(result.IncludeExtension, includeExtension); Assert.AreEqual(result.LowercaseUrls, lowercaseUrls); Assert.AreEqual(result.Thumbnail, thumbnail); Assert.AreEqual(result.UseDefaultIcon, useDefaultIcon); Assert.AreEqual(result.UseItemPath, useItemPath); }
public void MapToProperty_MediaUrlWithFlag_ReturnsModifiedUrl( SitecoreInfoMediaUrlOptions option, string expected ) { //Assign var mapper = new SitecoreInfoMapper(); var config = new SitecoreInfoConfiguration(); config.Type = SitecoreInfoType.MediaUrl; config.MediaUrlOptions = option; mapper.Setup(new DataMapperResolverArgs(null, config)); Sitecore.Context.Site = null; var item = _db.GetItem("/sitecore/Content/Tests/DataMappers/SitecoreInfoMapper/DataMappersEmptyItem"); Assert.IsNotNull(item, "Item is null, check in Sitecore that item exists"); var dataContext = new SitecoreDataMappingContext(null, item, null); //Act var value = mapper.MapToProperty(dataContext); //Assert Assert.AreEqual(expected, value); }
public static MediaUrlOptions GetMediaUrlOptions(SitecoreInfoMediaUrlOptions mediaUrlOptions) { var defaultMediaUrl = MediaUrlOptions.Empty; if (mediaUrlOptions == 0) { return(defaultMediaUrl); } Func <SitecoreInfoMediaUrlOptions, bool> flagCheck = option => (mediaUrlOptions & option) == option; defaultMediaUrl.AbsolutePath = !flagCheck(SitecoreInfoMediaUrlOptions.DisableAbsolutePath) && defaultMediaUrl.AbsolutePath; defaultMediaUrl.AllowStretch = flagCheck(SitecoreInfoMediaUrlOptions.AllowStretch) || defaultMediaUrl.AllowStretch; defaultMediaUrl.AlwaysIncludeServerUrl = flagCheck(SitecoreInfoMediaUrlOptions.AlwaysIncludeServerUrl) || defaultMediaUrl.AlwaysIncludeServerUrl; defaultMediaUrl.DisableBrowserCache = flagCheck(SitecoreInfoMediaUrlOptions.DisableBrowserCache) || defaultMediaUrl.DisableBrowserCache; defaultMediaUrl.DisableMediaCache = flagCheck(SitecoreInfoMediaUrlOptions.DisableMediaCache) || defaultMediaUrl.DisableMediaCache; defaultMediaUrl.IgnoreAspectRatio = flagCheck(SitecoreInfoMediaUrlOptions.IgnoreAspectRatio) || defaultMediaUrl.IgnoreAspectRatio; defaultMediaUrl.IncludeExtension = !flagCheck(SitecoreInfoMediaUrlOptions.RemoveExtension) && defaultMediaUrl.IncludeExtension; defaultMediaUrl.LowercaseUrls = flagCheck(SitecoreInfoMediaUrlOptions.LowercaseUrls) || defaultMediaUrl.LowercaseUrls; defaultMediaUrl.Thumbnail = flagCheck(SitecoreInfoMediaUrlOptions.Thumbnail) || defaultMediaUrl.Thumbnail; defaultMediaUrl.UseDefaultIcon = flagCheck(SitecoreInfoMediaUrlOptions.UseDefaultIcon) || defaultMediaUrl.UseDefaultIcon; defaultMediaUrl.UseItemPath = flagCheck(SitecoreInfoMediaUrlOptions.UseItemPath) || defaultMediaUrl.UseItemPath; // defaultMediaUrl.BackgroundColor // defaultMediaUrl.Database // defaultMediaUrl.Height // defaultMediaUrl.DefaultIcon // defaultMediaUrl.ItemRevision //defaultMediaUrl.Language; //defaultMediaUrl.MaxHeight; //defaultMediaUrl.MaxWidth; //defaultMediaUrl.MediaLinkServerUrl; //defaultMediaUrl.RequestExtension; //defaultMediaUrl.Scale; //defaultMediaUrl.Version; //defaultMediaUrl.VirtualFolder; //defaultMediaUrl.Width; return(defaultMediaUrl); }
public virtual MediaUrlOptions GetMediaUrlOptions(SitecoreInfoMediaUrlOptions mediaUrlOptions) { var defaultMediaUrl = MediaUrlOptions.Empty; if (mediaUrlOptions == 0) return defaultMediaUrl; Func<SitecoreInfoMediaUrlOptions, bool> flagCheck = option => (mediaUrlOptions & option) == option; defaultMediaUrl.AbsolutePath = !flagCheck(SitecoreInfoMediaUrlOptions.DisableAbsolutePath) && defaultMediaUrl.AbsolutePath; defaultMediaUrl.AllowStretch = flagCheck(SitecoreInfoMediaUrlOptions.AllowStretch) || defaultMediaUrl.AllowStretch; defaultMediaUrl.AlwaysIncludeServerUrl = flagCheck(SitecoreInfoMediaUrlOptions.AlwaysIncludeServerUrl) || defaultMediaUrl.AlwaysIncludeServerUrl; defaultMediaUrl.DisableBrowserCache = flagCheck(SitecoreInfoMediaUrlOptions.DisableBrowserCache) || defaultMediaUrl.DisableBrowserCache; defaultMediaUrl.DisableMediaCache = flagCheck(SitecoreInfoMediaUrlOptions.DisableMediaCache) || defaultMediaUrl.DisableMediaCache; defaultMediaUrl.IgnoreAspectRatio = flagCheck(SitecoreInfoMediaUrlOptions.IgnoreAspectRatio) || defaultMediaUrl.IgnoreAspectRatio; defaultMediaUrl.IncludeExtension = !flagCheck(SitecoreInfoMediaUrlOptions.RemoveExtension) && defaultMediaUrl.IncludeExtension; defaultMediaUrl.LowercaseUrls = flagCheck(SitecoreInfoMediaUrlOptions.LowercaseUrls) || defaultMediaUrl.LowercaseUrls; defaultMediaUrl.Thumbnail = flagCheck(SitecoreInfoMediaUrlOptions.Thumbnail) || defaultMediaUrl.Thumbnail; defaultMediaUrl.UseDefaultIcon = flagCheck(SitecoreInfoMediaUrlOptions.UseDefaultIcon) || defaultMediaUrl.UseDefaultIcon; defaultMediaUrl.UseItemPath = flagCheck(SitecoreInfoMediaUrlOptions.UseItemPath) || defaultMediaUrl.UseItemPath; // defaultMediaUrl.BackgroundColor // defaultMediaUrl.Database // defaultMediaUrl.Height // defaultMediaUrl.DefaultIcon // defaultMediaUrl.ItemRevision //defaultMediaUrl.Language; //defaultMediaUrl.MaxHeight; //defaultMediaUrl.MaxWidth; //defaultMediaUrl.MediaLinkServerUrl; //defaultMediaUrl.RequestExtension; //defaultMediaUrl.Scale; //defaultMediaUrl.Version; //defaultMediaUrl.VirtualFolder; //defaultMediaUrl.Width; return defaultMediaUrl; }
public void MapToProperty_MediaUrlWithFlag_ReturnsModifiedUrl( SitecoreInfoMediaUrlOptions option ) { //Assign var mapper = new SitecoreInfoMapper(); var config = new SitecoreInfoConfiguration(); config.Type = SitecoreInfoType.MediaUrl; config.MediaUrlOptions = option; mapper.Setup(new DataMapperResolverArgs(null, config)); var itemId = new ID("031501A9C7F24596BD659276DA3A627A"); string expected = "media url"; Sitecore.Context.Site = null; using (Db database = new Db { new Sitecore.FakeDb.DbItem("TestItem", itemId) { Fields = { new FakeDbField(new ID("{B5E02AD9-D56F-4C41-A065-A133DB87BDEB}"), "DataMappersEmptyItem DisplayName") }, } }) { Func <MediaUrlOptions, bool> pred = x => { switch (option) { case SitecoreInfoMediaUrlOptions.Default: return(true); case SitecoreInfoMediaUrlOptions.RemoveExtension: return(x.IncludeExtension == false); case SitecoreInfoMediaUrlOptions.LowercaseUrls: return(x.LowercaseUrls == true); default: return(false); } }; #if SC90 || SC91 || SC92 var mediaUrlProvider = Substitute.For <BaseMediaManager>(); SitecoreVersionAbstractions.MediaManager = new LazyResetable <BaseMediaManager>(() => mediaUrlProvider); mediaUrlProvider .GetMediaUrl( Arg.Is <Sitecore.Data.Items.MediaItem>(i => i.ID == itemId), Arg.Is <MediaUrlOptions>(x => pred(x)) ) .Returns(expected); #else Sitecore.Resources.Media.MediaProvider mediaProvider = Substitute.For <Sitecore.Resources.Media.MediaProvider>(); mediaProvider .GetMediaUrl( Arg.Is <Sitecore.Data.Items.MediaItem>(i => i.ID == itemId), Arg.Is <MediaUrlOptions>(x => pred(x)) ) .Returns(expected); new Sitecore.FakeDb.Resources.Media.MediaProviderSwitcher(mediaProvider); #endif var options = new GetItemOptionsParams(); var item = database.GetItem("/sitecore/content/TestItem"); Assert.IsNotNull(item, "Item is null, check in Sitecore that item exists"); var dataContext = new SitecoreDataMappingContext(null, item, null, options); //Act var value = mapper.MapToProperty(dataContext); //Assert Assert.AreEqual(expected, value); } }
public void MapToProperty_MediaUrlWithFlag_ReturnsModifiedUrl( SitecoreInfoMediaUrlOptions option ) { //Assign var mapper = new SitecoreInfoMapper(); var config = new SitecoreInfoConfiguration(); config.Type = SitecoreInfoType.MediaUrl; config.MediaUrlOptions = option; mapper.Setup(new DataMapperResolverArgs(null, config)); var itemId = new ID("031501A9C7F24596BD659276DA3A627A"); string expected = "media url"; Sitecore.Context.Site = null; using (Db database = new Db { new Sitecore.FakeDb.DbItem("TestItem", itemId) { Fields = { new FakeDbField(new ID("{B5E02AD9-D56F-4C41-A065-A133DB87BDEB}"), "DataMappersEmptyItem DisplayName") }, } }) { Func<MediaUrlOptions, bool> pred = x => { switch (option) { case SitecoreInfoMediaUrlOptions.Default: return true; case SitecoreInfoMediaUrlOptions.RemoveExtension: return x.IncludeExtension == false; case SitecoreInfoMediaUrlOptions.LowercaseUrls: return x.LowercaseUrls == true; default: return false; } }; Sitecore.Resources.Media.MediaProvider mediaProvider = Substitute.For<Sitecore.Resources.Media.MediaProvider>(); mediaProvider .GetMediaUrl( Arg.Is<Sitecore.Data.Items.MediaItem>(i => i.ID == itemId), Arg.Is<MediaUrlOptions>(x => pred(x)) ) .Returns(expected); using (new Sitecore.FakeDb.Resources.Media.MediaProviderSwitcher(mediaProvider)) { var item = database.GetItem("/sitecore/content/TestItem"); Assert.IsNotNull(item, "Item is null, check in Sitecore that item exists"); var dataContext = new SitecoreDataMappingContext(null, item, null); //Act var value = mapper.MapToProperty(dataContext); //Assert Assert.AreEqual(expected, value); } } }
/// <summary> /// UrlOptions, use in conjunction with SitecoreInfoType.Url /// </summary> /// <param name="option">The option.</param> /// <returns>SitecoreInfo{`0}.</returns> public SitecoreInfo <T> UrlOptions(SitecoreInfoMediaUrlOptions option) { Configuration.MediaUrlOptions = option; return(this); }