本文整理汇总了C#中Sitecore.FakeDb.Db类的典型用法代码示例。如果您正苦于以下问题:C# Db类的具体用法?C# Db怎么用?C# Db使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Db类属于Sitecore.FakeDb命名空间,在下文中一共展示了Db类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: DoesUserAgentMatchesTheRegularExpressionValueCondition
public void DoesUserAgentMatchesTheRegularExpressionValueCondition(string userAgent, string regularExpressionValue, bool expectedResult, Db database)
{
SetupDb(database);
RuleContext ruleContext = new RuleContext();
PoorMansDeviceDetectorCondition<RuleContext> customUserAgentCondition = new PoorMansDeviceDetectorCondition<RuleContext>()
{
OperatorId = Constants.StringOperations.MatchesTheRegularExpression.ItemID.ToString(),
Value = regularExpressionValue,
UserAgent = userAgent
};
var ruleStack = new RuleStack();
// act
customUserAgentCondition.Evaluate(ruleContext, ruleStack);
// assert
ruleStack.Should().HaveCount(1);
object value = ruleStack.Pop();
value.Should().Be(expectedResult);
}
示例2: GetProfileShouldReturnFullEditProfileModel
public void GetProfileShouldReturnFullEditProfileModel(Db db, [Substitute] UserProfile userProfile, [RightKeys("FirstName", "LastName", "Phone", "Interest")] IDictionary<string, string> properties,
[Frozen] IProfileSettingsService profileSettingsService, [Frozen] IUserProfileProvider userProfileProvider, [Greedy] UserProfileService userProfileService)
{
using (db)
{
var id = new ID();
db.Add(new DbItem("Profile", id)
{
Fields =
{
new DbField("FirstName", Templates.UserProfile.Fields.FirstName),
new DbField("LastName", Templates.UserProfile.Fields.LastName),
new DbField("Phone", Templates.UserProfile.Fields.PhoneNumber),
new DbField("Interest", Templates.UserProfile.Fields.Interest)
}
});
profileSettingsService.GetUserDefaultProfile().Returns(db.GetItem(id));
userProfileProvider.GetCustomProperties(Arg.Any<UserProfile>()).Returns(properties);
var result = userProfileService.GetProfile(userProfile);
result.FirstName.Should().Be(properties["FirstName"]);
result.LastName.Should().Be(properties["LastName"]);
result.PhoneNumber.Should().Be(properties["Phone"]);
result.Interest.Should().Be(properties["Interest"]);
}
}
示例3: ShouldShutdownLicenseWatcher
public void ShouldShutdownLicenseWatcher()
{
using (var db = new Db())
{
db.GetItem("/sitecore/content");
}
}
示例4: RenderParallaxMediaAttributes_Video_ShouldReturnVideoType
public void RenderParallaxMediaAttributes_Video_ShouldReturnVideoType(Db db)
{
var homeItemId = ID.NewID;
var mediaItemId = ID.NewID;
db.Add(new DbItem("home", homeItemId)
{
new DbLinkField("BackgroundMedia", Templates.HasParallaxBackground.Fields.BackgroundMedia)
{
LinkType = "media",
TargetID = mediaItemId
}
});
db.Add(new DbItem("mediaItem", mediaItemId)
{
{
"Mime type", "video/fake"
}
});
var homeItem = db.GetItem(homeItemId);
var htmlString = homeItem.RenderParallaxMediaAttributes();
var attributes = htmlString.ToString().Split(' ').Select(x => x.Split('=')).ToDictionary(x => x[0], val => val.Length == 1 ? "" : val[1].Trim('\'', '"'));
attributes["data-multibackground-layer-0-attachment"].Should().Be("static");
attributes["data-multibackground"].Should().BeEmpty();
attributes["data-multibackground-layer-0-type"].Should().Be("video");
attributes["data-multibackground-layer-0-format"].Should().Be("fake");
}
示例5: DemoContent_RenderingContextItemInitialized_ShouldReturnDemoContentView
public void DemoContent_RenderingContextItemInitialized_ShouldReturnDemoContentView(Db db, [Greedy] DemoController sut, [Content] DemoContentItem item)
{
using (RenderingContext.EnterContext(new Rendering(), db.GetItem(item.ID)))
{
sut.DemoContent().As<ViewResult>().Model.Should().BeOfType<DemoContent>();
}
}
示例6: GetEnumerator_Call_ReturnScoresWithKeyName
public void GetEnumerator_Call_ReturnScoresWithKeyName(Db db, ID keyId1, ID keyId2, DbItem profileItem, IBehaviorProfileContext behaviorProfile)
{
//Arrange
using (new SecurityDisabler())
{
profileItem.Add(new DbItem("Key1", keyId1, ProfileKeyItem.TemplateID)
{
{ProfileKeyItem.FieldIDs.NameField,"key1name" }
});
profileItem.Add(new DbItem("Key2", keyId2, ProfileKeyItem.TemplateID)
{
{ProfileKeyItem.FieldIDs.NameField,"key2name" }
});
db.Add(profileItem);
var item = db.GetItem(profileItem.FullPath);
var profile = new ProfileItem(item);
var behaviorScores = new List<KeyValuePair<ID, float>>() { new KeyValuePair<ID, float>(keyId1, 10), new KeyValuePair<ID, float>(keyId2, 20) };
behaviorProfile.Scores.Returns(behaviorScores);
var behaviorProfileDecorator = new BehaviorProfileDecorator(profile, behaviorProfile);
//Act
var result = behaviorProfileDecorator.ToList();
//Assert
result.Should().BeEquivalentTo(new[] { new KeyValuePair<string, float>("key1name", 10), new KeyValuePair<string, float>("key2name", 20) });
}
}
示例7: GetActive_ShouldReturnLanguageModelForContextLanguage
public void GetActive_ShouldReturnLanguageModelForContextLanguage(Db db, [Content] DbItem item)
{
var contextItem = db.GetItem(item.ID);
Context.Item = contextItem;
var activeLanguage = LanguageRepository.GetActive();
activeLanguage.TwoLetterCode.Should().BeEquivalentTo(Context.Language.Name);
}
示例8: GetKeywords_ContextItem_ShouldReturnKeywordsModel
public void GetKeywords_ContextItem_ShouldReturnKeywordsModel(Db db, string contextItemName, string keyword1ItemName, string keyword2ItemName)
{
var contextItemId = ID.NewID;
var keyword1Id = ID.NewID;
var keyword2Id = ID.NewID;
db.Add(new DbItem(contextItemName, contextItemId, Templates.PageMetadata.ID)
{
new DbField(Templates.PageMetadata.Fields.Keywords)
{
{"en", $"{keyword1Id}|{keyword2Id}"}
}
});
db.Add(new DbItem(keyword1ItemName, keyword1Id, Templates.Keyword.ID)
{
new DbField(Templates.Keyword.Fields.Keyword)
{
{"en", keyword1ItemName}
}
});
db.Add(new DbItem(keyword2ItemName, keyword2Id, Templates.Keyword.ID)
{
new DbField(Templates.Keyword.Fields.Keyword)
{
{"en", keyword2ItemName}
}
});
var contextItem = db.GetItem(contextItemId);
var keywordsModel = MetadataRepository.GetKeywords(contextItem);
keywordsModel.Should().BeOfType<MetaKeywordsModel>();
keywordsModel.Keywords.Count().Should().Be(2);
}
示例9: Process_LocalDatasourceNotExist_ShouldCreateDatasourceRoot
public void Process_LocalDatasourceNotExist_ShouldCreateDatasourceRoot(GetLocalDatasourceLocation processor, Db db, [Content] Item contextItem, [Content] DbTemplate template)
{
//arrange
db.Add(new DbItem("rendering")
{
{
Templates.RenderingOptions.Fields.SupportsLocalDatasource, "1"
}
});
var renderingItem = db.GetItem("/sitecore/content/rendering");
var getRenderingDatasourceArgs = new GetRenderingDatasourceArgs(renderingItem)
{
ContextItemPath = contextItem.Paths.FullPath
};
//act
using (new SettingsSwitcher("Foundation.LocalDatasource.LocalDatasourceFolderTemplate", template.ID.ToString()))
{
processor.Process(getRenderingDatasourceArgs);
}
//assert
var datasourceFolder = contextItem.GetChildren().First();
getRenderingDatasourceArgs.DatasourceRoots.First().ID.Should().Be(datasourceFolder.ID);
datasourceFolder.TemplateID.Should().Be(template.ID);
}
示例10: GetSupportedLanguages_NoneSelected_ShouldReturnEmptyList
public void GetSupportedLanguages_NoneSelected_ShouldReturnEmptyList(Db db, [Content] DbTemplate template, DbItem item, string rootName)
{
template.BaseIDs = new[]
{
Templates.Site.ID, Feature.Language.Templates.LanguageSettings.ID
};
var languageItem = new DbItem("en");
db.Add(languageItem);
var siteRootItem = new DbItem(rootName, ID.NewID, template.ID)
{
new DbField(Feature.Language.Templates.LanguageSettings.Fields.SupportedLanguages)
{
{
"en", ""
}
}
};
siteRootItem.Add(item);
db.Add(siteRootItem);
var contextItem = db.GetItem(item.ID);
Context.Item = contextItem;
var supportedLanguages = LanguageRepository.GetSupportedLanguages();
supportedLanguages.Count().Should().Be(0);
}
示例11: Execute_CreatesInferredType
public void Execute_CreatesInferredType()
{
//Arrange
using (Db database = new Db
{
new DbTemplate(new ID(StubInferred.TemplateId)),
new Sitecore.FakeDb.DbItem("Target", ID.NewID, new ID(StubInferred.TemplateId))
})
{
var context = Context.Create(FakeDb.Utilities.CreateStandardResolver());
var path = "/sitecore/content/Target";
context.Load(new AttributeTypeLoader(typeof(StubInferred)));
var typeContext = new SitecoreTypeCreationContext();
var args = new ConfigurationResolverArgs(context, typeContext, null, null);
var task = new TemplateInferredTypeTask();
typeContext.InferType = true;
typeContext.Item = database.GetItem(path);
typeContext.RequestedType = typeof(IBase);
args.RequestedType = typeof(IBase);
//Act
task.Execute(args);
//Assert
Assert.IsNotNull(args.Result);
Assert.AreEqual(typeof(StubInferred), args.Result.Type);
}
}
示例12: ReplaceItemReferences_ItemPassed_ShouldReplaceID
public void ReplaceItemReferences_ItemPassed_ShouldReplaceID(ItemReferenceReplacer referenceReplacer, Db db, [Content] Item source, [Content] Item target)
{
var initialValue = source.ID.ToString();
var expectedValue = target.ID.ToString();
ReplaceItemReferences_ItemPassed_ShouldReplaceValue(referenceReplacer, db, source, target, initialValue, expectedValue);
}
示例13: ReplaceItemReferences_ItemPassed_ShouldReplaceContentPath
public void ReplaceItemReferences_ItemPassed_ShouldReplaceContentPath(ItemReferenceReplacer referenceReplacer, Db db, [Content] Item source, [Content] Item target)
{
var initialValue = source.Paths.ContentPath;
var expectedValue = target.Paths.ContentPath;
ReplaceItemReferences_ItemPassed_ShouldReplaceValue(referenceReplacer, db, source, target, initialValue, expectedValue);
}
示例14: ParseFields_ReturnsExpectedValues
public void ParseFields_ReturnsExpectedValues(string fieldValue, string standardValue, string expected)
{
using (var db = new Db())
{
var testFieldId = ID.NewID;
var template = new DbTemplate("Test Template") { { testFieldId, standardValue } };
db.Add(template);
var testItem = ItemManager.CreateItem("Test", db.GetItem(ItemIDs.ContentRoot), template.ID);
if (expected != null)
{
using (new EditContext(testItem))
{
testItem[testFieldId] = expected;
}
}
var sut = new FieldReader();
testItem.Fields.ReadAll();
var result = sut.ParseFields(testItem, FieldReader.FieldReadType.Versioned).FirstOrDefault(f => f.FieldId == testFieldId.Guid);
if (expected == null) result.Should().BeNull();
else result.Value.Should().Be(expected);
}
}
示例15: Update_ItemPassed_ShouldReplaceLinks
public void Update_ItemPassed_ShouldReplaceLinks([Substitute] LinkDatabase linkDb, Db db)
{
var datasourceItemId = ID.NewID;
db.Add(new DbItem("source")
{
Children =
{
new DbItem("_Local")
{
new DbItem("DatasourceItem")
}
},
Fields =
{
"testField"
}
});
;
db.Add(new DbItem("target")
{
Children =
{
new DbItem("_Local")
{
new DbItem("DatasourceItem")
}
},
Fields =
{
"testField"
}
});
;
var sourceItem = db.GetItem("/sitecore/content/source");
var targetItem = db.GetItem("/sitecore/content/target");
var datasourceItem = db.GetItem("/sitecore/content/source/_Local/DatasourceItem");
var targetDatasourceItem = db.GetItem("/sitecore/content/target/_Local/DatasourceItem");
var itemLinks = new[]
{
new ItemLink(sourceItem, FieldIDs.LayoutField, datasourceItem, string.Empty)
};
linkDb.GetReferences(sourceItem).Returns(itemLinks.ToArray());
using (new LinkDatabaseSwitcher(linkDb))
{
using (new EditContext(targetItem))
{
targetItem["__Renderings"] = datasourceItem.ID.ToString();
}
var referenceReplacer = new UpdateLocalDatasourceReferencesService(sourceItem, targetItem);
referenceReplacer.Update();
var expectedValue = targetDatasourceItem.ID.ToString();
targetItem["__Renderings"].Should().Be(expectedValue);
}
}