public void Repeat_MustAbortForSettingsPasswordIfWishedByUser() { var currentSettings = new AppSettings(); var location = Path.GetDirectoryName(GetType().Assembly.Location); var resource = new Uri(Path.Combine(location, nameof(Operations), "Testdata", FILE_NAME)); var settings = new AppSettings { ConfigurationMode = ConfigurationMode.ConfigureClient }; currentSession.Settings = currentSettings; sessionContext.ReconfigurationFilePath = resource.LocalPath; repository.Setup(r => r.TryLoadSettings(It.Is <Uri>(u => u.Equals(resource)), out settings, It.IsAny <PasswordParameters>())).Returns(LoadStatus.PasswordNeeded); var sut = new ConfigurationOperation(null, repository.Object, fileSystem.Object, hashAlgorithm.Object, logger.Object, sessionContext); sut.ActionRequired += args => { if (args is PasswordRequiredEventArgs p) { p.Success = false; } }; var result = sut.Repeat(); fileSystem.Verify(f => f.Delete(It.Is <string>(s => s == resource.LocalPath)), Times.Once); Assert.AreEqual(OperationResult.Aborted, result); }
public void Repeat_MustDeleteTemporaryFileAfterClientConfiguration() { var currentSettings = new AppSettings(); var location = Path.GetDirectoryName(GetType().Assembly.Location); var resource = new Uri(Path.Combine(location, nameof(Operations), "Testdata", FILE_NAME)); var settings = new AppSettings { ConfigurationMode = ConfigurationMode.ConfigureClient }; var delete = 0; var configure = 0; var order = 0; currentSession.Settings = currentSettings; sessionContext.ReconfigurationFilePath = resource.LocalPath; fileSystem.Setup(f => f.Delete(It.IsAny <string>())).Callback(() => delete = ++order); repository.Setup(r => r.TryLoadSettings(It.Is <Uri>(u => u.Equals(resource)), out settings, It.IsAny <PasswordParameters>())).Returns(LoadStatus.Success); repository.Setup(r => r.ConfigureClientWith(It.Is <Uri>(u => u.Equals(resource)), It.IsAny <PasswordParameters>())).Returns(SaveStatus.Success).Callback(() => configure = ++order); var sut = new ConfigurationOperation(null, repository.Object, fileSystem.Object, hashAlgorithm.Object, logger.Object, sessionContext); var result = sut.Repeat(); fileSystem.Verify(f => f.Delete(It.Is <string>(s => s == resource.LocalPath)), Times.Once); repository.Verify(r => r.TryLoadSettings(It.Is <Uri>(u => u.Equals(resource)), out settings, It.IsAny <PasswordParameters>()), Times.AtLeastOnce); repository.Verify(r => r.ConfigureClientWith(It.Is <Uri>(u => u.Equals(resource)), It.IsAny <PasswordParameters>()), Times.Once); Assert.AreEqual(OperationResult.Success, result); Assert.AreEqual(1, configure); Assert.AreEqual(2, delete); }
public void Repeat_MustFailWithInvalidUri() { var resource = new Uri("file:///C:/does/not/exist.txt"); var settings = default(Settings); sessionContext.ReconfigurationFilePath = null; repository.Setup(r => r.TryLoadSettings(It.IsAny<Uri>(), out settings, It.IsAny<PasswordParameters>())).Returns(LoadStatus.Success); var sut = new ConfigurationOperation(null, repository.Object, hashAlgorithm.Object, logger.Object, sessionContext); var result = sut.Repeat(); repository.Verify(r => r.TryLoadSettings(It.Is<Uri>(u => u.Equals(resource)), out settings, It.IsAny<PasswordParameters>()), Times.Never); Assert.AreEqual(OperationResult.Failed, result); sessionContext.ReconfigurationFilePath = resource.LocalPath; result = sut.Repeat(); repository.Verify(r => r.TryLoadSettings(It.Is<Uri>(u => u.Equals(resource)), out settings, It.IsAny<PasswordParameters>()), Times.Never); Assert.AreEqual(OperationResult.Failed, result); }
public void Repeat_MustPerformForExamWithCorrectUri() { var currentSettings = new Settings(); var location = Path.GetDirectoryName(GetType().Assembly.Location); var resource = new Uri(Path.Combine(location, nameof(Operations), FILE_NAME)); var settings = new Settings { ConfigurationMode = ConfigurationMode.Exam }; currentSession.SetupGet(s => s.Settings).Returns(currentSettings); sessionContext.ReconfigurationFilePath = resource.LocalPath; repository.Setup(r => r.TryLoadSettings(It.Is<Uri>(u => u.Equals(resource)), out settings, It.IsAny<PasswordParameters>())).Returns(LoadStatus.Success); var sut = new ConfigurationOperation(null, repository.Object, hashAlgorithm.Object, logger.Object, sessionContext); var result = sut.Repeat(); nextSession.VerifySet(s => s.Settings = settings, Times.Once); repository.Verify(r => r.TryLoadSettings(It.Is<Uri>(u => u.Equals(resource)), out settings, It.IsAny<PasswordParameters>()), Times.AtLeastOnce); repository.Verify(r => r.ConfigureClientWith(It.Is<Uri>(u => u.Equals(resource)), It.IsAny<PasswordParameters>()), Times.Never); Assert.AreEqual(OperationResult.Success, result); }