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 Execute()
        {
            // Arrange
            var profiles = new[]
            {
                new AwsProfile {
                    Id = Guid.NewGuid()
                },
                new AwsProfile {
                    Id = Guid.NewGuid()
                }
            };

            ProfileRepositoryMock.Setup(x => x.FindAll()).Returns(profiles);

            // Act
            RefreshEverything.Execute();

            // Assert

            // This is good enough for now, but it isn't great because Execute calls an extension method on IBackgroundJobClient.
            // One can not verify that extension methods were called.
            BackgroundJobClientMock.Verify(x => x.Create(
                                               It.Is <Job>(j => j.Type == typeof(UpdateAllInstances)),
                                               It.IsAny <IState>()),
                                           Times.Exactly(profiles.Length));

            BackgroundJobClientMock.Verify(x => x.Create(
                                               It.Is <Job>(j => j.Type == typeof(UpdateAllStacks)),
                                               It.IsAny <IState>()),
                                           Times.Exactly(profiles.Length));
        }
        public void NextStopSooner_Ok()
        {
            // Arrange
            var stack = new Stack();

            ScheduleCalculatorMock.Setup(x => x.GetNextStart(stack)).Returns(new TimeSpan(0, 15, 0));
            ScheduleCalculatorMock.Setup(x => x.GetNextStop(stack)).Returns(new TimeSpan(0, 10, 0));

            // Act
            Kickstarter.KickstartSchedule(stack);

            // Assert
            BackgroundJobClientMock.Verify(x => x.Create(It.Is <Job>(j => j.Type == typeof(ScheduledStopStack)), It.IsAny <ScheduledState>()), Times.Once());
        }