public void FailToObtainAzureInstanceMetadataFieldsAltogether() { HeartbeatProviderMock hbeatMock = new HeartbeatProviderMock(); AzureInstanceMetadataRequestMock azureInstanceRequestorMock = new AzureInstanceMetadataRequestMock( getComputeMetadata: () => { try { throw new System.Exception("Failure"); } catch { } return(null); }); var azureIMSFields = new AzureComputeMetadataHeartbeatPropertyProvider(azureInstanceRequestorMock); var defaultFields = azureIMSFields.ExpectedAzureImsFields; // not adding the fields we're looking for, simulation of the Azure Instance Metadata service not being present... var taskWaiter = azureIMSFields.SetDefaultPayloadAsync(hbeatMock).ConfigureAwait(false); Assert.False(taskWaiter.GetAwaiter().GetResult()); // nop await for tests foreach (string fieldName in defaultFields) { string heartbeatFieldName = string.Concat(AzureComputeMetadataHeartbeatPropertyProvider.HeartbeatPropertyPrefix, fieldName); Assert.False(hbeatMock.HbeatProps.ContainsKey(heartbeatFieldName)); } }
public void GetAzureInstanceMetadataFieldsAsExpected() { HeartbeatProviderMock hbeatMock = new HeartbeatProviderMock(); AzureInstanceMetadataRequestMock azureInstanceRequestorMock = new AzureInstanceMetadataRequestMock(); AzureComputeMetadataHeartbeatPropertyProvider azureIMSFields = new AzureComputeMetadataHeartbeatPropertyProvider(azureInstanceRequestorMock); var taskWaiter = azureIMSFields.SetDefaultPayloadAsync(hbeatMock).ConfigureAwait(false); Assert.True(taskWaiter.GetAwaiter().GetResult()); // no await for tests foreach (string fieldName in azureIMSFields.ExpectedAzureImsFields) { string expectedFieldName = string.Concat(AzureComputeMetadataHeartbeatPropertyProvider.HeartbeatPropertyPrefix, fieldName); Assert.True(hbeatMock.HbeatProps.ContainsKey(expectedFieldName)); Assert.False(string.IsNullOrEmpty(hbeatMock.HbeatProps[expectedFieldName])); } }
public void AzureInstanceMetadataObtainedSuccessfully() { AzureInstanceComputeMetadata expected = new AzureInstanceComputeMetadata() { Location = "US-West", Name = "test-vm01", Offer = "D9_USWest", OsType = "Linux", PlatformFaultDomain = "0", PlatformUpdateDomain = "0", Publisher = "Microsoft", ResourceGroupName = "test.resource-group_01", Sku = "Windows_10", SubscriptionId = Guid.NewGuid().ToString(), Version = "10.8a", VmId = Guid.NewGuid().ToString(), VmSize = "A8" }; HeartbeatProviderMock hbeatMock = new HeartbeatProviderMock(); AzureInstanceMetadataRequestMock azureInstanceRequestorMock = new AzureInstanceMetadataRequestMock( getComputeMetadata: () => { return(expected); }); var azureIMSFields = new AzureComputeMetadataHeartbeatPropertyProvider(azureInstanceRequestorMock); var defaultFields = azureIMSFields.ExpectedAzureImsFields; // not adding the fields we're looking for, simulation of the Azure Instance Metadata service not being present... var taskWaiter = azureIMSFields.SetDefaultPayloadAsync(hbeatMock).ConfigureAwait(false); Assert.True(taskWaiter.GetAwaiter().GetResult()); // nop await for tests foreach (string fieldName in defaultFields) { string heartbeatFieldName = string.Concat(AzureComputeMetadataHeartbeatPropertyProvider.HeartbeatPropertyPrefix, fieldName); Assert.True(hbeatMock.HbeatProps.ContainsKey(heartbeatFieldName)); Assert.Equal(expected.GetValueForField(fieldName), hbeatMock.HbeatProps[heartbeatFieldName]); } }