コード例 #1
0
        public void Commit_RunStepsInTheOrderTheDependencySorterDictates()
        {
            var results = new Queue<Tuple<Type, string>>();
            Action<Type, string> capture = (t, s) =>
                results.Enqueue(new Tuple<Type, string>(t, s));

            var buildSteps = new IBuildStep[]
                {
                    new Step1(capture),
                    new Step2(capture),
                };

            var dependencySorter = Substitute.For<IBuildStepDependencySorter>();
            dependencySorter.Sort(Arg.Any<IEnumerable<IBuildStep>>())
                            .Returns(buildSteps.Reverse());

            var sut = new Builder(dependencySorter)
                            .With(buildSteps[0])
                            .With(buildSteps[1]);
            sut.Commit();

            var firstStep = results.Dequeue();
            firstStep.Item1.Should().Be(typeof (Step2));
            firstStep.Item2.Should().Be("Commit");

            var secondStep = results.Dequeue();
            secondStep.Item1.Should().Be(typeof (Step1));
            secondStep.Item2.Should().Be("Commit");

            results.Count.Should().Be(0);
        }
コード例 #2
0
        public void Commit_CallsCommitOnEachBuildStepOnce()
        {
            // Arrange
            var buildSteps = new[]
                {
                    Substitute.For<IBuildStep>(),
                    Substitute.For<IBuildStep>(),
                    Substitute.For<IBuildStep>()
                };

            var dependencySorter = Substitute.For<IBuildStepDependencySorter>();
            dependencySorter.Sort(Arg.Any<IEnumerable<IBuildStep>>())
                            .Returns(buildSteps);

            var sut = new Builder(dependencySorter)
                        .With(buildSteps[1])
                        .With(buildSteps[2])
                        .With(buildSteps[0]);

            // Act
            sut.Commit();

            // Assert
            buildSteps[0].Received(1).Commit();
            buildSteps[1].Received(1).Commit();
            buildSteps[2].Received(1).Commit();
        }