From ba30762725764c809b42b5195e2e599507823c4d Mon Sep 17 00:00:00 2001 From: enricosada Date: Fri, 3 Apr 2015 15:15:34 +0200 Subject: [PATCH] add test --- .../src/unittests/TestLib.ProjectSystem.fs | 2 +- .../unittests/Tests.ProjectSystem.Project.fs | 62 +++++++++++++++++++ 2 files changed, 63 insertions(+), 1 deletion(-) diff --git a/vsintegration/src/unittests/TestLib.ProjectSystem.fs b/vsintegration/src/unittests/TestLib.ProjectSystem.fs index 1a6acd05da8..491298f3c82 100644 --- a/vsintegration/src/unittests/TestLib.ProjectSystem.fs +++ b/vsintegration/src/unittests/TestLib.ProjectSystem.fs @@ -170,7 +170,7 @@ type TheTests() = | x -> x match TryFind node with | Some(x) -> x - | None -> failwith "did not find node with caption %s" caption + | None -> failwithf "did not find node with caption %s" caption static member MoveDown(node : HierarchyNode) = match node with diff --git a/vsintegration/src/unittests/Tests.ProjectSystem.Project.fs b/vsintegration/src/unittests/Tests.ProjectSystem.Project.fs index 31bc9df77b0..0c202470525 100644 --- a/vsintegration/src/unittests/Tests.ProjectSystem.Project.fs +++ b/vsintegration/src/unittests/Tests.ProjectSystem.Project.fs @@ -695,6 +695,68 @@ type Project() = File.Delete(absFilePath) )) + [] //ref bug https://github.com/Microsoft/visualfsharp/issues/259 + member public this.``RenameFile.InFolder``() = + this.MakeProjectAndDo(["file1.fs"; @"Folder1\file2.fs"; @"Folder1\nested1.fs"], [], "", (fun project -> + let absFilePath = Path.Combine(project.ProjectFolder, "Folder1", "nested1.fs") + try + Directory.CreateDirectory(Path.GetDirectoryName(absFilePath)) |> ignore; + File.AppendAllText(absFilePath, "#light") + let orig1 = TheTests.FindNodeWithCaption(project, "nested1.fs") + let folder1 = TheTests.FindNodeWithCaption(project, "Folder1") + VsMocks.vsRunningDocumentTableFindAndLockDocumentVsHierarchyMock <- project + + let added, deleted = ResizeArray(), ResizeArray() + + let sink = + { new IVsHierarchyEvents with + member x.OnInvalidateIcon _hicon = VSConstants.S_OK + member x.OnInvalidateItems _itemidParent = VSConstants.S_OK + member x.OnItemAdded (itemidParent, itemidSiblingPrev, itemidAdded) = + added.Add(itemidParent, itemidSiblingPrev, itemidAdded) + VSConstants.S_OK + member x.OnItemDeleted (itemid) = + deleted.Add(itemid) + VSConstants.S_OK + member x.OnItemsAppended (itemidParent) = + VSConstants.S_OK + member x.OnPropertyChanged (itemid, propid, flags) = + VSConstants.S_OK } + + let cookie = ref 0u + project.AdviseHierarchyEvents(sink, cookie) |> ErrorHandler.ThrowOnFailure |> ignore + + // rename the file + orig1.SetEditLabel("renamedNested2.fs") |> ErrorHandler.ThrowOnFailure |> ignore + + SaveProject project + + let file2 = TheTests.FindNodeWithCaption (project, "file2.fs") + let renamedNested2 = TheTests.FindNodeWithCaption (project, "renamedNested2.fs") + + AssertEqual [ folder1.ID, file2.ID, renamedNested2.ID ] (added |> Seq.distinct |> List.ofSeq) + AssertEqual [ orig1.ID ] (deleted |> Seq.distinct |> List.ofSeq) + + // TODO ensure IVsTrackProjectDocumentsEvents Renamed was fired + + // ensure right in .fsproj + let msbuildInfo = TheTests.MsBuildCompileItems(project.BuildProject) + AssertEqual ["file1.fs"; @"Folder1\file2.fs"; @"Folder1\renamedNested2.fs"] msbuildInfo + + // ensure right in solution explorer + let expect = + Tree("References", ANYTREE, + Tree("file1.fs", Nil, + Tree("Folder1", + Tree("file2.fs", Nil, + Tree("renamedNested2.fs", Nil, Nil)), + Nil))) + TheTests.AssertSameTree (expect, project.FirstChild) + + finally + if File.Exists(absFilePath) then File.Delete(absFilePath) + )) + [] member public this.``RenameFile.BuildActionIsResetBasedOnFilenameExtension``() = let GetTextFromBuildAction (action:VSLangProj.prjBuildAction) =