public async void Export_NameFile_FileNotFound()
        {
            DecisionModel decision     = this.Prototype;
            var           csvPersister = new CsvPersisterCreateFileDecorator(TestingDirectory, CsvFileName, DecisionModel.Separator);

            // Bloc 2 : Exporter tout
            {
                var decisionList = new List <DecisionModel> {
                    decision
                };

                foreach (DecisionModel decisionModel in decisionList)
                {
                    await csvPersister.StoreDecisionAsync(decisionModel);
                }
            }

            // Bloc final : vérification que le fichier csv existe
            {
                DecisionModel csv = (await csvPersister.FetchAllAsync()).Single();
                Assert.AreEqual(decision, csv);
            }
        }
Example #2
0
        private async void Export()
        {
            var saveFileDialog = new SaveFileDialog
            {
                InitialDirectory = "C:\\",
                Filter           = "csv files (*.csv)|*.csv",
                RestoreDirectory = true
            };

            var result = saveFileDialog.ShowDialog();

            if (result != true)
            {
                return;
            }

            var fileInfo     = new FileInfo(saveFileDialog.FileName);
            var directory    = new DirectoryInfoIDirectoryAdapter(new DirectoryInfo(fileInfo.DirectoryName ?? throw new InvalidOperationException()));
            var csvPersister = new CsvPersisterCreateFileDecorator(directory, fileInfo.Name, DecisionModel.Separator);



            try
            {
                foreach (DecisionModel decisionModel in await this._decisionSource.FetchAllAsync())
                {
                    await csvPersister.StoreDecisionAsync(decisionModel);
                }
                MessageBox.Show("L'export a bien été effectué.", "Confirmation");
            }

            catch (IOException)
            {
                MessageBox.Show("Impossible d'accéder au fichier, car il est en cours d'utilisation / déjà ouvert",
                                "Avertissement");
            }
        }