Пример #1
0
        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);
        }
Пример #2
0
        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);
        }
Пример #3
0
        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);
        }
Пример #4
0
        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());
        }