public void ShouldRaisePropertyChangedForErrorMessageWhenFailedResultChangedToSuccessful() { var validPath = @"data.xlsx"; var data = new[] { new Dictionary <string, double> { { "five", 0 }, { "six", 0 } } }; var successfulResult = DataResult.CreateSuccessful(data); FakeProvider.GetFrom(validPath).Returns(successfulResult); var invalidPath = @"notexisted.file"; var failedResult = DataResult.CreateFailed("File not found"); FakeProvider.GetFrom(invalidPath).Returns(failedResult); ViewModel.LoadDataCommand.Execute(invalidPath); ViewModel.MonitorEvents(); ViewModel.LoadDataCommand.Execute(validPath); ViewModel.ShouldRaisePropertyChangeFor(viewModel => viewModel.ErrorMessage); }
public void CreateFailed_ShouldReturnResultWithErrorMessageEqualsGivenMessage() { var errorMessage = "File not found"; var result = DataResult.CreateFailed(errorMessage); result.ErrorMessage.Should().Be(errorMessage); }
public void CreateFailed_ShouldReturnResultWithEmptyData() { var errorMessage = "something gone wrong"; var result = DataResult.CreateFailed(errorMessage); result.Data.Should().BeEmpty(); }
public void ShouldClearColumnsWhenGetFailedResult() { var path = @"notExistedFile.xls"; var failedResult = DataResult.CreateFailed("File not found"); FakeProvider.GetFrom(path).Returns(failedResult); ViewModel.LoadDataCommand.Execute(path); ViewModel.Columns.Should().BeEmpty(); }
public DataResult Read(string path) { try { return(ReadImpl(path)); } catch (Exception exception) { return(DataResult.CreateFailed(exception.Message)); } }
public void ShouldRaiseOnPropertyChangedForErrorMessageWhenGetFailedResult() { var path = @"file.txt"; var failedResult = DataResult.CreateFailed("Provider doesn not support this type of file"); FakeProvider.GetFrom(path).Returns(failedResult); ViewModel.MonitorEvents(); ViewModel.LoadDataCommand.Execute(path); ViewModel.ShouldRaisePropertyChangeFor(viewModel => viewModel.ErrorMessage); }
public void GetFrom_ShouldReturnFailedResultWithMessageProvidedByDataReader(string fileName, string fileExtension, string errorMessage) { var path = $"{fileName}.{fileExtension}"; var expectedResult = DataResult.CreateFailed(errorMessage); _fakeReaderProvider.GetByExtension(fileExtension).Returns(_fakeReader); _fakeReader.Read(path).Returns(expectedResult); var result = _provider.GetFrom(path); result.ShouldBeEquivalentTo(expectedResult); }
public DataResult Read(string path) { return(DataResult.CreateFailed($"Reader not found for file {path}")); }