public void RemoveStaleInstances_CleanUpInstances_Ok() { // Arrange var awsInstances = new List <Amazon.EC2.Model.Instance> { new Amazon.EC2.Model.Instance { InstanceId = "One" }, }; InstanceServiceMock.Setup(x => x.GetAllInstances()).Returns(awsInstances); AwsClientFactoryMock.Setup(x => x.GetClient(Profile).InstanceService).Returns(InstanceServiceMock.Object); var instances = new List <Instance> { new Instance { ResourceId = "One", OwnerProfileId = Profile.Id }, new Instance { ResourceId = "Two", NeedsRefreshing = true, OwnerProfileId = Profile.Id }, new Instance { ResourceId = "Three", OwnerProfileId = Profile.Id } }; StackRepositoryMock.Setup(x => x.FindAll()).Returns(instances); // Act Command.Execute(Profile.Id); // Assert BackgroundJobClientMock.Verify(x => x.Create(It.IsAny <Job>(), It.IsAny <IState>()), Times.Once()); }
public void Index() { // Arrange Guid stackId = Guid.NewGuid(); Guid instanceIdOne = Guid.NewGuid(); var instanceOne = new Instance { Name = "InstanceOne" }; Guid instanceIdTwo = Guid.NewGuid(); var instanceTwo = new Instance { Name = "InstanceTwo" }; var instanceIds = new List <Guid> { instanceIdOne, instanceIdTwo }; var stack = new Stack { Id = stackId, Name = "hoojey", InstanceIds = instanceIds }; StackRepositoryMock.Setup(x => x.Find(stackId)).Returns(stack); InstanceRepositoryMock.Setup(x => x.Find(instanceIdOne)).Returns(instanceOne); InstanceRepositoryMock.Setup(x => x.Find(instanceIdTwo)).Returns(instanceTwo); var instanceModels = new List <InstanceOverviewViewModel> { new InstanceOverviewViewModel { Name = instanceOne.Name }, new InstanceOverviewViewModel { Name = instanceTwo.Name } }; var expectedModel = new StackInstancesViewModel { StackName = stack.Name, Instances = instanceModels }; MappingEngineMock.Setup(engine => engine .Map <Instance, InstanceOverviewViewModel>(instanceOne)) .Returns(instanceModels[0]); MappingEngineMock.Setup(engine => engine .Map <Instance, InstanceOverviewViewModel>(instanceTwo)) .Returns(instanceModels[1]); // Act var actionResult = Controller.Index(stack.Id) as ViewResultBase; // Assert (actionResult.Model as StackInstancesViewModel).ShouldBeEquivalentTo(expectedModel, options => options.Excluding(vm => vm.StackRecordId)); }
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)); }
public void RemoveStaleInstances() { // Arrange var awsInstances = new List <Amazon.EC2.Model.Instance> { new Amazon.EC2.Model.Instance { InstanceId = "One" }, new Amazon.EC2.Model.Instance { InstanceId = "Two" }, new Amazon.EC2.Model.Instance { InstanceId = "Five" }, }; InstanceServiceMock.Setup(x => x.GetAllInstances()).Returns(awsInstances); AwsClientFactoryMock.Setup(x => x.GetClient(Profile).InstanceService).Returns(InstanceServiceMock.Object); var instances = new List <Instance> { new Instance { ResourceId = "One", OwnerProfileId = Profile.Id }, new Instance { ResourceId = "Two", OwnerProfileId = Profile.Id }, new Instance { ResourceId = "Three", OwnerProfileId = Profile.Id }, new Instance { ResourceId = "Four", OwnerProfileId = Profile.Id } }; StackRepositoryMock.Setup(x => x.FindAll()).Returns(instances); // Act Command.Execute(Profile.Id); // Assert StackRepositoryMock.Verify(x => x.Delete(It.Is <Instance>(s => s.ResourceId == "Three"))); StackRepositoryMock.Verify(x => x.Delete(It.Is <Instance>(s => s.ResourceId == "Four"))); // Ensure no stacks were deleted that should not have been StackRepositoryMock.Verify(x => x.Delete(It.IsAny <Instance>()), Times.Exactly(2)); }
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)); }