示例#1
0
        public async Task DeployAsync_InOrder()
        {
            // Arrange
            var resourceA = new MockResource("A")
            {
                Delay = TimeSpan.FromMilliseconds(40)
            };
            var resourceB = new MockResource("B")
            {
                Delay = TimeSpan.FromMilliseconds(60)
            };
            var resourceC = new MockResource("C")
            {
                Delay = TimeSpan.FromMilliseconds(80)
            };

            resourceA.AddAntecedent(resourceB);
            resourceB.AddAntecedent(resourceC);

            var resources = new List <IDeploymentResource>
            {
                resourceA,
                resourceB,
                resourceC
            };
            var resourceProvider       = new MockDeploymentResourceProvider();
            IDeploymentContext context = new MockDeploymentContext(resourceProvider)
            {
                Parallel = false
            };
            IDeploymentManager target = new DeploymentManager();

            // Act
            await target.DeployAsync(context, resources, CancellationToken.None);

            // Assert
            Assert.AreEqual(3, resourceA.CompletedIndex);
            Assert.AreEqual(2, resourceB.CompletedIndex);
            Assert.AreEqual(1, resourceC.CompletedIndex);
        }
示例#2
0
        public async Task DeployAsync([Values(true, false)] bool parallel)
        {
            // Arrange
            TestContext.WriteLine();
            var resourceA = new MockResource("A")
            {
                Delay = TimeSpan.FromMilliseconds(10)
            };
            var resourceB = new MockResource("B")
            {
                Delay = TimeSpan.FromMilliseconds(10)
            };
            var resourceC = new MockResource("C")
            {
                Delay = TimeSpan.FromMilliseconds(10)
            };
            var resourceD = new MockResource("D")
            {
                Delay = TimeSpan.FromMilliseconds(70)
            };
            var resourceE = new MockResource("E")
            {
                Delay = TimeSpan.FromMilliseconds(10)
            };

            resourceE.AddAntecedent(resourceC);
            resourceC.AddAntecedent(resourceB);
            resourceB.AddAntecedent(resourceA);
            resourceD.AddAntecedent(resourceA);

            var resources = new List <IDeploymentResource>
            {
                resourceA,
                resourceB,
                resourceC,
                resourceD,
                resourceE
            };
            var resourceProvider = new MockDeploymentResourceProvider();

            resourceProvider.Reset();
            IDeploymentContext context = new MockDeploymentContext(resourceProvider)
            {
                Parallel = parallel
            };
            IDeploymentManager target = new DeploymentManager();

            // Act
            var stopwatch = new Stopwatch();

            stopwatch.Start();
            await target.DeployAsync(context, resources, CancellationToken.None);

            stopwatch.Stop();

            // Assert
            TestContext.WriteLine("Elapsed Time: " + stopwatch.Elapsed);
            if (parallel)
            {
                Assert.AreEqual(1, resourceA.CompletedIndex);
                Assert.AreEqual(2, resourceB.CompletedIndex);
                Assert.AreEqual(3, resourceC.CompletedIndex);
                Assert.AreEqual(5, resourceD.CompletedIndex);
                Assert.AreEqual(4, resourceE.CompletedIndex);
            }
            else
            {
                Assert.AreEqual(3, resourceA.CompletedIndex);
                Assert.AreEqual(4, resourceB.CompletedIndex);
                Assert.AreEqual(5, resourceC.CompletedIndex);
                Assert.AreEqual(2, resourceD.CompletedIndex);
                Assert.AreEqual(6, resourceE.CompletedIndex);
            }
        }