private void AddExistingInstance(
            InstanceSetHistoryBuilder builder,
            int count,
            DateTime lastSeen,
            Tenancies tenancy)
        {
            for (int i = 0; i < count; i++)
            {
                instanceIdSequence++;

                var locator = new InstanceLocator("project", "zone", $"instance-{instanceIdSequence}");
                builder.AddExistingInstance(
                    instanceIdSequence,
                    locator,
                    new ImageLocator("project", $"image-{instanceIdSequence}"),
                    InstanceState.Running,
                    lastSeen,
                    tenancy,
                    tenancy == Tenancies.SoleTenant
                        ? "server-1"
                        : null,
                    null);
                builder.GetInstanceHistoryBuilder(instanceIdSequence)
                .OnStart(BaselineTime.AddDays(i), locator);
            }
        }
        private void AddExistingInstance(
            InstanceSetHistoryBuilder builder,
            int count,
            DateTime lastSeen,
            Tenancies tenancy)
        {
            for (int i = 0; i < count; i++)
            {
                instanceIdSequence++;

                var locator = new InstanceLocator("project", "zone", $"instance-{instanceIdSequence}");
                builder.AddExistingInstance(
                    instanceIdSequence,
                    locator,
                    new ImageLocator("project", $"image-{instanceIdSequence}"),
                    InstanceState.Running,
                    lastSeen,
                    tenancy,
                    tenancy == Tenancies.SoleTenant
                        ? "server-1"
                        : null,
                    null);

                var instanceBuilder = builder.GetInstanceHistoryBuilder(instanceIdSequence);
                if (tenancy == Tenancies.SoleTenant)
                {
                    // Add sole tenant placement.
                    instanceBuilder.OnSetPlacement("server-1", null, lastSeen.AddHours(-1));
                }

                // Add fleet placement.
                instanceBuilder.OnStart(BaselineTime.AddDays(i), locator);
            }
        }
        private void AddExistingInstance(
            InstanceSetHistoryBuilder builder,
            int count,
            Tenancies tenancy)
        {
            for (int i = 0; i < count; i++)
            {
                instanceIdSequence++;
                builder.AddExistingInstance(
                    instanceIdSequence,
                    new InstanceLocator("project", "zone", $"instance-{instanceIdSequence}"),
                    new ImageLocator("project", $"image-{instanceIdSequence}"),
                    InstanceState.Running,
                    BaselineTime.AddDays(i),
                    tenancy);

                var instanceBuilder = builder.GetInstanceHistoryBuilder(instanceIdSequence);
                if (tenancy == Tenancies.SoleTenant)
                {
                    // Add sole tenant placement.
                    instanceBuilder.OnSetPlacement("server-1", BaselineTime);
                }

                // Add fleet placement.
                instanceBuilder.OnStop(
                    BaselineTime.AddDays(-1),
                    new InstanceLocator("project", "zone", $"instance-{instanceIdSequence}"));
                instanceBuilder.OnStart(
                    BaselineTime.AddDays(-2),
                    new InstanceLocator("project", "zone", $"instance-{instanceIdSequence}"));
            }
        }
        private void AddExistingInstance(
            InstanceSetHistoryBuilder builder,
            int count,
            Tenancies tenancy)
        {
            for (int i = 0; i < count; i++)
            {
                instanceIdSequence++;

                builder.AddExistingInstance(
                    instanceIdSequence,
                    new InstanceLocator("project", "zone", $"instance-{instanceIdSequence}"),
                    new ImageLocator("project", $"image-{instanceIdSequence}"),
                    InstanceState.Running,
                    BaselineTime.AddDays(i),
                    tenancy);
            }
        }
        public void WhenInstanceAdded_ThenInstanceIncludedInSet()
        {
            var b = new InstanceSetHistoryBuilder(
                new DateTime(2019, 12, 1, 0, 0, 0, DateTimeKind.Utc),
                new DateTime(2020, 1, 1, 0, 0, 0, DateTimeKind.Utc));

            b.AddExistingInstance(
                1,
                SampleReference,
                SampleImage,
                InstanceState.Running,
                DateTime.Now,
                Tenancies.Fleet);

            var set = b.Build();

            Assert.AreEqual(1, set.Instances.Count());
            Assert.AreEqual(1, set.Instances.First().InstanceId);
        }
        public void WhenSoleTenantInstanceAdded_ThenInstanceIncludedInSet()
        {
            var b = new InstanceSetHistoryBuilder(
                new DateTime(2019, 12, 1, 0, 0, 0, DateTimeKind.Utc),
                new DateTime(2020, 1, 1, 0, 0, 0, DateTimeKind.Utc));

            b.AddExistingInstance(
                1,
                SampleReference,
                SampleImage,
                InstanceState.Running,
                DateTime.Now,
                Tenancies.SoleTenant,
                "server-1",
                new NodeTypeLocator("project-1", "zone-1", "type-1"));

            var set = b.Build();

            Assert.AreEqual(1, set.Instances.Count());
            Assert.AreEqual(1, set.Instances.First().InstanceId);
            Assert.AreEqual("server-1", set.Instances.First().Placements.First().ServerId);
            Assert.AreEqual("type-1", set.Instances.First().Placements.First().NodeType.Name);
        }