public void TestLayerLocking()
        {
            try
            {
                const string TEST_SCENENAME  = "TestSceneLocking";
                const string TEST_SCENENAME2 = "TestSceneLocking_SaveAsTest";

                // Create a new project and scene
                TestManager.Helpers.CreateTestScene(TEST_SCENENAME);
                EditorProject project    = EditorApp.Project;
                IScene        scene      = project.Scene;
                Layer         firstLayer = scene.Layers[0];

                // First layer must be writeable
                Assert.IsTrue(firstLayer.OwnsLock);
                Assert.IsTrue(firstLayer.SaveToFile());

                // close scene
                string layerFilePath = firstLayer.AbsoluteLayerFilename;
                firstLayer = null;
                scene.Close();
                Assert.IsNull(project.Scene);

                // Get external lock on layer file
                IFileLock extFileLock = EditorManager.FileLockFactory.GetFileLock(layerFilePath);
                Assert.IsTrue(extFileLock.TryLock());

                // Reopen scene: must fail on saving layer (locked externally)
                Assert.IsTrue(project.OpenScene(TEST_SCENENAME));
                scene      = project.Scene;
                firstLayer = scene.Layers[0];
                Assert.IsFalse(firstLayer.OwnsLock);

                // Release lock: OwnsWriteLock state must get updated
                extFileLock.Unlock();
                // Give windows time to inform the file watcher
                System.Threading.Thread.Sleep(1000); TestManager.Helpers.ProcessEvents();
                // And then give the file watcher time to send his queued/delayed notification
                System.Threading.Thread.Sleep(1000); TestManager.Helpers.ProcessEvents();
                Assert.IsTrue(firstLayer.LockStatus == Layer.LayerLockStatus_e.NotLocked);

                // Let the scene lock the layer again: saving file must be successful
                firstLayer.TryLock(null, false);
                Assert.IsTrue(firstLayer.OwnsLock);
                Assert.IsTrue(firstLayer.SaveToFile());

                // Getting external lock must fail (since file is locked by scene)
                Assert.IsFalse(extFileLock.TryLock());

                // Rename the scene file
                Assert.IsTrue(scene.SaveAs(TEST_SCENENAME2));
                string renamedLayerFilePath = firstLayer.AbsoluteLayerFilename;
                Assert.IsTrue(renamedLayerFilePath != layerFilePath);

                // Getting external lock must work after scene-save-as
                Assert.IsTrue(firstLayer.OwnsLock);
                Assert.IsTrue(extFileLock.TryLock());
                extFileLock.Unlock();

                // Getting external lock on renamed file must fail
                IFileLock extFileLockRenamed = EditorManager.FileLockFactory.GetFileLock(renamedLayerFilePath);
                Assert.IsFalse(extFileLockRenamed.TryLock());

                // Verify that a scene can't be opened without closing it at first
                // (important, since we otherwise still have the lock on the old scene)
                Assert.IsFalse(project.OpenScene(TEST_SCENENAME));

                // Close scene
                scene.Close();
                Assert.IsNull(project.Scene);

                // Test correct behaviour for readonly layer files
                {
                    // Set the layer as readonly (as done by some version control systems
                    // when using exclusive locking)
                    File.SetAttributes(layerFilePath, File.GetAttributes(layerFilePath) | FileAttributes.ReadOnly);

                    // Reopen scene
                    Assert.IsTrue(project.OpenScene(TEST_SCENENAME));
                    scene      = project.Scene;
                    firstLayer = scene.Layers[0];

                    // Layer must not be locked due to being readonly.
                    Assert.IsFalse(firstLayer.OwnsLock);
                    Assert.AreEqual(Layer.LayerLockStatus_e.ReadOnly, firstLayer.LockStatus);

                    // Close scene
                    scene.Close();
                    Assert.IsNull(project.Scene);

                    // Set the layer as readonly (as done by some version control systems
                    // when using exclusive locking)
                    File.SetAttributes(layerFilePath, File.GetAttributes(layerFilePath) & (~FileAttributes.ReadOnly));
                }

                TestManager.Helpers.CloseTestProject();
            }
            catch (Exception ex)
            {
                EditorManager.DumpException(ex);
                throw ex;
            }
        }