Ejemplo n.º 1
0
        public void ShouldCleanDependenciesAndTheirDependenciesAfterBuildIfMarkedSo()
        {
            var artefacts = new HashSet <string>();

            var d     = new FakeArtefactTaskWithDependencies(artefacts, "d");
            var a     = new FakeArtefactTaskWithDependencies(artefacts, "a");
            var b     = new FakeArtefactTaskWithDependencies(artefacts, "b", new[] { new TaskDependency(d) });
            var cDeps = new[] { new TaskDependency(a), new TaskDependency(b)
                                {
                                    CleanAfterBuild = true
                                } };
            var c = new FakeArtefactTaskWithDependencies(artefacts, "c", cDeps);

            ITargetBuilderBounce bounce = GetBounce();

            var invoker       = new TargetInvoker(bounce);
            var bounceCommand = new BounceCommandParser().BuildAndClean;

            invoker.Invoke(bounceCommand, c);
            invoker.CleanAfterBuild(bounceCommand);

            Assert.That(artefacts, Has.Member("a"));
            Assert.That(artefacts, Has.No.Member("b"));
            Assert.That(b.Invoked);
            Assert.That(artefacts, Has.Member("c"));
            Assert.That(artefacts, Has.No.Member("d"));
            Assert.That(d.Invoked);
        }
Ejemplo n.º 2
0
            public T Multiply <T>(T x, T y)
            {
                var method             = typeof(ICalculator).GetMethod("Multiply");
                var interceptor        = _interceptors.GetInterceptor(method);
                var invoker            = new TargetInvoker <T>(_target);
                InterceptDelegate next = new InterceptDelegate(invoker.Invoke);
                var arguments          = new object[] { x, y };
                var context            = new DefaultInvocationContext(method, this, _target, arguments);

                interceptor(next)(context).Wait();
                return((T)context.ReturnValue);
            }
Ejemplo n.º 3
0
        public void EachTaskShouldDescribeThemSelvesBeforeBuild()
        {
            var dependent = new FakeDescribingTask("one");
            var dependency = new FakeDescribingTask("two");
            dependent.Dependencies = new[] {new TaskDependency(dependency)};

            ITargetBuilderBounce bounce = GetBounce();

            var builder = new TargetInvoker(bounce);
            builder.Invoke(new BounceCommandParser().Build, dependent);

            Assert.That(bounce.DescriptionOutput.ToString(), Is.EqualTo(@"two;one;"));
        }
Ejemplo n.º 4
0
        public void EachTaskShouldDescribeThemSelvesBeforeBuild()
        {
            var dependent  = new FakeDescribingTask("one");
            var dependency = new FakeDescribingTask("two");

            dependent.Dependencies = new[] { new TaskDependency(dependency) };

            ITargetBuilderBounce bounce = GetBounce();

            var builder = new TargetInvoker(bounce);

            builder.Invoke(new BounceCommandParser().Build, dependent);

            Assert.That(bounce.DescriptionOutput.ToString(), Is.EqualTo(@"two;one;"));
        }
Ejemplo n.º 5
0
        public void ShouldBuildDependenciesBeforeDependencts()
        {
            var dependent = new Mock<ITask>();
            var dependency = new Mock<ITask>();
            ITargetBuilderBounce bounce = GetBounce();

            var buildActions = new StringWriter();

            dependent.Setup(d => d.Dependencies).Returns(new[] {new TaskDependency (dependency.Object)});
            var bounceCommand = new BounceCommandParser().Build;
            dependent.Setup(d => d.Invoke(bounceCommand, bounce)).Callback(() => buildActions.Write("build dependent;"));
            dependency.Setup(d => d.Invoke(bounceCommand, bounce)).Callback(() => buildActions.Write("build dependency;"));

            var builder = new TargetInvoker(bounce);
            builder.Invoke(bounceCommand, dependent.Object);

            Assert.That(buildActions.ToString(), Is.EqualTo(@"build dependency;build dependent;"));
        }
Ejemplo n.º 6
0
        public void ShouldOnlyBuildTasksOnceEvenIfTheyAreDependedUponTwice()
        {
            var all                     = new Mock <IObsoleteTask>();
            var dependent1              = new Mock <IObsoleteTask>();
            var dependent2              = new Mock <IObsoleteTask>();
            var twiceADependency        = new Mock <IObsoleteTask>();
            ITargetBuilderBounce bounce = GetBounce();

            all.Setup(d => d.Dependencies).Returns(new[] { new TaskDependency(dependent1.Object), new TaskDependency(dependent2.Object) });
            dependent1.Setup(d => d.Dependencies).Returns(new[] { new TaskDependency(twiceADependency.Object) });
            dependent2.Setup(d => d.Dependencies).Returns(new[] { new TaskDependency(twiceADependency.Object) });

            var invoker       = new TargetInvoker(bounce);
            var bounceCommand = new BounceCommandParser().Build;

            invoker.Invoke(bounceCommand, all.Object);

            twiceADependency.Verify(t => t.Invoke(bounceCommand, bounce), Times.Once());
        }
Ejemplo n.º 7
0
        public void ShouldBuildDependenciesBeforeDependencts()
        {
            var dependent  = new Mock <IObsoleteTask>();
            var dependency = new Mock <IObsoleteTask>();
            ITargetBuilderBounce bounce = GetBounce();

            var buildActions = new StringWriter();

            dependent.Setup(d => d.Dependencies).Returns(new[] { new TaskDependency(dependency.Object) });
            var bounceCommand = new BounceCommandParser().Build;

            dependent.Setup(d => d.Invoke(bounceCommand, bounce)).Callback(() => buildActions.Write("build dependent;"));
            dependency.Setup(d => d.Invoke(bounceCommand, bounce)).Callback(() => buildActions.Write("build dependency;"));

            var builder = new TargetInvoker(bounce);

            builder.Invoke(bounceCommand, dependent.Object);

            Assert.That(buildActions.ToString(), Is.EqualTo(@"build dependency;build dependent;"));
        }
Ejemplo n.º 8
0
        public void ShouldNotCleanDepsIfMarkedCleanAfterBuildButAlsoDependedUponElsewhere()
        {
            var artefacts = new HashSet <string>();

            var b     = new FakeArtefactTaskWithDependencies(artefacts, "b");
            var cDeps = new[] { new TaskDependency(b), new TaskDependency(b)
                                {
                                    CleanAfterBuild = true
                                } };
            var c = new FakeArtefactTaskWithDependencies(artefacts, "c", cDeps);

            ITargetBuilderBounce bounce = GetBounce();

            var invoker = new TargetInvoker(bounce);

            invoker.Invoke(new BounceCommandParser().Build, c);

            Assert.That(artefacts, Has.Member("b"));
            Assert.That(artefacts, Has.Member("c"));
        }
Ejemplo n.º 9
0
        public void ShouldCleanDependenciesAndTheirDependenciesAfterBuildIfMarkedSo()
        {
            var artefacts = new HashSet<string>();

            var d = new FakeArtefactTaskWithDependencies(artefacts, "d");
            var a = new FakeArtefactTaskWithDependencies(artefacts, "a");
            var b = new FakeArtefactTaskWithDependencies(artefacts, "b", new[] {new TaskDependency(d)});
            var cDeps = new[] {new TaskDependency(a), new TaskDependency(b) {CleanAfterBuild = true}};
            var c = new FakeArtefactTaskWithDependencies(artefacts, "c", cDeps);

            ITargetBuilderBounce bounce = GetBounce();

            var invoker = new TargetInvoker(bounce);
            var bounceCommand = new BounceCommandParser().BuildAndClean;
            invoker.Invoke(bounceCommand, c);
            invoker.CleanAfterBuild(bounceCommand);

            Assert.That(artefacts, Has.Member("a"));
            Assert.That(artefacts, Has.No.Member("b"));
            Assert.That(b.Invoked);
            Assert.That(artefacts, Has.Member("c"));
            Assert.That(artefacts, Has.No.Member("d"));
            Assert.That(d.Invoked);
        }
Ejemplo n.º 10
0
        public void ShouldNotCleanDepsIfMarkedCleanAfterBuildButAlsoDependedUponElsewhere()
        {
            var artefacts = new HashSet<string>();

            var b = new FakeArtefactTaskWithDependencies(artefacts, "b");
            var cDeps = new[] {new TaskDependency(b), new TaskDependency (b) {CleanAfterBuild = true}};
            var c = new FakeArtefactTaskWithDependencies(artefacts, "c", cDeps);

            ITargetBuilderBounce bounce = GetBounce();

            var invoker = new TargetInvoker(bounce);
            invoker.Invoke(new BounceCommandParser().Build, c);

            Assert.That(artefacts, Has.Member("b"));
            Assert.That(artefacts, Has.Member("c"));
        }
Ejemplo n.º 11
0
        public void ShouldOnlyCleanTasksOnceEvenIfTheyAreDependedUponTwice()
        {
            var all = new Mock<ITask>();
            var dependent1 = new Mock<ITask>();
            var dependent2 = new Mock<ITask>();
            var twiceADependency = new Mock<ITask>();
            ITargetBuilderBounce bounce = GetBounce();

            all.Setup(d => d.Dependencies).Returns(new[] {new TaskDependency(dependent1.Object), new TaskDependency (dependent2.Object) });
            dependent1.Setup(d => d.Dependencies).Returns(new[] {new TaskDependency (twiceADependency.Object) });
            dependent2.Setup(d => d.Dependencies).Returns(new[] {new TaskDependency (twiceADependency.Object) });

            var invoker = new TargetInvoker(bounce);
            var bounceCommand = new BounceCommandParser().Clean;
            invoker.Invoke(bounceCommand, all.Object);

            twiceADependency.Verify(t => t.Invoke(bounceCommand, bounce), Times.Once());
        }
Ejemplo n.º 12
0
 public FakeTargetBuilderBounce()
 {
     DescriptionOutput = new StringWriter();
     TargetInvoker = new TargetInvoker(this);
 }
Ejemplo n.º 13
0
 public FakeTargetBuilderBounce()
 {
     DescriptionOutput = new StringWriter();
     TargetInvoker     = new TargetInvoker(this);
 }