public async Task GetDedicatedHostForVmPlacementTest()
        {
            var loggerMock                    = new Mock <ILogger <DedicatedHostEngine> >();
            var configurationMock             = new Mock <Config>();
            var dedicatedHostSelectorMock     = new Mock <IDedicatedHostSelector>();
            var syncProviderMock              = new Mock <ISyncProvider>();
            var dedicatedHostStateManagerMock = new Mock <IDedicatedHostStateManager>();
            var dhmComputeClientMock          = new Mock <IDhmComputeClient>();
            var computeManagementClientMock   = new Mock <IComputeManagementClient>();
            var mockDhg = new DedicatedHostGroup(Location, PlatformFaultDomainCount, null, HostGroupName);

            _dedicatedHostGroupResponseMock = new Microsoft.Rest.Azure.AzureOperationResponse <DedicatedHostGroup>
            {
                Body = mockDhg,
            };
            _dedicatedHostGroupResponseMock.Body.Location = Location;
            _dedicatedHostGroupResponseMock.Body.PlatformFaultDomainCount = PlatformFaultDomainCount;
            computeManagementClientMock
            .Setup(
                s => s.DedicatedHostGroups.CreateOrUpdateWithHttpMessagesAsync(
                    It.IsAny <string>(),
                    It.IsAny <string>(),
                    It.IsAny <DedicatedHostGroup>(),
                    null,
                    It.IsAny <CancellationToken>()))
            .ReturnsAsync(_dedicatedHostGroupResponseMock);
            dhmComputeClientMock.Setup(s =>
                                       s.GetComputeManagementClient(It.IsAny <string>(), It.IsAny <AzureCredentials>(),
                                                                    It.IsAny <AzureEnvironment>()))
            .ReturnsAsync(computeManagementClientMock.Object);
            var dedicatedHostList =
                JsonConvert.DeserializeObject <List <DedicatedHost> >(
                    File.ReadAllText(@"TestData\dedicatedHostsInput1.json"));

            dedicatedHostSelectorMock
            .Setup(
                s => s.ListDedicatedHosts(Token, AzureEnvironment.AzureUSGovernment, TenantId, SubscriptionId, ResourceGroup, HostGroupName))
            .ReturnsAsync(dedicatedHostList);
            dedicatedHostStateManagerMock.Setup(s => s.IsHostAtCapacity(It.IsAny <string>())).Returns(false);
            dedicatedHostSelectorMock
            .Setup(
                s => s.SelectDedicatedHost(Token, AzureEnvironment.AzureUSGovernment, TenantId, SubscriptionId, ResourceGroup, HostGroupName, VmSize))
            .ReturnsAsync("/subscriptions/6e412d70-9128-48a7-97b4-04e5bd35cefc/resourceGroups/63296244-ce2c-46d8-bc36-3e558792fbee/providers/Microsoft.Compute/hostGroups/citrix-dhg/hosts/20887a6e-0866-4bae-82b7-880839d9e76b");

            var dedicatedHostEngine = new DedicatedHostEngine(
                loggerMock.Object,
                configurationMock.Object,
                dedicatedHostSelectorMock.Object,
                syncProviderMock.Object,
                dedicatedHostStateManagerMock.Object,
                dhmComputeClientMock.Object);
            var host = await dedicatedHostEngine.GetDedicatedHostForVmPlacement(Token, AzureEnvironment.AzureUSGovernment, TenantId, SubscriptionId,
                                                                                ResourceGroup, HostGroupName, VmSize, "test-vm", Location);

            Assert.Equal(host, "/subscriptions/6e412d70-9128-48a7-97b4-04e5bd35cefc/resourceGroups/63296244-ce2c-46d8-bc36-3e558792fbee/providers/Microsoft.Compute/hostGroups/citrix-dhg/hosts/20887a6e-0866-4bae-82b7-880839d9e76b");
        }
        public async Task PrepareDedicatedHostGroup_Scenarios_Test(string location, int platformFDCount, int?platformFD, int vmInstanceToCreate, List <DedicatedHost> existingHosts, List <DedicatedHost> expectedHostsToBeCreated)
        {
            // Arrange
            var hostGroupName                 = "TestDH";
            var loggerMock                    = new Mock <ILogger <DedicatedHostEngine> >();
            var config                        = new Config();
            var dedicatedHostSelectorMock     = new Mock <IDedicatedHostSelector>();
            var syncProviderMock              = new Mock <ISyncProvider>();
            var dedicatedHostStateManagerMock = new Mock <IDedicatedHostStateManager>();
            var dhmComputeClientMock          = new Mock <IDhmComputeClient>();
            var computeManagementClientMock   = new Mock <IComputeManagementClient>();

            // *** Mock Configuration
            config.DedicatedHostMapping = File.ReadAllText(@"TestData\PrepareDedicatedHostMappingConfig.json");
            // *** Mock Get Host Group call
            computeManagementClientMock
            .Setup(
                s => s.DedicatedHostGroups.GetWithHttpMessagesAsync(
                    It.IsAny <string>(),
                    It.IsAny <string>(),
                    null,
                    It.IsAny <CancellationToken>()))
            .ReturnsAsync(new AzureOperationResponse <DedicatedHostGroup>()
            {
                Response = new System.Net.Http.HttpResponseMessage(HttpStatusCode.OK),
                Body     = new DedicatedHostGroup(location, platformFDCount, null, hostGroupName)
            });

            // *** Mock Existing Host information call
            existingHosts.ForEach(dh =>
                                  computeManagementClientMock
                                  .Setup(
                                      s => s.DedicatedHosts.GetWithHttpMessagesAsync(
                                          It.IsAny <string>(),
                                          hostGroupName,
                                          dh.Name,
                                          InstanceViewTypes.InstanceView,
                                          null,
                                          It.IsAny <CancellationToken>()))
                                  .ReturnsAsync(new AzureOperationResponse <DedicatedHost>()
            {
                Body = existingHosts.Single(d => d.Name == dh.Name)
            }));

            // *** Mock Create Dedicated Host Call
            computeManagementClientMock
            .Setup(s => s.DedicatedHosts.CreateOrUpdateWithHttpMessagesAsync(
                       It.IsAny <string>(),
                       hostGroupName,
                       It.IsAny <string>(),
                       It.IsAny <DedicatedHost>(),
                       null,
                       It.IsAny <CancellationToken>()))
            .ReturnsAsync((string rg, string dhgName, string dhName, DedicatedHost dh, Dictionary <string, List <string> > headers, CancellationToken ctk) =>
            {
                return(new AzureOperationResponse <DedicatedHost>()
                {
                    Body = new DedicatedHost(location: dh.Location, sku: dh.Sku, name: dhName, platformFaultDomain: dh.PlatformFaultDomain)
                });
            });

            dhmComputeClientMock.Setup(s =>
                                       s.GetComputeManagementClient(It.IsAny <string>(), It.IsAny <AzureCredentials>(),
                                                                    It.IsAny <AzureEnvironment>()))
            .ReturnsAsync(computeManagementClientMock.Object);

            // *** Mock List Hosts call
            dedicatedHostSelectorMock
            .Setup(
                s => s.ListDedicatedHosts(
                    It.IsAny <string>(), It.IsAny <AzureEnvironment>(), It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string>(), hostGroupName))
            .ReturnsAsync(existingHosts);

            var dedicatedHostEngine = new DedicatedHostEngine(
                loggerMock.Object,
                config,
                dedicatedHostSelectorMock.Object,
                syncProviderMock.Object,
                dedicatedHostStateManagerMock.Object,
                dhmComputeClientMock.Object);

            // Act
            var addedHosts = await dedicatedHostEngine.PrepareDedicatedHostGroup(
                Token,
                AzureEnvironment.AzureUSGovernment,
                TenantId,
                SubscriptionId,
                ResourceGroup,
                hostGroupName,
                "Standard_D2s_v3",
                vmInstanceToCreate,
                platformFD);

            (addedHosts ?? (new List <DedicatedHost>()))
            .Select(p => new { p.Location, p.PlatformFaultDomain, p.Sku })
            .Should().BeEquivalentTo(expectedHostsToBeCreated
                                     .Select(p => new { p.Location, p.PlatformFaultDomain, p.Sku }));
        }