diff --git a/tests/Camelot.ViewModels.Tests/SearchViewModelTests.cs b/tests/Camelot.ViewModels.Tests/SearchViewModelTests.cs index 9de783d7..53e77ead 100644 --- a/tests/Camelot.ViewModels.Tests/SearchViewModelTests.cs +++ b/tests/Camelot.ViewModels.Tests/SearchViewModelTests.cs @@ -13,14 +13,27 @@ namespace Camelot.ViewModels.Tests public class SearchViewModelTests { private const string SearchText = "text"; + private const string Error = "error"; + private const string ResourceName = "ResourceName"; + + private readonly IResourceProvider _resourceProvider; + + public SearchViewModelTests() + { + var resourceProviderMock = new Mock(); + resourceProviderMock + .Setup(m => m.GetResourceByName(ResourceName)) + .Returns(Error); + + _resourceProvider = resourceProviderMock.Object; + } [Fact] public void TestDefaults() { var regexServiceMock = new Mock(); - var resourceProviderMock = new Mock(); - var configuration = new SearchViewModelConfiguration(); - var viewModel = new SearchViewModel(regexServiceMock.Object, resourceProviderMock.Object, configuration); + var configuration = GetConfiguration(); + var viewModel = new SearchViewModel(regexServiceMock.Object, _resourceProvider, configuration); Assert.False(viewModel.IsSearchEnabled); Assert.False(viewModel.IsRegexSearchEnabled); @@ -31,12 +44,11 @@ public void TestDefaults() [Fact] public void TestToggle() { - var configuration = new SearchViewModelConfiguration(); + var configuration = GetConfiguration(); var regexServiceMock = new Mock(); - var resourceProviderMock = new Mock(); - var viewModel = new SearchViewModel(regexServiceMock.Object, resourceProviderMock.Object, configuration); + var viewModel = new SearchViewModel(regexServiceMock.Object, _resourceProvider, configuration); Assert.False(viewModel.IsSearchEnabled); viewModel.SearchText = SearchText; @@ -68,9 +80,8 @@ public void TestSpecification(bool isSearchEnabled, bool isRegexSearchEnabled, regexServiceMock .Setup(m => m.ValidateRegex(It.IsAny())) .Returns(isRegexValid); - var resourceProviderMock = new Mock(); - var configuration = new SearchViewModelConfiguration(); - var viewModel = new SearchViewModel(regexServiceMock.Object, resourceProviderMock.Object, configuration) + var configuration = GetConfiguration(); + var viewModel = new SearchViewModel(regexServiceMock.Object, _resourceProvider, configuration) { IsSearchEnabled = isSearchEnabled, IsRegexSearchEnabled = isRegexSearchEnabled @@ -87,12 +98,8 @@ public async Task TestTextChangedChanged() var taskCompletionSource = new TaskCompletionSource(); var regexServiceMock = new Mock(); - var resourceProviderMock = new Mock(); - var configuration = new SearchViewModelConfiguration - { - TimeoutMs = 10 - }; - var viewModel = new SearchViewModel(regexServiceMock.Object, resourceProviderMock.Object, configuration); + var configuration = GetConfiguration(); + var viewModel = new SearchViewModel(regexServiceMock.Object, _resourceProvider, configuration); viewModel.SearchSettingsChanged += (sender, args) => taskCompletionSource.SetResult(true); viewModel.SearchText = "test"; @@ -107,12 +114,8 @@ public async Task TestSearchCaseChanged() var taskCompletionSource = new TaskCompletionSource(); var regexServiceMock = new Mock(); - var resourceProviderMock = new Mock(); - var configuration = new SearchViewModelConfiguration - { - TimeoutMs = 10 - }; - var viewModel = new SearchViewModel(regexServiceMock.Object, resourceProviderMock.Object, configuration); + var configuration = GetConfiguration(); + var viewModel = new SearchViewModel(regexServiceMock.Object, _resourceProvider, configuration); viewModel.SearchSettingsChanged += (sender, args) => taskCompletionSource.SetResult(true); viewModel.IsSearchCaseSensitive = true; @@ -132,12 +135,8 @@ public async Task TestRegexChanged(bool isRegexValid) regexServiceMock .Setup(m => m.ValidateRegex(SearchText)) .Returns(isRegexValid); - var resourceProviderMock = new Mock(); - var configuration = new SearchViewModelConfiguration - { - TimeoutMs = 10 - }; - var viewModel = new SearchViewModel(regexServiceMock.Object, resourceProviderMock.Object, configuration); + var configuration = GetConfiguration(); + var viewModel = new SearchViewModel(regexServiceMock.Object, _resourceProvider, configuration); viewModel.SearchSettingsChanged += (sender, args) => taskCompletionSource.SetResult(true); viewModel.SearchText = SearchText; @@ -146,5 +145,12 @@ public async Task TestRegexChanged(bool isRegexValid) var task = await Task.WhenAny(Task.Delay(1000), taskCompletionSource.Task); Assert.Equal(isRegexValid, taskCompletionSource.Task == task); } + + private static SearchViewModelConfiguration GetConfiguration() => + new SearchViewModelConfiguration + { + InvalidRegexResourceName = ResourceName, + TimeoutMs = 10 + }; } } \ No newline at end of file