Exemple #1
0
        public void TestExportWithCurrentLanguage()
        {
            CultureInfo       cultureInfo       = CultureInfo.CurrentUICulture;
            SkylineDataSchema skylineDataSchema =
                new SkylineDataSchema(CreateMemoryDocumentContainer(LoadTestDocument()), SkylineDataSchema.GetLocalizedSchemaLocalizer());
            SkylineViewContext viewContext = new DocumentGridViewContext(skylineDataSchema);

            string testFile  = Path.Combine(TestContext.TestDir, "TestExportWithCurrentLanguage.csv");
            char   separator = TextUtil.GetCsvSeparator(cultureInfo);
            var    dsvWriter = new DsvWriter(cultureInfo, separator);

            viewContext.ExportToFile(null, GetTestReport(skylineDataSchema), testFile, dsvWriter);
            string strExported   = File.ReadAllText(testFile);
            var    actualLines   = strExported.Split(new[] { Environment.NewLine }, StringSplitOptions.None);
            var    expectedLines = ExpectedInvariantReport.Split(new[] { Environment.NewLine }, StringSplitOptions.None);

            var invariantHeaders = expectedLines[0].Split(',');
            var expectedHeaders  =
                invariantHeaders.Select(header => ColumnCaptions.ResourceManager.GetString(header, cultureInfo) ?? header).ToArray();
            var actualHeaders = actualLines[0].Split(separator);

            CollectionAssert.AreEqual(expectedHeaders, actualHeaders);
            // If the language in English, then the exported report will be identical to the invariant report except for the headers
            if (cultureInfo.Name == "en-US")
            {
                CollectionAssert.AreEqual(expectedLines.Skip(1).ToArray(), actualLines.Skip(1).ToArray());
            }
        }
Exemple #2
0
        public void TestInvariantExport()
        {
            SkylineDataSchema skylineDataSchema =
                new SkylineDataSchema(CreateMemoryDocumentContainer(LoadTestDocument()), DataSchemaLocalizer.INVARIANT);
            SkylineViewContext viewContext = new DocumentGridViewContext(skylineDataSchema);

            string testFile  = Path.Combine(TestContext.TestDir, "TestInvariantExport.csv");
            var    dsvWriter = new DsvWriter(CultureInfo.InvariantCulture, ',');

            viewContext.ExportToFile(null, GetTestReport(skylineDataSchema), testFile, dsvWriter);
            string strExported = File.ReadAllText(testFile);

            Assert.AreEqual(ExpectedInvariantReport, strExported);
            // Assert that the file written out was UTF8 encoding without any byte order mark
            byte[] bytesExported = File.ReadAllBytes(testFile);
            CollectionAssert.AreEqual(Encoding.UTF8.GetBytes(strExported), bytesExported);
        }