public void TransformFileOverrideIfFileExistsAndLoggerReturnsOverride(FileConflictResolution resolution) { // Arrange var logger = new Mock <ILogger>(); logger.Setup(l => l.ResolveFileConflict(It.IsAny <string>())).Returns(resolution); var processor = new Preprocessor(); var mockProjectSystem = new Mock <MockProjectSystem>() { CallBase = true }; mockProjectSystem.Setup(m => m.GetPropertyValue("token")).Returns("token value"); mockProjectSystem.Object.AddFile("foo.bar", GetStream("hello")); mockProjectSystem.Setup(m => m.Logger).Returns(logger.Object); var mockFile = new Mock <IPackageFile>(); mockFile.Setup(m => m.Path).Returns("foo.bar.pp"); mockFile.Setup(m => m.GetStream()).Returns(() => GetStream("test $token$")); // Act processor.TransformFile(mockFile.Object, "foo.bar", mockProjectSystem.Object); // Assert Assert.Equal("test token value", mockProjectSystem.Object.OpenFile("foo.bar").ReadToEnd()); }
public FileConflictDialogViewModel(string filePath, bool isFileConflict) { this.filePath = filePath; this.isFileConflict = isFileConflict; this.fileConflictResolution = FileConflictResolution.Cancel; }
public void ResolveConflict_FileConflictActionIsOverwrite_ResolutionIsOverwrite() { CreateResolver(FileConflictAction.Overwrite); FileConflictResolution resolution = ResolveConflict(); Assert.AreEqual(FileConflictResolution.Overwrite, resolution); }
public void ResolveConflict_FileConflictActionIsIgnore_ResolutionIsIgnore() { CreateResolver(FileConflictAction.Ignore); FileConflictResolution resolution = ResolveConflict(); Assert.AreEqual(FileConflictResolution.Ignore, resolution); }
public void OnResolveFileConflict_OneEventSubscriberWhichChangesResolutionToOverwrite_ReturnsOverwrite() { CreateEvents(); events.ResolveFileConflict += (sender, e) => e.Resolution = FileConflictResolution.Overwrite; FileConflictResolution resolution = events.OnResolveFileConflict("message"); Assert.AreEqual(FileConflictResolution.Overwrite, resolution); }
public void ResolveFileConflict_MessagePassed_MessagePassedToWrappedLogger() { CreateLogger(); FileConflictResolution resolution = operationLogger.ResolveFileConflict("message"); fakeLogger.AssertWasCalled(logger => logger.ResolveFileConflict("message")); }
private void OnButtonClick(object sender, System.Windows.RoutedEventArgs e) { var button = (Button)sender; string tagValue = (string)button.Tag; UserSelection = (FileConflictResolution)Enum.Parse(typeof(FileConflictResolution), tagValue); CloseDialog(true); }
public void OnResolveFileConflict_NoInvokeRequired_ValueReturnedFromNonThreadSafeOnResolveFileConflict() { CreateEvents(); fakeEvents.FileConflictResolutionToReturn = FileConflictResolution.OverwriteAll; FileConflictResolution result = threadSafeEvents.OnResolveFileConflict("message"); Assert.AreEqual(FileConflictResolution.OverwriteAll, result); }
public ConsoleHostFileConflictResolver ( IPackageManagementEvents packageEvents, FileConflictAction fileConflictAction) { this.packageEvents = packageEvents; conflictResolution = GetFileConflictResolution (fileConflictAction); packageEvents.ResolveFileConflict += ResolveFileConflict; }
void ResolveFileConflict(object sender, ResolveFileConflictEventArgs e) { if (UserPreviouslySelectedOverwriteAllOrIgnoreAll()) { e.Resolution = lastFileConflictResolution; } else { e.Resolution = fileConflictResolver.ResolveFileConflict(e.Message); lastFileConflictResolution = e.Resolution; } }
public void ResolveConflict_FileConflictActionIsOverwriteButResolverIsDisposed_ResolutionIsNotChangedByResolver() { CreateResolver(FileConflictAction.Overwrite); resolver.Dispose(); FileConflictResolution resolution = ResolveConflict(); Assert.AreEqual(FileConflictResolution.IgnoreAll, resolution); }
public ConsoleHostFileConflictResolver( IPackageManagementEvents packageEvents, FileConflictAction fileConflictAction) { this.packageEvents = packageEvents; conflictResolution = GetFileConflictResolution(fileConflictAction); packageEvents.ResolveFileConflict += ResolveFileConflict; }
public void OnResolveFileConflict_FileConflictResolverReturnsOverwrite_OverwriteSetInEventArgs() { CreateUserPrompts(); RaisePackageOperationsStarting(); ResolverReturns(FileConflictResolution.Overwrite); FileConflictResolution resolution = RaiseResolveFileConflict("message"); Assert.AreEqual(FileConflictResolution.Overwrite, resolution); }
public void ResolveFileConflict_PackageManagementEventsResolveFileConflictReturnsIgnoreAll_ReturnsIgnoreAll() { CreateLogger(); packageManagementEvents.ResolveFileConflict += (sender, e) => { e.Resolution = FileConflictResolution.IgnoreAll; }; FileConflictResolution resolution = logger.ResolveFileConflict("message"); Assert.AreEqual(FileConflictResolution.IgnoreAll, resolution); }
public void ResolveFileConflict_WrappedLoggerResolveFileConflictReturnsOverwriteAll_ReturnsOverwriteAll() { CreateLogger(); fakeLogger .Stub(logger => logger.ResolveFileConflict("message")) .Return(FileConflictResolution.OverwriteAll); FileConflictResolution resolution = operationLogger.ResolveFileConflict("message"); Assert.AreEqual(FileConflictResolution.OverwriteAll, resolution); }
public void ResolveFileConflict_PackageManagementEventsResolveFileConflictReturnsIgnoreAll_ReturnsIgnoreAll() { CreateLogger(); fakePackageManagementEvents .Stub(events => events.OnResolveFileConflict("message")) .Return(FileConflictResolution.IgnoreAll); FileConflictResolution resolution = logger.ResolveFileConflict("message"); Assert.AreEqual(FileConflictResolution.IgnoreAll, resolution); }
public void OnResolveFileConflict_ResolverReturnsOverwriteAllAndThenResolveFileConflictFiredAgain_OverwriteAllReturnedWithoutCallingFileConflictResolverAgain() { CreateUserPrompts(); RaisePackageOperationsStarting(); ResolverReturns(FileConflictResolution.OverwriteAll); RaiseResolveFileConflict("message"); ResetFakeResolver(); ResolverReturns(FileConflictResolution.Ignore); FileConflictResolution resolution = RaiseResolveFileConflict("message"); Assert.AreEqual(FileConflictResolution.OverwriteAll, resolution); }
public void AddFilesAskingForResolutionForEveryConflict() { var resolutions = new FileConflictResolution[] { FileConflictResolution.Ignore, FileConflictResolution.Overwrite, FileConflictResolution.Ignore, FileConflictResolution.IgnoreAll, FileConflictResolution.OverwriteAll, FileConflictResolution.Overwrite, }; var index = 0; var logger = new Mock <ILogger>(); logger.Setup(l => l.ResolveFileConflict(It.IsAny <string>())) .Returns(() => resolutions[index++]); // Arrange var project = new MockProjectSystem(); project.AddFile("a.txt", "this is a"); project.AddFile("b.txt", "this is b"); project.AddFile("c.txt", "this is c"); project.AddFile("d.txt", "this is d"); project.AddFile("e.txt", "this is e"); project.AddFile("f.txt", "this is f"); project.Logger = logger.Object; var files = PackageUtility.CreateFiles(new [] { "a.txt", "b.txt", "c.txt", "d.txt", "e.txt", "f.txt" }, "content"); // Act project.AddFiles(files, new Dictionary <FileTransformExtensions, IPackageFileTransformer>()); // Assert Assert.True(project.FileExists("a.txt")); Assert.True(project.FileExists("b.txt")); Assert.True(project.FileExists("c.txt")); Assert.True(project.FileExists("d.txt")); Assert.True(project.FileExists("e.txt")); Assert.True(project.FileExists("f.txt")); logger.Verify(l => l.ResolveFileConflict(It.IsAny <string>()), Times.Exactly(6)); Assert.Equal("this is a", project.ReadAllText("a.txt")); Assert.Equal("content\\b.txt", project.ReadAllText("b.txt")); Assert.Equal("this is c", project.ReadAllText("c.txt")); Assert.Equal("this is d", project.ReadAllText("d.txt")); Assert.Equal("content\\e.txt", project.ReadAllText("e.txt")); Assert.Equal("content\\f.txt", project.ReadAllText("f.txt")); }
public void OnResolveFileConflict_ResolverReturnsOverwriteAllAndNewPackageInstalledAndThenResolveFileConflictFiredAgain_FileConflictResolverUsedAgainForNewPackage() { CreateUserPrompts(); RaisePackageOperationsStarting(); ResolverReturns(FileConflictResolution.OverwriteAll); RaiseResolveFileConflict("message"); ResetFakeResolver(); RaisePackageOperationsStarting(); ResolverReturns(FileConflictResolution.Ignore); FileConflictResolution resolution = RaiseResolveFileConflict("message"); Assert.AreEqual(FileConflictResolution.Ignore, resolution); }
public void TransformFileOverrideIfFileExistsAndLoggerReturnsIgnore(FileConflictResolution resolution) { // Arrange var logger = new Mock<ILogger>(); logger.Setup(l => l.ResolveFileConflict(It.IsAny<string>())).Returns(resolution); var processor = new Preprocessor(); var mockProjectSystem = new Mock<MockProjectSystem>() { CallBase = true }; mockProjectSystem.Setup(m => m.GetPropertyValue("token")).Returns("token value"); mockProjectSystem.Object.AddFile("foo.bar", GetStream("hello")); mockProjectSystem.Setup(m => m.Logger).Returns(logger.Object); var mockFile = new Mock<IPackageFile>(); mockFile.Setup(m => m.Path).Returns("foo.bar.pp"); mockFile.Setup(m => m.GetStream()).Returns(() => GetStream("test $token$")); // Act processor.TransformFile(mockFile.Object, "foo.bar", mockProjectSystem.Object); // Assert Assert.Equal("hello", mockProjectSystem.Object.OpenFile("foo.bar").ReadToEnd()); }
public FileConflictResolution ResolveFileConflict(string message) { if (_overwriteAll) { return FileConflictResolution.OverwriteAll; } if (_ignoreAll) { return FileConflictResolution.IgnoreAll; } HideProgressWindow(); FileConflictResolution resolution = _providerServices.UserNotifierServices.ShowFileConflictResolution(message); _overwriteAll = resolution == FileConflictResolution.OverwriteAll; _ignoreAll = resolution == FileConflictResolution.IgnoreAll; ShowProgressWindow(); return resolution; }
/// <summary> /// Try to add the specified the project with the target path. If there's an existing file in the project with the same name, /// it will ask the logger for the resolution, which has 4 choices: Overwrite|Ignore|Overwrite All|Ignore All /// </summary> /// <param name="project"></param> /// <param name="file"></param> /// <param name="path"></param> public static void TryAddFile(IProjectSystem project, IPackageFile file, string path) { if (project.FileExists(path) && project.FileExistsInProject(path)) { // file exists in project, ask user if he wants to overwrite or ignore string conflictMessage = String.Format(CultureInfo.CurrentCulture, NuGetResources.FileConflictMessage, path, project.ProjectName); FileConflictResolution resolution = project.Logger.ResolveFileConflict(conflictMessage); if (resolution == FileConflictResolution.Overwrite || resolution == FileConflictResolution.OverwriteAll) { // overwrite project.Logger.Log(MessageLevel.Info, NuGetResources.Info_OverwriteExistingFile, path); project.AddFile(path, file.GetStream()); } else { // ignore project.Logger.Log(MessageLevel.Info, NuGetResources.Warning_FileAlreadyExists, path); } } else { project.AddFile(path, file.GetStream()); } }
void UpdateResolution(FileConflictResolution resolution) { this.resolution = resolution; Close(this, new EventArgs()); }
void ResetFileConflictResolution() { lastFileConflictResolution = FileConflictResolution.Overwrite; }
void ResolverReturns(FileConflictResolution resolution) { fakeFileConflictResolver .Stub(r => r.ResolveFileConflict(Arg <string> .Is.Anything)) .Return(resolution); }
void ResolverReturns(FileConflictResolution resolution) { fakeFileConflictResolver .Stub(r => r.ResolveFileConflict(Arg<string>.Is.Anything)) .Return(resolution); }