From 9b2f52ce8fc73acc6d2802659ed5e0c1c1e98d7e Mon Sep 17 00:00:00 2001 From: Matt Ward Date: Wed, 29 May 2019 14:14:30 +0100 Subject: [NuGet] Add tests for restore command handlers being enabled Added tests for existing logic before changing it to fix some bugs where the restore menu is not enabled when it should be. --- .../FakeNuGetAwareProject.cs | 5 ++ .../TestableRestorePackagesHandler.cs | 54 ++++++++++++++++++++++ .../TestableRestorePackagesInProjectHandler.cs | 54 ++++++++++++++++++++++ 3 files changed, 113 insertions(+) create mode 100644 main/src/addins/MonoDevelop.PackageManagement/MonoDevelop.PackageManagement.Tests/MonoDevelop.PackageManagement.Tests.Helpers/TestableRestorePackagesHandler.cs create mode 100644 main/src/addins/MonoDevelop.PackageManagement/MonoDevelop.PackageManagement.Tests/MonoDevelop.PackageManagement.Tests.Helpers/TestableRestorePackagesInProjectHandler.cs (limited to 'main/src/addins/MonoDevelop.PackageManagement/MonoDevelop.PackageManagement.Tests/MonoDevelop.PackageManagement.Tests.Helpers') diff --git a/main/src/addins/MonoDevelop.PackageManagement/MonoDevelop.PackageManagement.Tests/MonoDevelop.PackageManagement.Tests.Helpers/FakeNuGetAwareProject.cs b/main/src/addins/MonoDevelop.PackageManagement/MonoDevelop.PackageManagement.Tests/MonoDevelop.PackageManagement.Tests.Helpers/FakeNuGetAwareProject.cs index abe4cce276..33cd30fbb5 100644 --- a/main/src/addins/MonoDevelop.PackageManagement/MonoDevelop.PackageManagement.Tests/MonoDevelop.PackageManagement.Tests.Helpers/FakeNuGetAwareProject.cs +++ b/main/src/addins/MonoDevelop.PackageManagement/MonoDevelop.PackageManagement.Tests/MonoDevelop.PackageManagement.Tests.Helpers/FakeNuGetAwareProject.cs @@ -33,6 +33,11 @@ namespace MonoDevelop.PackageManagement.Tests.Helpers { class FakeNuGetAwareProject : DummyDotNetProject, INuGetAwareProject { + public FakeNuGetAwareProject () + { + Initialize (this); + } + public NuGetProject CreateNuGetProject () { throw new NotImplementedException (); diff --git a/main/src/addins/MonoDevelop.PackageManagement/MonoDevelop.PackageManagement.Tests/MonoDevelop.PackageManagement.Tests.Helpers/TestableRestorePackagesHandler.cs b/main/src/addins/MonoDevelop.PackageManagement/MonoDevelop.PackageManagement.Tests/MonoDevelop.PackageManagement.Tests.Helpers/TestableRestorePackagesHandler.cs new file mode 100644 index 0000000000..dfb6272a16 --- /dev/null +++ b/main/src/addins/MonoDevelop.PackageManagement/MonoDevelop.PackageManagement.Tests/MonoDevelop.PackageManagement.Tests.Helpers/TestableRestorePackagesHandler.cs @@ -0,0 +1,54 @@ +// +// TestableRestorePackagesHandler.cs +// +// Author: +// Matt Ward +// +// Copyright (c) 2019 Microsoft +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +// THE SOFTWARE. + +using MonoDevelop.Components.Commands; +using MonoDevelop.PackageManagement.Commands; +using MonoDevelop.Projects; + +namespace MonoDevelop.PackageManagement.Tests.Helpers +{ + class TestableRestorePackagesHandler : RestorePackagesHandler + { + CommandInfo info = new CommandInfo (); + Project project; + Solution solution; + + public bool Enabled { + get { return info.Enabled; } + } + + public void RunUpdate (Solution solution, Project project) + { + this.solution = solution; + this.project = project; + + base.Update (info); + } + + protected override Project CurrentSelectedProject => project; + protected override Solution CurrentSelectedSolution => solution; + } +} diff --git a/main/src/addins/MonoDevelop.PackageManagement/MonoDevelop.PackageManagement.Tests/MonoDevelop.PackageManagement.Tests.Helpers/TestableRestorePackagesInProjectHandler.cs b/main/src/addins/MonoDevelop.PackageManagement/MonoDevelop.PackageManagement.Tests/MonoDevelop.PackageManagement.Tests.Helpers/TestableRestorePackagesInProjectHandler.cs new file mode 100644 index 0000000000..64304cb624 --- /dev/null +++ b/main/src/addins/MonoDevelop.PackageManagement/MonoDevelop.PackageManagement.Tests/MonoDevelop.PackageManagement.Tests.Helpers/TestableRestorePackagesInProjectHandler.cs @@ -0,0 +1,54 @@ +// +// TestableRestorePackagesInProjectHandler.cs +// +// Author: +// Matt Ward +// +// Copyright (c) 2019 Microsoft +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +// THE SOFTWARE. + +using MonoDevelop.Components.Commands; +using MonoDevelop.PackageManagement.Commands; +using MonoDevelop.Projects; + +namespace MonoDevelop.PackageManagement.Tests.Helpers +{ + class TestableRestorePackagesInProjectHandler : RestorePackagesInProjectHandler + { + CommandInfo info = new CommandInfo (); + Project project; + Solution solution; + + public bool Enabled { + get { return info.Enabled; } + } + + public void RunUpdate (Solution solution, Project project) + { + this.solution = solution; + this.project = project; + + base.Update (info); + } + + protected override Project CurrentSelectedProject => project; + protected override Solution CurrentSelectedSolution => solution; + } +} -- cgit v1.2.3