예제 #1
0
        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);
        }
예제 #2
0
        public void CreateFailed_ShouldReturnResultWithErrorMessageEqualsGivenMessage()
        {
            var errorMessage = "File not found";

            var result = DataResult.CreateFailed(errorMessage);

            result.ErrorMessage.Should().Be(errorMessage);
        }
예제 #3
0
        public void CreateFailed_ShouldReturnResultWithEmptyData()
        {
            var errorMessage = "something gone wrong";

            var result = DataResult.CreateFailed(errorMessage);

            result.Data.Should().BeEmpty();
        }
예제 #4
0
        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();
        }
예제 #5
0
 public DataResult Read(string path)
 {
     try
     {
         return(ReadImpl(path));
     }
     catch (Exception exception)
     {
         return(DataResult.CreateFailed(exception.Message));
     }
 }
예제 #6
0
        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);
        }
예제 #7
0
        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}"));
 }