

using System.Threading.Tasks;
using Xunit;

namespace Compute.Samples.Tests
{
    [Collection(nameof(ComputeFixture))]
    public class ListAllInstancesAsyncTest
    {
        private readonly ComputeFixture _fixture;
        private readonly CreateInstanceAsyncSample _createSample = new CreateInstanceAsyncSample();
        private readonly ListAllInstancesAsyncSample _listSample = new ListAllInstancesAsyncSample();

        public ListAllInstancesAsyncTest(ComputeFixture fixture) => _fixture = fixture;

        [Fact]
        public async Task ListsInstance()
        {
            string machineName = _fixture.GenerateMachineName();
            // Let's use the create instance sample because that polls until completed.
            await _createSample.CreateInstanceAsync(_fixture.ProjectId, _fixture.Zone, machineName, _fixture.MachineType, _fixture.DiskImage, _fixture.DiskSizeGb);

            var instances = await _listSample.ListAllInstancesAsync(_fixture.ProjectId);

            Assert.Contains(instances, i => machineName == i.Name);
        }
    }
}
