Ejemplo n.º 1
0
        public static TerrificNetApplication RegisterForApplication(IUnityContainer childContainer, string hostPath, string basePath, string applicationName, string section)
        {
            try
            {
                var fileSystem = childContainer.Resolve<FileSystemProvider>().GetFileSystem(hostPath, basePath, out basePath);
                childContainer.RegisterInstance(fileSystem);

                var config = ConfigurationLoader.LoadTerrificConfiguration(basePath, fileSystem);
                var application = new TerrificNetApplication(applicationName, section, config, childContainer);

                var projectPath = PathInfo.Create("terrific.json");
                if (fileSystem.FileExists(projectPath))
                {
                    var project = Project.FromFile(new StreamReader(fileSystem.OpenRead(projectPath)).ReadToEnd(), fileSystem);
                    childContainer.RegisterInstance(project);

                    var builder = new Builder(project);
                    var pId = new ProjectItemIdentifier("app.js", "javascript_bundle");

                    builder.AddTask(new BundleTask("app.js", pId));
                    builder.AddTask(new CompileJavascriptTask(pId, "app.min.js"));
                    builder.AddTask(new BuildViewTask(project));
                    builder.AddTask(new BuildThtmlTask(project));
                }

                childContainer.RegisterInstance(application);
                RegisterForConfiguration(childContainer, config);

                return application;
            }
            catch (ConfigurationException ex)
            {
                throw new InvalidApplicationException(
                    $"Could not load the configuration for application '{applicationName}'.", ex);
            }
        }
Ejemplo n.º 2
0
        public void TestAddTarget_InvokesOnExistingItemsWhenOnChange()
        {
            var kind = "test";
            var projectItem = new ProjectItem("p2", kind);

            var project = new Project();
            project.AddItem(new ProjectItem("p1"));
            project.AddItem(projectItem);

            var target = new Mock<IBuildTask>();
            target.SetupGet(t => t.DependsOn).Returns(BuildQuery.AllFromKind(kind));
            SetupProceed(target, projectItem).Returns(new [] { new BuildTaskResult(new ProjectItemIdentifier("t1", "test2"), NullProjectItemContent.Instance)});

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

            target.VerifyAll();
        }
Ejemplo n.º 3
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);
        }
Ejemplo n.º 4
0
        //[Fact]
        public void Test_BuilderAddedLinks_CalledOnChange()
        {
            var kind = "test";
            var project = new Project();
            var observerMock = new Mock<IProjectObserver>();
            project.AddObserver(observerMock.Object);

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

            var id1 = new ProjectItemIdentifier("created", "created");

            var task = new Mock<IBuildTask>();
            task.SetupGet(p => p.DependsOn).Returns(BuildQuery.SingleFromKind(kind).Or(BuildQuery.Exact(p2.Identifier)));

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

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

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

            project.Touch(p2);

            observerMock.Verify(s => s.NotifyItemChanged(project, It.Is<ProjectItem>(i => i.Identifier.Kind == kind)), Times.Once());
        }
Ejemplo n.º 5
0
        public void Test_Many_RemoveItemTouchesGeneratedItems()
        {
            var kind = "test";
            var project = new Project();

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

            var task = new Mock<IBuildTask>();
            task.SetupGet(p => p.DependsOn).Returns(BuildQuery.AllFromKind(kind));

            var id1 = new ProjectItemIdentifier("created", "created");

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

            task.Setup(p => p.Proceed(It.Is<IEnumerable<ProjectItem>>(list => list.SequenceEqual(new [] {p1, p2}))))
                .Returns(new [] { s1 });

            task.Setup(p => p.Proceed(It.Is<IEnumerable<ProjectItem>>(list => list.SequenceEqual(new [] { p2 }))))
                .Returns(new[] { s1 });

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

            project.RemoveItem(p1);

            task.VerifyAll();
        }
Ejemplo n.º 6
0
        public void Test_OneToMany_RemoveItemRemovesGeneratedItems()
        {
            var kind = "test";
            var project = new Project();

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

            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);

            project.RemoveItem(p1);

            var result = project.GetItems();
            Assert.NotNull(result);
            Assert.Empty(result);
        }
Ejemplo n.º 7
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);
        }
Ejemplo n.º 8
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);
        }
Ejemplo n.º 9
0
        public void TestChangePropagation()
        {
            var kind = "test";
            var projectItem = new ProjectItem("p1", kind);

            var project = new Project();
            var observerMock = new Mock<IProjectObserver>();
            project.AddObserver(observerMock.Object);

            var underTest = new Builder(project);

            var kind2 = "created";
            var kind3 = "created2";

            var buildTarget = CreateBuildTarget(kind, kind2);
            var buildTarget2 = CreateBuildTarget(kind2, kind3);

            underTest.AddTask(buildTarget);
            underTest.AddTask(buildTarget2);

            project.AddItem(projectItem);

            project.Touch(projectItem);

            observerMock.Verify(s => s.NotifyItemChanged(project, It.Is<ProjectItem>(i => i.Identifier.Kind == kind)), Times.Once());
            observerMock.Verify(s => s.NotifyItemChanged(project, It.Is<ProjectItem>(i => i.Identifier.Kind == kind2)), Times.Once());
            observerMock.Verify(s => s.NotifyItemChanged(project, It.Is<ProjectItem>(i => i.Identifier.Kind == kind3)), Times.Once());
        }
Ejemplo n.º 10
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());
        }