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


C# Project.GetItemById方法代码示例

本文整理汇总了C#中Project.GetItemById方法的典型用法代码示例。如果您正苦于以下问题:C# Project.GetItemById方法的具体用法?C# Project.GetItemById怎么用?C# Project.GetItemById使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Project的用法示例。


在下文中一共展示了Project.GetItemById方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: TestBuilderSingleItemOnAddWithBuildInBackgroundOption

        public async Task TestBuilderSingleItemOnAddWithBuildInBackgroundOption()
        {
            var kind = "test";
            var projectItem = new ProjectItem("p1", kind);

            var project = new Project();

            var target = new Mock<IBuildTask>();
            const string targetName = "test";
            target.SetupGet(t => t.Name).Returns(targetName);
            target.SetupGet(t => t.DependsOn).Returns(BuildQuery.SingleFromKind(kind));
            target.SetupGet(t => t.Options).Returns(BuildOptions.BuildInBackground);

            var id = new ProjectItemIdentifier("gugus", "created");
            const string contentString = "test";
            var source = new BuildTaskResult(id, new ProjectItemContentFromAction(() => GenerateStreamFromString(contentString)));
            SetupProceed(target, projectItem).Returns(new [] { source });

            var underTest = new Builder(project);
            underTest.AddTask(target.Object);

            project.AddItem(new ProjectItem("p2"));
            project.AddItem(projectItem);

            var generatedItem = project.GetItemById(id);
            Assert.NotNull(generatedItem);
            Assert.Equal(id, generatedItem.Identifier);

            var stream = await generatedItem.OpenRead();
            //Second Stream
            var stream2 = await generatedItem.OpenRead();

            AssertStream(stream, contentString);
            AssertStream(stream2, contentString);

            var links = projectItem.GetLinkedItems();
            Assert.NotNull(links);

            var linkList = links.ToList();
            Assert.Equal(1, linkList.Count);

            Assert.Equal(generatedItem, linkList[0].ProjectItem);
            Assert.Equal(targetName, linkList[0].Description.Name);
        }
开发者ID:TerrificNet,项目名称:TerrificNet,代码行数:44,代码来源:BuilderTest.cs

示例2: TestManyToOne

        public void TestManyToOne()
        {
            var kind = "test";
            var project = new Project();

            AddAndCreateItem(kind, project, "p1");
            AddAndCreateItem(kind, project, "p2");
            AddAndCreateItem(kind, project, "p3");

            var task = new Mock<IBuildTask>();
            task.SetupGet(p => p.DependsOn).Returns(BuildQuery.AllFromKind(kind));
            var id = new ProjectItemIdentifier("created", "created");
            task.Setup(p => p.Proceed(It.Is<IEnumerable<ProjectItem>>(list => list.SequenceEqual(project.GetItems()))))
                .Returns(new [] { new BuildTaskResult(id, NullProjectItemContent.Instance) });

            var builder = new Builder(project);
            builder.AddTask(task.Object);

            task.Verify(p => p.Proceed(It.IsAny<IEnumerable<ProjectItem>>()), Times.Once());

            var result = project.GetItemById(id);
            Assert.NotNull(result);

            var linkedItems = result.GetLinkedItems();
            Assert.NotNull(linkedItems);

            var linkedItemsList = linkedItems.ToList();
            Assert.Equal(3, linkedItemsList.Count);
        }
开发者ID:TerrificNet,项目名称:TerrificNet,代码行数:29,代码来源:BuilderTest.cs

示例3: TestOneToMany

        public void TestOneToMany()
        {
            var kind = "test";
            var project = new Project();

            var p1 = AddAndCreateItem(kind, project, "p1");
            AddAndCreateItem(kind, project, "p2");
            AddAndCreateItem(kind, project, "p3");

            var task = new Mock<IBuildTask>();
            task.SetupGet(p => p.DependsOn).Returns(BuildQuery.SingleFromKind(kind));
            var id1 = new ProjectItemIdentifier("created", "created");
            var id2 = new ProjectItemIdentifier("created2", "created");

            var s1 = new BuildTaskResult(id1, NullProjectItemContent.Instance);
            var s2 = new BuildTaskResult(id2, NullProjectItemContent.Instance);

            SetupProceed(task, p1).Returns(new [] { s1, s2 });

            var builder = new Builder(project);
            builder.AddTask(task.Object);

            var result = project.GetItemById(id1);
            Assert.NotNull(result);

            var linkedItems = result.GetLinkedItems();
            Assert.NotNull(linkedItems);

            var linkedItemsList = linkedItems.ToList();
            Assert.Equal(1, linkedItemsList.Count);

            var otherItem = linkedItemsList[0].ProjectItem.GetLinkedItems();
            Assert.NotNull(otherItem);

            var otherItemList = otherItem.ToList();
            Assert.Equal(2, otherItemList.Count);
        }
开发者ID:TerrificNet,项目名称:TerrificNet,代码行数:37,代码来源:BuilderTest.cs

示例4: TestBuilderSingleItemOnAddWithBuildOnRequestOption

        public void TestBuilderSingleItemOnAddWithBuildOnRequestOption()
        {
            var kind = "test";
            var projectItem = new ProjectItem("p1", kind);

            var project = new Project();

            var id = new ProjectItemIdentifier("gugus", "created");

            var content = new Mock<IProjectItemContent>();
            content.Setup(s => s.ReadAsync()).Returns(GenerateStreamFromString("test"));

            var target = new Mock<IBuildTask>();
            const string targetName = "test";
            target.SetupGet(t => t.Name).Returns(targetName);
            target.SetupGet(t => t.DependsOn).Returns(BuildQuery.SingleFromKind(kind));
            target.SetupGet(t => t.Options).Returns(BuildOptions.BuildOnRequest);
            SetupProceed(target, projectItem).Returns(new [] { new BuildTaskResult(id, content.Object)});

            var underTest = new Builder(project);
            underTest.AddTask(target.Object);

            project.AddItem(new ProjectItem("p2"));
            project.AddItem(projectItem);

            content.Verify(t => t.ReadAsync(), Times.Never());

            var generatedItem = project.GetItemById(id);
            Assert.NotNull(generatedItem);
            Assert.Equal(id, generatedItem.Identifier);

            generatedItem.OpenRead();
            content.Verify(t => t.ReadAsync(), Times.Once());

            generatedItem.OpenRead();
            content.Verify(t => t.ReadAsync(), Times.Once());
        }
开发者ID:TerrificNet,项目名称:TerrificNet,代码行数:37,代码来源:BuilderTest.cs


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