// ReSharper disable InconsistentNaming - Unit Tests public void SaveInstanceAssociation_With_FileUsedByAnotherProcess_Expected_ThrowsInstancePersistenceException() // ReSharper restore InconsistentNaming { var instanceId = Guid.NewGuid(); var instanceKey = Guid.NewGuid(); var store = new FileSystemInstanceStoreIO(); var path = store.GetSaveInstanceAssociationPath(instanceId, instanceKey); try { var xml = XmlResource.Fetch(TestFileName); xml.Save(path); // Force error: The process cannot access the file because it is being used by another process using (var fs = File.Open(path, FileMode.Open, FileAccess.Read, FileShare.None)) { store.SaveInstanceAssociation(instanceId, instanceKey, true); } } finally { if (File.Exists(path)) { File.Delete(path); } } }
// ReSharper disable InconsistentNaming - Unit Tests public void SaveAllInstanceMetaData_With_FileUsedByAnotherProcess_Expected_ThrowsInstancePersistenceException() // ReSharper restore InconsistentNaming { var instanceId = Guid.NewGuid(); var path = Path.Combine(TestPath, instanceId + ".meta.xml"); try { var xml = XmlResource.Fetch(TestMetaFileName); xml.Save(path); // Force error: The process cannot access the file because it is being used by another process using (var fs = File.Open(path, FileMode.Open, FileAccess.Read, FileShare.None)) { var store = new FileSystemInstanceStoreIO(); store.SaveAllInstanceMetaData(instanceId, new SaveWorkflowCommand()); } } finally { if (File.Exists(path)) { File.Delete(path); } } }
// ReSharper disable InconsistentNaming - Unit Tests public void LoadInstance_With_FileUsedByAnotherProcess_Expected_ThrowsInstancePersistenceException() // ReSharper restore InconsistentNaming { var instanceId = Guid.NewGuid(); var path = Path.Combine(TestPath, instanceId + ".xml"); var metaPath = Path.Combine(TestPath, instanceId + ".meta.xml"); try { var xml = XmlResource.Fetch(TestFileName); xml.Save(path); xml = XmlResource.Fetch(TestMetaFileName); xml.Save(metaPath); // Force error: The process cannot access the file because it is being used by another process using (var fs = File.Open(path, FileMode.Open, FileAccess.Read, FileShare.None)) { var store = new FileSystemInstanceStoreIO(); IDictionary <XName, InstanceValue> instanceData; IDictionary <XName, InstanceValue> instanceMetadata; var result = store.LoadInstance(instanceId, out instanceData, out instanceMetadata); } } finally { if (File.Exists(path)) { File.Delete(path); } if (File.Exists(metaPath)) { File.Delete(metaPath); } } }
// ReSharper disable InconsistentNaming - Unit Tests public void GetInstanceAssociation_With_InvalidFileName_Expected_ReturnsEmptyGuid() // ReSharper restore InconsistentNaming { const string InvalidInstanceId = "99999"; var instanceKey = Guid.NewGuid(); var path = Path.Combine(TestPath, string.Format("Key.{0}.{1}.xml", instanceKey, InvalidInstanceId)); try { var xml = XmlResource.Fetch(TestFileName); xml.Save(path); var store = new FileSystemInstanceStoreIO(); var result = store.GetInstanceAssociation(instanceKey); Assert.AreEqual(Guid.Empty, result); } finally { if (File.Exists(path)) { File.Delete(path); } } }