Exemplo n.º 1
0
        public void ExitEarlyIfStackIsNotAtAmazon()
        {
            // Arrange
            StackServiceMock.Setup(x => x.GetStack(It.IsAny <string>())).Returns((AwsStack)null);
            AwsClientFactoryMock.Setup(x => x.GetClient(Profile).StackService).Returns(StackServiceMock.Object);

            // Act
            Command.Execute(Profile.Id, "HoojeyStack");

            // Assert
            StackRepositoryMock.Verify(x => x.FindAll(), Times.Never);
        }
Exemplo n.º 2
0
        public void RemoveStaleStacks()
        {
            // Arrange
            var awsStacks = new List <Amazon.CloudFormation.Model.Stack>
            {
                new Amazon.CloudFormation.Model.Stack {
                    StackId = "One"
                },
                new Amazon.CloudFormation.Model.Stack {
                    StackId = "Two"
                },
                new Amazon.CloudFormation.Model.Stack {
                    StackId = "Five"
                },
            };

            StackServiceMock.Setup(x => x.GetAllStacks()).Returns(awsStacks);

            AwsClientFactoryMock.Setup(x => x.GetClient(Profile).StackService).Returns(StackServiceMock.Object);

            var stacks = new List <Stack>
            {
                new Stack {
                    ResourceId = "One", OwnerProfileId = Profile.Id
                },
                new Stack {
                    ResourceId = "Two", OwnerProfileId = Profile.Id
                },
                new Stack {
                    ResourceId = "Three", OwnerProfileId = Profile.Id
                },
                new Stack {
                    ResourceId = "Four", OwnerProfileId = Profile.Id
                }
            };

            StackRepositoryMock.Setup(x => x.FindAll()).Returns(stacks);

            // Act
            Command.Execute(Profile.Id);

            // Assert
            StackRepositoryMock.Verify(x => x.Delete(It.Is <Stack>(s => s.ResourceId == "Three")));
            StackRepositoryMock.Verify(x => x.Delete(It.Is <Stack>(s => s.ResourceId == "Four")));

            // Ensure no stacks were deleted that should not have been
            StackRepositoryMock.Verify(x => x.Delete(It.IsAny <Stack>()), Times.Exactly(2));
        }
Exemplo n.º 3
0
        public void RemoveStaleStacks_DontRemoveStacksThatNeedRefreshing()
        {
            // Arrange
            var awsStacks = new List <Amazon.CloudFormation.Model.Stack>
            {
                new Amazon.CloudFormation.Model.Stack {
                    StackId = "One"
                }
            };

            StackServiceMock.Setup(x => x.GetAllStacks()).Returns(awsStacks);

            AwsClientFactoryMock.Setup(x => x.GetClient(Profile).StackService).Returns(StackServiceMock.Object);

            var stacks = new List <Stack>
            {
                new Stack {
                    ResourceId = "One", OwnerProfileId = Profile.Id
                },
                new Stack {
                    ResourceId = "Two", NeedsRefreshing = false, OwnerProfileId = Profile.Id
                },
                new Stack {
                    Id = Guid.NewGuid(), NeedsRefreshing = true, OwnerProfileId = Profile.Id
                }
            };

            StackRepositoryMock.Setup(x => x.FindAll()).Returns(stacks);

            // Act
            Command.Execute(Profile.Id);

            // Assert
            StackRepositoryMock.Verify(x => x.Delete(It.Is <Stack>(s => s.ResourceId == "Two")));

            StackRepositoryMock.Verify(x => x.Delete(It.IsAny <Stack>()), Times.Exactly(1));
        }