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 ExitEarlyIfInstanceIdIsNotAtAmazon() { // Arrange var profile = new AwsProfile(); AwsProfileRepositoryMock.Setup(x => x.Find(profile.Id)).Returns(profile); InstanceServiceMock.Setup(x => x.GetInstance(It.IsAny <string>())).Returns((AwsInstance)null); AwsClientFactoryMock.Setup(x => x.GetClient(profile).InstanceService).Returns(InstanceServiceMock.Object); // Act Command.Execute(profile.Id, "HoojeyId"); // Assert InstanceServiceMock.Verify(x => x.GetSecurityGroups(It.IsAny <AwsInstance>()), Times.Never); }
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)); }