// 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);
}
}
}