本文整理汇总了C#中Db类的典型用法代码示例。如果您正苦于以下问题:C# Db类的具体用法?C# Db怎么用?C# Db使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Db类属于命名空间,在下文中一共展示了Db类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: TestIfInvalidConnectionString
public void TestIfInvalidConnectionString()
{
var db = new Db();
db.ConString = "Server=localhosts;Database=testdb;Uid=root;Pwd=;";//erroneous
db.Connect();
Assert.AreEqual(db.IsConnected(), false);
}
示例2: ShouldBeAbleToSetLayoutFieldValue
public void ShouldBeAbleToSetLayoutFieldValue()
{
ID itemId = ID.NewID;
using (var db = new Db
{
new DbItem("page", itemId)
{
new DbField(FieldIDs.LayoutField)
{
Value = "<r/>"
}
}
})
{
DbItem fakeItem = db.DataStorage.GetFakeItem(itemId);
Assert.Equal("<r/>", fakeItem.Fields[FieldIDs.LayoutField].Value);
var item = db.GetItem("/sitecore/content/page");
var layoutField = item.Fields[FieldIDs.LayoutField];
Assert.Equal("<r/>", layoutField.Value);
Assert.Equal("<r/>", item[FieldIDs.LayoutField]);
Assert.Equal("<r/>", item["__Renderings"]);
Assert.Equal("<r/>", LayoutField.GetFieldValue(item.Fields[FieldIDs.LayoutField]));
}
}
示例3: ShouldDeepCopyItem
public void ShouldDeepCopyItem()
{
// arrange
using (var db = new Db
{
new DbItem("original") { new DbItem("child") { { "Title", "Child" } } }
})
{
var original = db.GetItem("/sitecore/content/original");
var root = db.GetItem("/sitecore/content");
// act
var copy = original.CopyTo(root, "copy"); // deep is the default
// assert
copy.Should().NotBeNull();
copy.Children.Should().HaveCount(1);
var child = copy.Children.First();
child.Fields["Title"].Should().NotBeNull("'child.Fields[\"Title\"]' should not be null");
child.Fields["Title"].Value.Should().Be("Child");
child.ParentID.Should().Be(copy.ID);
child.Name.Should().Be("child");
child.Paths.FullPath.Should().Be("/sitecore/content/copy/child");
}
}
示例4: All
public IEnumerable<SalesOrderHeader> All()
{
using (var db = new Db(ConnectionString))
{
return db.SalesOrderHeader.ToList();
}
}
示例5: Deserialize_DeserializesNewItem
public void Deserialize_DeserializesNewItem()
{
using (var db = new Db())
{
var deserializer = CreateTestDeserializer(db);
var item = new FakeItem(
id: Guid.NewGuid(),
parentId: ItemIDs.ContentRoot.Guid,
templateId: _testTemplateId.Guid,
versions: new[]
{
new FakeItemVersion(1, "en", new FakeFieldValue("Hello", fieldId: _testVersionedFieldId.Guid))
});
var deserialized = deserializer.Deserialize(item);
Assert.NotNull(deserialized);
var fromDb = db.GetItem(new ID(item.Id));
Assert.NotNull(fromDb);
Assert.Equal("Hello", fromDb[_testVersionedFieldId]);
Assert.Equal(item.ParentId, fromDb.ParentID.Guid);
Assert.Equal(item.TemplateId, fromDb.TemplateID.Guid);
}
}
示例6: GetSupportedLanguages_ShouldReturlListOfSupportedLanguages
public void GetSupportedLanguages_ShouldReturlListOfSupportedLanguages(Db db, DbItem item , string rootName)
{
var contextItemId = ID.NewID;
var rootId = ID.NewID;
var template = new DbTemplate();
template.BaseIDs = new[]
{
Foundation.Multisite.Templates.Site.ID,
Templates.LanguageSettings.ID
};
var languageItem = new DbItem("en");
db.Add(languageItem);
db.Add(new DbTemplate(Foundation.Multisite.Templates.Site.ID));
db.Add(new DbTemplate(Templates.LanguageSettings.ID) {Fields = { { Templates.LanguageSettings.Fields.SupportedLanguages, languageItem.ID.ToString()} }});
db.Add(template);
var rootItem = new DbItem(rootName, rootId, template.ID){ new DbField(Templates.LanguageSettings.Fields.SupportedLanguages) { {"en", languageItem.ID.ToString()} } };
rootItem.Add(item);
db.Add(rootItem);
var contextItem = db.GetItem(item.ID);
Sitecore.Context.Item = contextItem;
var supportedLanguages = LanguageRepository.GetSupportedLanguages();
supportedLanguages.Count().Should().BeGreaterThan(0);
}
示例7: ViewMaterialsRefresh
protected void ViewMaterialsRefresh(int taskid)
{
Db obj = new Db();
string sql = string.Format("SELECT Material.MaterialName, Material.Description, Material.Filepath, Task.TaskName, Material.MaterialId FROM Material INNER JOIN Task ON Material.TaskId = Task.TaskId where Task.TaskId = {0} ", taskid);
GridView1.DataSource = obj.fetch(sql);
GridView1.DataBind();
}
示例8: State
public State(string projectToken, string target, Logger logger, string workingDirectory)
{
this.projectToken = projectToken;
this.target = (target != null) ? target : Constants.DEFAULT_TARGET;
this.logger = (logger != null) ? logger : new NullLogger();
db = new Db(this.logger, workingDirectory);
}
示例9: MapToProperty_ItemIdAsGuid_ReturnsIdAsGuid
public void MapToProperty_ItemIdAsGuid_ReturnsIdAsGuid()
{
//Assign
string targetPath = "/sitecore/content/target";
using (Db database = new Db
{
new Sitecore.FakeDb.DbItem("Target")
})
{
var mapper = new SitecoreIdMapper();
var config = new SitecoreIdConfiguration();
var property = typeof(Stub).GetProperty("GuidId");
var item = database.GetItem("/sitecore/content/target");
Assert.IsNotNull(item, "Item is null, check in Sitecore that item exists");
config.PropertyInfo = property;
mapper.Setup(new DataMapperResolverArgs(null, config));
var dataContext = new SitecoreDataMappingContext(null, item, null);
var expected = item.ID.Guid;
//Act
var value = mapper.MapToProperty(dataContext);
//Assert
Assert.AreEqual(expected, value);
}
}
示例10: GetDatasources_LocationSetByRelativeQuery_ShouldReturnSourcesFromSettingItem
public void GetDatasources_LocationSetByRelativeQuery_ShouldReturnSourcesFromSettingItem([Frozen]ISiteSettingsProvider siteSettingsProvider, [Greedy]DatasourceProvider provider, string name, string contextItemName, Db db, string settingItemName, Item item, string sourceRootName)
{
var contextItemId = ID.NewID;
var contextDbItem = new DbItem(contextItemName.Replace("-", String.Empty), contextItemId);
var rootName = sourceRootName.Replace("-", string.Empty);
var sourceRoot = new DbItem(rootName);
contextDbItem.Add(sourceRoot);
db.Add(contextDbItem);
var settingId = ID.NewID;
var settingDbItem = new DbItem(settingItemName.Replace("-", String.Empty), settingId, Templates.DatasourceConfiguration.ID)
{
new DbField(Templates.DatasourceConfiguration.Fields.DatasourceLocation)
{
{
"en", $"query:./{rootName}"
}
}
};
var contextItem = db.GetItem(contextItemId);
db.Add(settingDbItem);
var sourceRootItem = db.GetItem(sourceRoot.ID);
var settingItem = db.GetItem(settingId);
siteSettingsProvider.GetSetting(Arg.Any<Item>(), Arg.Any<string>(), Arg.Any<string>()).Returns(settingItem);
var sources = provider.GetDatasourceLocations(contextItem, name);
sources.Should().NotBeNull();
sources.Should().Contain(sourceRootItem);
}
示例11: CustomDataMapper
public void CustomDataMapper()
{
//Arrange
var templateId = ID.NewID;
using (Db database = new Db
{
new Sitecore.FakeDb.DbItem("Target", ID.NewID, templateId)
{
new Sitecore.FakeDb.DbItem("Child1")
}
})
{
var resolver = Utilities.CreateStandardResolver();
resolver.DataMapperFactory.Insert(0, () => new StubDataMapper());
var context = Context.Create(resolver);
var service = new SitecoreService(database.Database, context);
//Act
var result = service.GetItem<Stub>("/sitecore");
//Assert
Assert.AreEqual("property test", result.Property1.Value);
}
}
示例12: LazyLoading_LazyDisabledGettingParent_ReturnsConcrete
public void LazyLoading_LazyDisabledGettingParent_ReturnsConcrete()
{
//Arrange
using (Db database = new Db
{
new Sitecore.FakeDb.DbItem("Parent") {
new Sitecore.FakeDb.DbItem("Target")
}
})
{
var context = Context.Create(Utilities.CreateStandardResolver());
var fluent = new SitecoreFluentConfigurationLoader();
var parentConfig = fluent.Add<Stub2>();
var lazy1Config = fluent.Add<Stub1>();
lazy1Config.Parent(x => x.Stub2).IsNotLazy();
context.Load(fluent);
var service = new SitecoreService(database.Database, context);
//Act
var target = service.GetItem<Stub1>("/sitecore/content/parent/target");
var parent = target.Stub2;
//Assert
Assert.AreEqual(typeof(Stub2), parent.GetType());
Assert.True(parent is Stub2);
}
}
示例13: ViewAreaRefresh
protected void ViewAreaRefresh(int taskid)
{
Db obj = new Db();
string sql = string.Format("SELECT TestCaseArea.AreaId, TestCaseArea.AreaName, Task.TaskName FROM Task INNER JOIN TestCaseArea ON Task.TaskId = TestCaseArea.TaskId where Task.TaskId = {0} ", taskid);
GvViewArea.DataSource = obj.fetch(sql);
GvViewArea.DataBind();
}
示例14: ShouldNotOverrideStatisticsIfSetExplicitly
public void ShouldNotOverrideStatisticsIfSetExplicitly()
{
// arrange
const string Created = "20080407T135900";
const string CreatedBy = @"sitecore\admin";
const string Revision = "17be5e4c-19ac-4a67-b582-d72eaa761b1c";
const string Updated = "20140613T111309:635382547899455734";
const string UpdatedBy = @"sitecore\editor";
// act
using (var db = new Db
{
new DbItem("Home")
{
{ "__Created", Created }, { "__Created by", CreatedBy },
{ "__Revision", Revision },
{ "__Updated", Updated }, { "__Updated by", UpdatedBy }
}
})
{
var item = db.GetItem("/sitecore/content/home");
// assert
item["__Created"].Should().Be(Created);
item["__Created by"].Should().Be(CreatedBy);
item["__Revision"].Should().Be(Revision);
item["__Updated"].Should().Be(Updated);
item["__Updated by"].Should().Be(UpdatedBy);
}
}
示例15: Main
public static void Main(string[] args)
{
var db = new Db();
if (!db.Hotels.Any())
{
InitData(db);
}
while (true)
{
Console.WriteLine("请输入半径:");
var limit = Console.ReadLine();
var intLimit = 0;
TryParse(limit, out intLimit);
Console.WriteLine("请输入坐标:xxx,xxx");
var locs = Console.ReadLine();
var locsSps = locs?.Split(',');
if (locsSps?.Length != 2)
{
continue;
}
var point = DbGeography.PointFromText($"Point({locsSps[0]} {locsSps[1]})", 4326);
var query = db.Hotels.Where(_ => _.Geo.Distance(point) < intLimit).ToList();
Console.WriteLine("符合条件的有:");
foreach (var hotel in query)
{
Console.WriteLine($"Name:{hotel.Name},Point:{hotel.Geo.Longitude},{hotel.Geo.Latitude}");
}
}
}