Implement validator for repo name warning

This commit is contained in:
Haacked 2015-03-17 00:15:02 -07:00
Родитель 6caab8a4d7
Коммит b2bf96bd29
2 изменённых файлов: 34 добавлений и 0 удалений

Просмотреть файл

@ -28,6 +28,7 @@ namespace GitHub.ViewModels
readonly ReactiveCommand<object> browseForDirectoryCommand = ReactiveCommand.Create();
readonly ReactiveCommand<object> createRepositoryCommand = ReactiveCommand.Create();
[ImportingConstructor]
public RepositoryCreationViewModel(IOperatingSystem operatingSystem)
{
this.operatingSystem = operatingSystem;
@ -56,6 +57,13 @@ namespace GitHub.ViewModels
.IfTrue(x => x.Length > 200, "Path too long")
.IfContainsInvalidPathChars("Path contains invalid characters")
.IfPathNotRooted("Please enter a valid path");
SafeRepositoryNameWarningValidator = ReactivePropertyValidator.ForObservable(nonNullRepositoryName)
.Add(repoName =>
{
var parsedReference = GetSafeRepositoryName(repoName);
return parsedReference != repoName ? "Will be created as " + parsedReference : null;
});
}
public string Title { get { return "Create a GitHub Repository"; } } // TODO: this needs to be contextual

Просмотреть файл

@ -219,6 +219,32 @@ public class RepositoryCreationViewModelTests
}
}
public class TheSafeRepositoryNameWarningValidatorProperty
{
[Fact]
public void IsTrueWhenRepoNameIsSafe()
{
var vm = new RepositoryCreationViewModel(Substitute.For<IOperatingSystem>());
vm.BaseRepositoryPath = @"c:\fake\";
vm.RepositoryName = "this-is-bad";
Assert.True(vm.SafeRepositoryNameWarningValidator.ValidationResult.IsValid);
}
[Fact]
public void IsFalseWhenRepoNameIsNotSafe()
{
var vm = new RepositoryCreationViewModel(Substitute.For<IOperatingSystem>());
vm.BaseRepositoryPath = @"c:\fake\";
vm.RepositoryName = "this is bad";
Assert.False(vm.SafeRepositoryNameWarningValidator.ValidationResult.IsValid);
Assert.Equal("Will be created as this-is-bad", vm.SafeRepositoryNameWarningValidator.ValidationResult.Message);
}
}
public class TheAccountsProperty
{
[Fact]