Пример #1
0
        public void Write_NotExistingFile_FileIsCreated()
        {
            var persp = BuildFakeMetadata();

            //Build the fullpath for the file to read
            var filename = Path.Combine(DiskOnFile.GetDirectoryPath(), @"MetadataNotExistingFile.xls");

            //set the object to test
            var mew = new MetadataExcelOleDbWriter(filename);
            mew.SheetName = "MySheet";
            mew.Write(persp);

            //Assertion
            Assert.IsTrue(File.Exists(filename));
        }
Пример #2
0
        public void Write_NotExistingSheet_FileBiggerThanOriginal()
        {
            var persp = BuildFakeMetadata();

            //Build the fullpath for the file to read
            var filename = DiskOnFile.CreatePhysicalFile("MetadataNotExistingSheet.xls", "NBi.Testing.Unit.Core.Analysis.Metadata.Resources.MetadataExcelSample.xls");
            var initLength = new FileInfo(filename).Length;

            //set the object to test
            var mew = new MetadataExcelOleDbWriter(filename);
            mew.SheetName = "NotExistingMetadata";
            mew.Write(persp);

            //Assertion
            Assert.Greater(new FileInfo(filename).Length, initLength);
        }
Пример #3
0
        private void saveAsMetadataToolStripMenuItem_Click(object sender, EventArgs e)
        {
            StartClick(null);
            var cfg = Configuration.Project.Directories[Configuration.DirectoryCollection.DirectoryType.Metadata];
            using (var sfd = new SaveFileDialog())
            {
                sfd.InitialDirectory =cfg.Path;
                sfd.FileName = cfg.File;
                sfd.Filter = "CSV|*.csv|Excel 97-2003|*.xls";
                if(!string.IsNullOrEmpty(cfg.File))
                    sfd.FilterIndex = cfg.File.EndsWith("csv") ? 1 : 2;

                if (sfd.ShowDialog() == DialogResult.OK)
                {
                    IMetadataWriter mw = null;
                    switch (Path.GetExtension(sfd.FileName))
                    {
                        case ".csv":
                            mw = new MetadataCsvWriter(sfd.FileName);
                            break;
                        case ".xls":
                        case ".xlsx":
                            mw = new MetadataExcelOleDbWriter(sfd.FileName);
                            var saveForm = new MetadataSave();
                            saveForm.MetadataWriter = mw;
                            if (saveForm.ShowDialog() != DialogResult.OK)
                            {
                                EndClick(null);
                                return;
                            }
                            break;
                        default:
                            throw new NotImplementedException();
                    }

                    mw.ProgressStatusChanged += new ProgressStatusHandler(ProgressStatus);
                    mw.Write(Metadata);
                    mw.ProgressStatusChanged -= new ProgressStatusHandler(ProgressStatus);

                    cfg.FullFileName = sfd.FileName;
                }
            }
            EndClick(null);
        }