public void DataCollectionHandlesDirectoryExistenceErrors() { TestExecutionHelpers.SetUpSessionAndProfile(); Mock <IDataStore> mock = new Mock <IDataStore>(); mock.Setup(f => f.DirectoryExists(It.IsAny <string>())).Throws(new IOException("This should not be raised")); mock.Setup(f => f.FileExists(It.IsAny <string>())).Returns(true); mock.Setup(f => f.DeleteFile(It.IsAny <string>())); var oldDataStore = AzureSession.Instance.DataStore; AzureSession.Instance.DataStore = mock.Object; try { var controller = DataCollectionController.Create(AzureSession.Instance); var profile = controller.GetProfile(() => { }); DataCollectionController.WritePSDataCollectionProfile(AzureSession.Instance, profile); } finally { AzureSession.Instance.DataStore = oldDataStore; } }
public void DataCollectionHandlesSerializationErrors() { TestExecutionHelpers.SetUpSessionAndProfile(); MemoryDataStore dataStore; string oldFileValue = null; var dataCollectionPath = Path.Combine(AzureSession.Instance.ProfileDirectory, AzurePSDataCollectionProfile.DefaultFileName); var oldDataStore = AzureSession.Instance.DataStore; var memoryStore = oldDataStore as MemoryDataStore; if (memoryStore != null) { dataStore = memoryStore; if (dataStore.VirtualStore.ContainsKey(dataCollectionPath)) { oldFileValue = dataStore.VirtualStore[dataCollectionPath]; } } else { dataStore = new MemoryDataStore(); } dataStore.VirtualStore.Add(dataCollectionPath, "{{{{{{{{{{}}}--badly-formatted-file"); AzureSession.Instance.DataStore = dataStore; try { var controller = DataCollectionController.Create(AzureSession.Instance); var profile = controller.GetProfile(() => { }); DataCollectionController.WritePSDataCollectionProfile(AzureSession.Instance, profile); } finally { dataStore.VirtualStore[dataCollectionPath] = oldFileValue; AzureSession.Instance.DataStore = oldDataStore; } }
protected void SetDataCollectionProfile(bool enable) { var profile = _dataCollectionProfile; profile.EnableAzureDataCollection = enable; DataCollectionController.WritePSDataCollectionProfile(AzureSession.Instance, profile); AzureSession.Instance.RegisterComponent(DataCollectionController.RegistryKey, () => DataCollectionController.Create(profile), true); }
static void InitializeDataCollection(IAzureSession session) { session.RegisterComponent(DataCollectionController.RegistryKey, () => DataCollectionController.Create(session)); }