Skip to content
This repository has been archived by the owner on Oct 16, 2020. It is now read-only.

Commit

Permalink
Merge remote-tracking branch 'remotes/sd/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
jogibear9988 committed May 13, 2015
2 parents 848365c + 27c8cac commit 2f7618f
Show file tree
Hide file tree
Showing 38 changed files with 698 additions and 185 deletions.
Expand Up @@ -153,6 +153,7 @@
<Compile Include="Src\ICodeGenerator.cs" />
<Compile Include="Src\IDocumentView.cs" />
<Compile Include="Src\InstalledPackagesViewModel.cs" />
<Compile Include="Src\IOpenPackageReadMeMonitor.cs" />
<Compile Include="Src\IPackageRepositoryFactoryEvents.cs" />
<Compile Include="Src\IPackageViewModelParent.cs" />
<Compile Include="Src\ISettingsProvider.cs" />
Expand Down Expand Up @@ -230,6 +231,7 @@
<Compile Include="Src\NoPackageSourcesConfiguredException.cs" />
<Compile Include="Src\NuGetExePath.cs" />
<Compile Include="Src\NuGetPackageRestoreCommandLine.cs" />
<Compile Include="Src\OpenPackageReadMeMonitor.cs" />
<Compile Include="Src\PackageLicenseViewModel.cs" />
<Compile Include="Src\PackageManagementServiceProvider.cs" />
<Compile Include="Src\IPackageRepositoryExtensions.cs" />
Expand Down
Expand Up @@ -43,6 +43,21 @@ public FakePackageManagementProject(string name)

ConstraintProvider = NullConstraintProvider.Instance;
TargetFramework = new FrameworkName(".NETFramework", new Version("4.0"));

InstallPackageAction = (package, installAction) => {
PackagePassedToInstallPackage = package;
PackageOperationsPassedToInstallPackage = installAction.Operations;
IgnoreDependenciesPassedToInstallPackage = installAction.IgnoreDependencies;
AllowPrereleaseVersionsPassedToInstallPackage = installAction.AllowPrereleaseVersions;
};

UpdatePackageAction = (package, updateAction) => {
PackagePassedToUpdatePackage = package;
PackageOperationsPassedToUpdatePackage = updateAction.Operations;
UpdateDependenciesPassedToUpdatePackage = updateAction.UpdateDependencies;
AllowPrereleaseVersionsPassedToUpdatePackage = updateAction.AllowPrereleaseVersions;
IsUpdatePackageCalled = true;
};
}

private FakeInstallPackageAction FakeInstallPackageAction;
Expand Down Expand Up @@ -99,12 +114,11 @@ public virtual IEnumerable<PackageOperation> GetInstallPackageOperations(IPackag
public bool IgnoreDependenciesPassedToInstallPackage;
public bool AllowPrereleaseVersionsPassedToInstallPackage;

public Action<IPackage, InstallPackageAction> InstallPackageAction;

public void InstallPackage(IPackage package, InstallPackageAction installAction)
{
PackagePassedToInstallPackage = package;
PackageOperationsPassedToInstallPackage = installAction.Operations;
IgnoreDependenciesPassedToInstallPackage = installAction.IgnoreDependencies;
AllowPrereleaseVersionsPassedToInstallPackage = installAction.AllowPrereleaseVersions;
InstallPackageAction(package, installAction);
}

public FakePackageOperation AddFakeInstallOperation()
Expand Down Expand Up @@ -148,13 +162,11 @@ public void UninstallPackage(IPackage package, UninstallPackageAction uninstallA

public void UpdatePackage(IPackage package, UpdatePackageAction updateAction)
{
PackagePassedToUpdatePackage = package;
PackageOperationsPassedToUpdatePackage = updateAction.Operations;
UpdateDependenciesPassedToUpdatePackage = updateAction.UpdateDependencies;
AllowPrereleaseVersionsPassedToUpdatePackage = updateAction.AllowPrereleaseVersions;
IsUpdatePackageCalled = true;
UpdatePackageAction(package, updateAction);
}

public Action<IPackage, UpdatePackageAction> UpdatePackageAction;

public FakeInstallPackageAction LastInstallPackageCreated;

public virtual InstallPackageAction CreateInstallPackageAction()
Expand Down
@@ -0,0 +1,27 @@
// Copyright (c) 2015 AlphaSierraPapa for the SharpDevelop Team
//
// 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 System;

namespace ICSharpCode.PackageManagement
{
public interface IOpenPackageReadMeMonitor : IDisposable
{
void OpenReadMeFile();
}
}
Expand Up @@ -42,8 +42,11 @@ protected override IEnumerable<PackageOperation> GetPackageOperations()

protected override void ExecuteCore()
{
Project.InstallPackage(Package, this);
OnParentPackageInstalled();
using (IOpenPackageReadMeMonitor monitor = CreateOpenPackageReadMeMonitor(Package.Id)) {
Project.InstallPackage(Package, this);
monitor.OpenReadMeFile();
OnParentPackageInstalled();
}
}
}
}
@@ -0,0 +1,86 @@
// Copyright (c) 2015 AlphaSierraPapa for the SharpDevelop Team
//
// 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 System;
using System.IO;
using System.Linq;
using NuGet;

namespace ICSharpCode.PackageManagement
{
public class OpenPackageReadMeMonitor : IOpenPackageReadMeMonitor
{
IPackageManagementProject project;
IPackageManagementFileService fileService;

public OpenPackageReadMeMonitor(string packageId, IPackageManagementProject project)
: this(packageId, project, new PackageManagementFileService())
{
}

public OpenPackageReadMeMonitor(
string packageId,
IPackageManagementProject project,
IPackageManagementFileService fileService)
{
PackageId = packageId;
this.project = project;
this.fileService = fileService;
project.PackageInstalled += PackageInstalled;
}

public string PackageId { get; private set; }
public bool IsDisposed { get; private set; }

string ReadMeFile { get; set; }

public void Dispose()
{
if (IsDisposed) {
return;
}

IsDisposed = true;
project.PackageInstalled -= PackageInstalled;
}

void PackageInstalled(object sender, PackageOperationEventArgs e)
{
if (e.Package.Id != PackageId) {
return;
}

ReadMeFile = FindReadMeFileInPackage(e.InstallPath, e.Package);
}

string FindReadMeFileInPackage(string installPath, IPackage package)
{
return package.GetFiles()
.Where(file => "readme.txt".Equals(file.Path, StringComparison.OrdinalIgnoreCase))
.Select(file => Path.Combine(installPath, file.Path))
.FirstOrDefault();
}

public void OpenReadMeFile()
{
if ((ReadMeFile != null) && fileService.FileExists(ReadMeFile)) {
fileService.OpenFile(ReadMeFile);
}
}
}
}
Expand Up @@ -161,5 +161,10 @@ string GetPackageId()
}
return PackageId;
}

protected virtual IOpenPackageReadMeMonitor CreateOpenPackageReadMeMonitor(string packageId)
{
return new OpenPackageReadMeMonitor(packageId, Project);
}
}
}
Expand Up @@ -47,8 +47,11 @@ protected override IEnumerable<PackageOperation> GetPackageOperations()
protected override void ExecuteCore()
{
if (ShouldUpdatePackage()) {
Project.UpdatePackage(Package, this);
OnParentPackageInstalled();
using (IOpenPackageReadMeMonitor monitor = CreateOpenPackageReadMeMonitor(Package.Id)) {
Project.UpdatePackage(Package, this);
monitor.OpenReadMeFile();
OnParentPackageInstalled();
}
}
}

Expand Down
Expand Up @@ -123,11 +123,13 @@
<Compile Include="Src\Helpers\SelectedProjectCollectionAssert.cs" />
<Compile Include="Src\Helpers\SolutionHelper.cs" />
<Compile Include="Src\Helpers\TestableInstalledPackageViewModel.cs" />
<Compile Include="Src\Helpers\TestableInstallPackageAction.cs" />
<Compile Include="Src\Helpers\TestablePackageFromRepository.cs" />
<Compile Include="Src\Helpers\TestablePackagesViewModels.cs" />
<Compile Include="Src\Helpers\TestableProjectBehaviour.cs" />
<Compile Include="Src\Helpers\TestableSelectedProjectsForUpdatedPackages.cs" />
<Compile Include="Src\Helpers\TestableSolutionSnapshot.cs" />
<Compile Include="Src\Helpers\TestableUpdatePackageAction.cs" />
<Compile Include="Src\Helpers\TestableUpdatePackagesAction.cs" />
<Compile Include="Src\Helpers\TestableUpdateSolutionPackagesAction.cs" />
<Compile Include="Src\Helpers\TestPackageHelper.cs" />
Expand Down Expand Up @@ -190,6 +192,7 @@
<Compile Include="Src\ManagePackagesUserPromptsTests.cs" />
<Compile Include="Src\NuGetPackageRestoreCommandLineTests.cs" />
<Compile Include="Src\OpenMSBuildProjectsTests.cs" />
<Compile Include="Src\OpenPackageReadMeMonitorTests.cs" />
<Compile Include="Src\PackageManagementServiceProviderTests.cs" />
<Compile Include="Src\PackageViewModelOperationLoggerTests.cs" />
<Compile Include="Src\ReducedPackageOperationsTests.cs" />
Expand Down
Expand Up @@ -64,9 +64,11 @@ void RemoveFirstProjectItem()
}

public string FileNamePassedToOpenFile;
public bool IsOpenFileCalled;

public void OpenFile(string fileName)
{
IsOpenFileCalled = true;
FileNamePassedToOpenFile = fileName;
}

Expand Down
@@ -0,0 +1,46 @@
// Copyright (c) 2015 AlphaSierraPapa for the SharpDevelop Team
//
// 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 System;
using ICSharpCode.PackageManagement;

namespace PackageManagement.Tests.Helpers
{
public class TestableInstallPackageAction : InstallPackageAction
{
public TestableInstallPackageAction(
IPackageManagementProject project,
IPackageManagementEvents packageManagementEvents)
: base(project, packageManagementEvents)
{
CreateOpenPackageReadMeMonitorAction = packageId => {
IOpenPackageReadMeMonitor monitor = base.CreateOpenPackageReadMeMonitor(packageId);
OpenPackageReadMeMonitor = monitor as OpenPackageReadMeMonitor;
return monitor;
};
}

public OpenPackageReadMeMonitor OpenPackageReadMeMonitor;
public Func<string, IOpenPackageReadMeMonitor> CreateOpenPackageReadMeMonitorAction;

protected override IOpenPackageReadMeMonitor CreateOpenPackageReadMeMonitor(string packageId)
{
return CreateOpenPackageReadMeMonitorAction(packageId);
}
}
}
@@ -0,0 +1,45 @@
// Copyright (c) 2015 AlphaSierraPapa for the SharpDevelop Team
//
// 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 System;
using ICSharpCode.PackageManagement;

namespace PackageManagement.Tests.Helpers
{
public class TestableUpdatePackageAction : UpdatePackageAction
{
public TestableUpdatePackageAction(
IPackageManagementProject project,
IPackageManagementEvents packageManagementEvents)
: base(project, packageManagementEvents)
{
CreateOpenPackageReadMeMonitorAction = packageId => {
OpenPackageReadMeMonitor = base.CreateOpenPackageReadMeMonitor(packageId) as OpenPackageReadMeMonitor;
return OpenPackageReadMeMonitor;
};
}

public OpenPackageReadMeMonitor OpenPackageReadMeMonitor;
public Func<string, IOpenPackageReadMeMonitor> CreateOpenPackageReadMeMonitorAction;

protected override IOpenPackageReadMeMonitor CreateOpenPackageReadMeMonitor(string packageId)
{
return CreateOpenPackageReadMeMonitorAction(packageId);
}
}
}

0 comments on commit 2f7618f

Please sign in to comment.