当前位置: 首页>>代码示例>>C#>>正文


C# Db类代码示例

本文整理汇总了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);
 }
开发者ID:rcdosado,项目名称:addressbook,代码行数:7,代码来源:DbTests.cs

示例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]));
      }
    }
开发者ID:sergeyshushlyapin,项目名称:Sitecore.FakeDb,代码行数:29,代码来源:LayoutFieldTest.cs

示例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");
      }
    }
开发者ID:dharnitski,项目名称:Sitecore.FakeDb,代码行数:26,代码来源:DbItemCopyingTest.cs

示例4: All

 public IEnumerable<SalesOrderHeader> All()
 {
     using (var db = new Db(ConnectionString))
     {
         return db.SalesOrderHeader.ToList();
     }
 }
开发者ID:tdhung80,项目名称:RawDataAccessBencher,代码行数:7,代码来源:SalesOrderHeaderRepository.cs

示例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);
			}
		}
开发者ID:OlegJytnik,项目名称:Rainbow,代码行数:27,代码来源:DefaultDeserializerTests.cs

示例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);
    }
开发者ID:robearlam,项目名称:Habitat,代码行数:26,代码来源:LanguageRepositoryTests.cs

示例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();
 }
开发者ID:sowmyachakrapani,项目名称:BugTrackingSystem,代码行数:7,代码来源:ViewMaterials.aspx.cs

示例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);
 }
开发者ID:Infinario,项目名称:c-sharp-sdk,代码行数:7,代码来源:State.cs

示例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);
            }
        }
开发者ID:mikeedwards83,项目名称:Glass.Mapper,代码行数:31,代码来源:SitecoreIdMapperFixture.cs

示例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);
    }
开发者ID:alinulms,项目名称:Habitat,代码行数:28,代码来源:DatasourceProviderTests.cs

示例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);
            }
        }
开发者ID:mikeedwards83,项目名称:Glass.Mapper,代码行数:25,代码来源:Issue145.cs

示例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);
            }
        }
开发者ID:mikeedwards83,项目名称:Glass.Mapper,代码行数:29,代码来源:LazyLoadingFixture.cs

示例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();
 }
开发者ID:sowmyachakrapani,项目名称:BugTrackingSystem,代码行数:7,代码来源:ViewArea.aspx.cs

示例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);
      }
    }
开发者ID:dharnitski,项目名称:Sitecore.FakeDb,代码行数:30,代码来源:StatisticsFieldsTest.cs

示例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}");
         }
     }
     
 }
开发者ID:panyufeng,项目名称:EFGeoDemo,代码行数:30,代码来源:Program.cs


注:本文中的Db类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。