Exemplo n.º 1
0
        private static void ReadFile(string filename, out int varCount, out int rowCount)
        {
            FileStream readFileStream = new FileStream(filename, FileMode.Open, FileAccess.Read,
                                                       FileShare.Read, 2048 * 10, FileOptions.SequentialScan);

            try
            {
                TestSpssReader.ReadData(readFileStream, out varCount, out rowCount);
            }
            finally
            {
                readFileStream.Close();
            }
        }
Exemplo n.º 2
0
        public void TestWriteDoubleLongStringVar()
        {
            var filename = @"testWriteDoubleLongString.sav";

            using (FileStream fileStream = new FileStream(filename, FileMode.Create, FileAccess.Write))
            {
                var var1 = new Variable("stringvar_01")
                {
                    Label     = "This is a string variable",
                    Type      = DataType.Text,
                    Width     = 50,
                    TextWidth = 5000
                };

                var var2 = new Variable("stringvar_02")
                {
                    Label       = "This is a string variable",
                    PrintFormat = new OutputFormat(FormatType.A, 60),
                    WriteFormat = new OutputFormat(FormatType.A, 70),
                    Type        = DataType.Text,
                    Width       = 50,
                    TextWidth   = 5000
                };

                var var3 = new Variable("stringvar_03")
                {
                    Label       = "This is a string variable",
                    PrintFormat = new OutputFormat(FormatType.A, 60),
                    WriteFormat = new OutputFormat(FormatType.A, 70),
                    Type        = DataType.Text,
                    Width       = 50,
                    TextWidth   = 5000
                };

                var var4 = new Variable("stringvar_04")
                {
                    Label     = "This is a string variable",
                    Type      = DataType.Text,
                    Width     = 50,
                    TextWidth = 50
                };

                var var5 = new Variable("stringvar_05")
                {
                    Label     = "This is a string variable",
                    Type      = DataType.Text,
                    Width     = 4,
                    TextWidth = 4
                };

                var var6 = new Variable("LIKES")
                {
                    Label       = "This is a string variable",
                    PrintFormat = new OutputFormat(FormatType.A, 255),
                    WriteFormat = new OutputFormat(FormatType.A, 255),
                    Type        = DataType.Text,
                    Width       = 50,
                    TextWidth   = 1026
                };


                var variables = new List <Variable>
                {
                    var1,
                    var2,
                    var3,
                    var4,
                    var5,
                    var6
                };

                var options = new SpssOptions();

                using (var writer = new SpssWriter(fileStream, variables, options))
                {
                    object[] newRecord = writer.CreateRecord();
                    newRecord[0] = "test";
                    newRecord[1] = "test";
                    newRecord[2] = "Lorem";
                    //newRecord[3] = 200d;
                    writer.WriteRecord(newRecord);
                    writer.EndFile();
                }
            }


            FileStream readFileStream = new FileStream(filename, FileMode.Open, FileAccess.Read,
                                                       FileShare.Read, 2048 * 10, FileOptions.SequentialScan);

            TestSpssReader.ReadData(readFileStream, out int varCount, out int rowCount);

            Assert.AreEqual(varCount, 6, "Variable count does not match");
            Assert.AreEqual(rowCount, 1, "Rows count does not match");
        }