public void SetUp()
        {
            var data = new[]
            {
                new Dictionary <string, double>
                {
                    { "one", 0.00052 },
                    { "two", 2.17 },
                    { "three", 3.14 },
                    { "four", 4.42 },
                    { "five", 1.5 },
                    { "six", 16 },
                    { "seven", 71.51 },
                    { "eight", 64.12 },
                    { "nine", 29.00900 },
                    { "ten", 1.00010010001 },
                }
            };

            var dataResult = DataResult.CreateSuccessful(data);

            FakeProvider.GetFrom(null).ReturnsForAnyArgs(dataResult);

            ViewModel.LoadDataCommand.Execute("dummy.path");
        }
Example #2
0
        public void ShouldUpdateColumnsWithUniqueValuesWhenGetSuccessfulResult()
        {
            var validPath = @"somefile.xls";
            var data      = new[]
            {
                new Dictionary <string, double> {
                    { "one", 1.23 }, { "two", 45 }
                },
                new Dictionary <string, double> {
                    { "one", 1.0 }, { "two", 128.7 }
                },
                new Dictionary <string, double> {
                    { "one", 3.14 }, { "two", 0.123 }
                }
            };
            var result = DataResult.CreateSuccessful(data);

            FakeProvider.GetFrom(validPath).Returns(result);
            var expectedColumns = new[]
            {
                new DataColumnViewModel("one")
                {
                    SelectionType = SelectionType.NotSelected
                },
                new DataColumnViewModel("two")
                {
                    SelectionType = SelectionType.NotSelected
                }
            };

            ViewModel.LoadDataCommand.Execute(validPath);

            ViewModel.Columns.ShouldBeEquivalentTo(expectedColumns);
        }
Example #3
0
        public void ShouldResetReportData()
        {
            var inputData = new ScatterInputData
            {
                Data = new[]
                {
                    new Dictionary <string, double> {
                        { "seven", 0.00052 }, { "eight", 1.000012 }, { "nine", 1.1 }
                    },
                    new Dictionary <string, double> {
                        { "seven", 0.0000010101 }, { "eight", 0.12456 }, { "nine", 1.2 }
                    }
                },
                AbscissaColumnName = "seven",
                OrdinateColumnName = "eight"
            };

            var dataResult = DataResult.CreateSuccessful(inputData.Data);

            FakeProvider.GetFrom(null).ReturnsForAnyArgs(dataResult);

            var dummyReportData = GenerateDummyReportData();

            FakeScatterReportCalculator.Calculate(null).ReturnsForAnyArgs(dummyReportData);

            ViewModel.LoadDataCommand.Execute("dummy.path");
            var(abscissaColumn, ordinateColumn) = SelectColumnsForReport("seven", "nine");
            ViewModel.GenerateReportDataCommand.Execute(null);

            ViewModel.LoadDataCommand.Execute("dummy2.path");

            ViewModel.Report.ShouldBeEquivalentTo(ScatterReportData.Empty);
        }
Example #4
0
        public void ShouldPassCorrectInputValuesToTheCalculatorWhenSuccessfulyLoadData()
        {
            ScatterInputData actualInputData = null;
            var expectedInputData            = new ScatterInputData
            {
                Data = new[]
                {
                    new Dictionary <string, double> {
                        { "seven", 0.00052 }, { "eight", 1.000012 }, { "nine", 1.1 }
                    },
                    new Dictionary <string, double> {
                        { "seven", 0.0000010101 }, { "eight", 0.12456 }, { "nine", 1.2 }
                    }
                },
                AbscissaColumnName = "seven",
                OrdinateColumnName = "eight"
            };

            var dataResult = DataResult.CreateSuccessful(expectedInputData.Data);

            FakeProvider.GetFrom(null).ReturnsForAnyArgs(dataResult);

            var dummyReportData = new ScatterReportData(Enumerable.Empty <ScatterPoint>(), new ScatterLine(new ScatterPoint(), new ScatterPoint()));

            FakeScatterReportCalculator.Calculate(Arg.Do <ScatterInputData>(input => actualInputData = input)).ReturnsForAnyArgs(dummyReportData);

            ViewModel.LoadDataCommand.Execute("dummy.path");
            SelectColumnsForReport("seven", "eight");

            ViewModel.GenerateReportDataCommand.Execute(null);

            actualInputData.ShouldBeEquivalentTo(expectedInputData);
        }
Example #5
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);
        }
Example #6
0
        protected override DataResult ReadImpl(string path)
        {
            var rawData = File.ReadAllText(path);
            var data    = Newtonsoft.Json.JsonConvert.DeserializeObject <List <Dictionary <string, double> > >(rawData);

            return(DataResult.CreateSuccessful(data));
        }
Example #7
0
        protected override DataResult ReadImpl(string path)
        {
            using (var document = SpreadsheetDocument.Open(path, false))
            {
                var sheet         = document.WorkbookPart.WorksheetParts.First();
                var sharedStrings = TryLoadSharedStrings(document);
                var cellReader    = new CellReader(sharedStrings);

                var data = ReadValues(sheet, cellReader);

                return(DataResult.CreateSuccessful(data));
            }
        }
Example #8
0
        private void ConfigureDataForCanExecuteTests()
        {
            var data = new[]
            {
                new Dictionary <string, double> {
                    { "one", 0.00052 }, { "two", 1.000012 }, { "three", 1.1 }
                }
            };

            var dataResult = DataResult.CreateSuccessful(data);

            FakeProvider.GetFrom(null).ReturnsForAnyArgs(dataResult);

            ViewModel.LoadDataCommand.Execute("dummy.path");
        }
Example #9
0
        public void CreateSuccessful_ShouldReturnResultWithGivenData()
        {
            var expectedData = new[]
            {
                new Dictionary <string, double> {
                    { "test", 12.3 }, { "age", 34 }
                },
                new Dictionary <string, double> {
                    { "test", 12.87 }, { "age", 45 }
                }
            };

            var result = DataResult.CreateSuccessful(expectedData);

            result.Data.ShouldBeEquivalentTo(expectedData);
        }
Example #10
0
        public void CreateSuccessful_ShouldReturnResultWithErrorMessageEqualsNull()
        {
            var data = new[]
            {
                new Dictionary <string, double> {
                    { "second", 497.3 }, { "third", 3.1415 }
                },
                new Dictionary <string, double> {
                    { "second", 6.87 }, { "third", 0.12 }
                }
            };

            var result = DataResult.CreateSuccessful(data);

            result.ErrorMessage.Should().BeNull();
        }
Example #11
0
        public void ShouldRaisePropertyChangedForAbscissaColumnName()
        {
            var validPath = @"anotherFile.xls";
            var data      = new[]
            {
                new Dictionary <string, double> {
                    { "three", 1.23 }, { "five", 4.785 }, { "two", 42 }
                }
            };
            var result = DataResult.CreateSuccessful(data);

            FakeProvider.GetFrom(validPath).Returns(result);
            ViewModel.MonitorEvents();

            ViewModel.LoadDataCommand.Execute(validPath);

            ViewModel.ShouldRaisePropertyChangeFor(viewmodel => viewmodel.AbscissaColumnName);
        }
Example #12
0
        public void ShouldRaiseCanExecuteForGenerateReportDataCommand()
        {
            var validPath = @"anotherFile.xls";
            var data      = new[]
            {
                new Dictionary <string, double> {
                    { "three", 1.23 }, { "five", 4.785 }, { "two", 42 }
                }
            };
            var result = DataResult.CreateSuccessful(data);

            FakeProvider.GetFrom(validPath).Returns(result);
            ViewModel.GenerateReportDataCommand.MonitorEvents();

            ViewModel.LoadDataCommand.Execute(validPath);

            ViewModel.GenerateReportDataCommand.ShouldRaise("CanExecuteChanged");
        }
Example #13
0
        public void ShouldClearErrorMessageWhenGetSuccessfulResult()
        {
            var validPath = @"file.csv";
            var data      = new[]
            {
                new Dictionary <string, double> {
                    { "three", 0.2 }, { "four", -45.34 }
                },
                new Dictionary <string, double> {
                    { "three", 0 }, { "four", 1.55 }
                }
            };
            var result = DataResult.CreateSuccessful(data);

            FakeProvider.GetFrom(validPath).Returns(result);

            ViewModel.LoadDataCommand.Execute(validPath);

            ViewModel.ErrorMessage.Should().BeNull();
        }
        public void GetFrom_ShouldReturnSuccessfulResultReturnedByProvidedReader(string fileName, string fileExtension)
        {
            var path = $"{fileName}.{fileExtension}";
            var data = new[]
            {
                new Dictionary <string, double> {
                    { "one", 1.1 }, { "two", 2.1 }
                },
                new Dictionary <string, double> {
                    { "one", 1.2 }, { "two", 2.2 }
                }
            };
            var expectedResult = DataResult.CreateSuccessful(data);

            _fakeReaderProvider.GetByExtension(fileExtension).Returns(_fakeReader);
            _fakeReader.Read(path).Returns(expectedResult);

            var result = _provider.GetFrom(path);

            result.ShouldBeEquivalentTo(expectedResult);
        }
Example #15
0
        protected override DataResult ReadImpl(string path)
        {
            var data = new List <Dictionary <string, double> >();

            using (var reader = new StreamReader(path))
            {
                List <string> columnNames = null;
                while (reader.EndOfStream == false)
                {
                    if (columnNames == null)
                    {
                        columnNames = ReadValues(reader).ToList();
                    }

                    var values = ReadLineData(reader, columnNames);
                    data.Add(values);
                }
            }

            return(DataResult.CreateSuccessful(data));
        }
Example #16
0
        public void Read_ShouldReturnSuccessfulResultWithExpectedData()
        {
            var path = TestUtils.BuildPathFor(@"DataReadersTestCases\ExcelDataReaderTestCase1.xlsx");
            var data = new[]
            {
                new Dictionary <string, double> {
                    { "one", 1.1 }, { "two", 1.2 }, { "three", 1.3 }
                },
                new Dictionary <string, double> {
                    { "one", 2.1 }, { "two", 2.2 }, { "three", 2.3 }
                },
                new Dictionary <string, double> {
                    { "one", 3.1 }, { "two", 3.2 }, { "three", 3.3 }
                }
            };
            var expectedResult = DataResult.CreateSuccessful(data);
            var reader         = new ExcelDataReader();

            var result = reader.Read(path);

            result.ShouldBeEquivalentTo(expectedResult);
        }
Example #17
0
        public void Read_ShouldReturnSuccessfulResultWithExpectedDataWhenFileInProtectedView()
        {
            var path = TestUtils.BuildPathFor(@"DataReadersTestCases\ExcelDataReaderTestCase3ProtectedView.xlsx");
            var data = new[]
            {
                new Dictionary <string, double> {
                    { "one", 30.24 }, { "two", 256 }, { "three", 0.4099 }
                },
                new Dictionary <string, double> {
                    { "one", 30.84 }, { "two", 338 }, { "three", 0.0312 }
                },
                new Dictionary <string, double> {
                    { "one", 16.92 }, { "two", 357 }, { "three", 0.4993 }
                }
            };
            var expectedResult = DataResult.CreateSuccessful(data);
            var reader         = new ExcelDataReader();

            var result = reader.Read(path);

            result.ShouldBeEquivalentTo(expectedResult);
        }