Beispiel #1
0
        public void DerivedTableCopyTo1()
        {
            var dataSet      = new CremaDataSet();
            var dataTable    = dataSet.Tables.Add("Table1");
            var childTable   = dataTable.Childs.Add();
            var derivedTable = dataTable.Inherit("derived");

            var tempPath = PathUtility.GetTempPath(true);

            try
            {
                dataSet.WriteToDirectory(tempPath);

                dataSet = new CremaDataSet();
                dataSet.ReadTable(Path.Combine(tempPath, CremaSchema.TableDirectory, derivedTable.Name + ".xml"));
                derivedTable = dataSet.Tables["derived"];

                var targetSet   = new CremaDataSet();
                var targetTable = derivedTable.CopyTo(targetSet);
                CremaComparer.CompareTable(derivedTable, targetTable);

                var schema = targetSet.GetXmlSchema();
            }
            finally
            {
                DirectoryUtility.Delete(tempPath);
            }
        }
Beispiel #2
0
        public static void CompareColumn(CremaDataColumn column1, CremaDataColumn column2)
        {
            if (column1 == null && column2 == null)
            {
                return;
            }
            if (column1 == null || column2 == null)
            {
                Assert.Fail("컬럼이 같지 않습니다.");
            }

            Assert.AreEqual(column1.AllowDBNull, column2.AllowDBNull, "AllowDBNull");
            Assert.AreEqual(column1.AutoIncrement, column2.AutoIncrement, "AutoIncrement");
            Assert.AreEqual(column1.ColumnName, column2.ColumnName, "ColumnName");
            Assert.AreEqual(column1.DataType, column2.DataType, "DataType");
            CremaComparer.CompareType(column1.CremaType, column2.CremaType);
            Assert.AreEqual(column1.DefaultValue, column2.DefaultValue, "DefaultValue");
            Assert.AreEqual(column1.Expression, column2.Expression, "Expression");
            Assert.AreEqual(column1.Validation, column2.Validation, "Validation");
            Assert.AreEqual(column1.Unique, column2.Unique, "Unique");
            Assert.AreEqual(column1.ReadOnly, column2.ReadOnly, "ReadOnly");
            Assert.AreEqual(column1.Comment, column2.Comment, "Comment");
            Assert.AreEqual(column1.IsKey, column2.IsKey, "IsKey");
            Assert.AreEqual(column1.CreationInfo, column2.CreationInfo, "CreationInfo");
            Assert.AreEqual(column1.ModificationInfo, column2.ModificationInfo, "ModificationInfo");
            Assert.AreEqual(column1.ColumnID, column2.ColumnID, "ColumnID");
            Assert.AreEqual(column1.Tags, column2.Tags, "Tags");
            Assert.AreEqual(column1.ColumnInfo, column2.ColumnInfo, "ColumnInfo");
            Assert.AreEqual(column1.Index, column2.Index, "Ordinal");
        }
Beispiel #3
0
        public void WriteToXmlWriter_ReadFromXmlReader()
        {
            var schemaBuilder = new StringBuilder();
            var xmlBuilder    = new StringBuilder();

            using (var schemaWriter = XmlWriter.Create(schemaBuilder))
            {
                this.dataSet.WriteXmlSchema(schemaWriter);
            }

            using (var xmlWriter = XmlWriter.Create(xmlBuilder))
            {
                this.dataSet.WriteXml(xmlWriter);
            }

            CremaDataSet dataSet = null;

            using (var sr = new StringReader(schemaBuilder.ToString()))
                using (var schemaReader = XmlReader.Create(sr))
                {
                    dataSet = CremaDataSet.ReadSchema(schemaReader);
                }

            using (var sr = new StringReader(xmlBuilder.ToString()))
                using (var xmlReader = XmlReader.Create(sr))
                {
                    dataSet.ReadXml(xmlReader);
                }

            CremaComparer.CompareDataSet(this.dataSet, dataSet);
        }
Beispiel #4
0
        public void WriteToXmlWriter_ReadFromXmlReader()
        {
            var dataSet = CremaDataSetExtensions.CreateRandomSet();
            var testSet = new CremaDataSet();

            foreach (var item in dataSet.Tables)
            {
                if (item.TemplateNamespace != string.Empty)
                {
                    continue;
                }

                var schemaBuilder = new StringBuilder();
                var xmlBuilder    = new StringBuilder();
                using (var schemaWriter = XmlWriter.Create(schemaBuilder))
                {
                    item.WriteXmlSchema(schemaWriter);
                }
                using (var xmlWriter = XmlWriter.Create(xmlBuilder))
                {
                    item.WriteXml(xmlWriter);
                }

                try
                {
                    using (var sr = new StringReader(schemaBuilder.ToString()))
                        using (var reader = XmlReader.Create(sr))
                        {
                            testSet.ReadXmlSchema(reader);
                        }
                    if (item.Columns.Where(i => i.CremaType != null).Any() == true)
                    {
                        Assert.Fail("테이블이 사용자타입을 사용하는 경우 읽어들이는데 실패를 해야함.");
                    }
                }
                catch
                {
                    using var sr     = new StringReader(schemaBuilder.ToString());
                    using var reader = XmlReader.Create(sr);
                    testSet.ReadXmlSchema(reader, new CremaTypeXmlResolver(dataSet, item.Namespace));
                }

                using (var sr = new StringReader(xmlBuilder.ToString()))
                    using (var reader = XmlReader.Create(sr))
                    {
                        testSet.ReadXml(reader);
                    }
            }

            foreach (var item in dataSet.Tables)
            {
                if (item.TemplateNamespace != string.Empty)
                {
                    continue;
                }
                var newTable = testSet.Tables[item.Name];
                CremaComparer.CompareTable(item, newTable);
            }
        }
        public void Test11()
        {
            var dataSet1  = new CremaDataSet();
            var dataType1 = dataSet1.AddRandomType();
            var dataSet2  = new CremaDataSet();
            var dataType2 = dataSet2.Types.Add(dataType1.TypeInfo);

            CremaComparer.CompareType(dataType1, dataType2);
        }
        public void XmlSerializing()
        {
            var dataSet = CremaDataSetExtensions.CreateRandomSet();

            foreach (var item in dataSet.Types)
            {
                string xml     = XmlSerializerUtility.GetString(item);
                var    newType = XmlSerializerUtility.ReadString <CremaDataType>(xml);

                CremaComparer.CompareType(item, newType);
            }
        }
Beispiel #7
0
        public void DerivedTableCopyTo()
        {
            var dataSet      = new CremaDataSet();
            var dataTable    = dataSet.Tables.Add("Table1");
            var childTable   = dataTable.Childs.Add();
            var derivedTable = dataTable.Inherit("derived");
            var targetSet    = new CremaDataSet();
            var targetTable  = derivedTable.CopyTo(targetSet);

            CremaComparer.CompareTable(derivedTable, targetTable);

            var schema = targetSet.GetXmlSchema();
        }
        public void WriteToString_ReadFromString()
        {
            var dataSet = CremaDataSetExtensions.CreateRandomSet();
            var testSet = new CremaDataSet();

            foreach (var item in dataSet.Types)
            {
                string schema = item.GetXmlSchema();
                testSet.ReadTypeString(schema);
                var newType = testSet.Types[item.TypeName];

                CremaComparer.CompareType(item, newType);
            }
        }
Beispiel #9
0
        public void WriteToStream_ReadFromStream()
        {
            var dataSet = CremaDataSetExtensions.CreateRandomSet();
            var testSet = new CremaDataSet();

            foreach (var item in dataSet.Tables)
            {
                if (item.TemplateNamespace != string.Empty)
                {
                    continue;
                }

                var schemaStream = new MemoryStream();
                var xmlStream    = new MemoryStream();

                item.WriteXmlSchema(schemaStream);
                item.WriteXml(xmlStream);

                //try
                //{
                //    schemaStream.Position = 0;
                //    testSet.ReadXmlSchema(schemaStream);
                //    if (item.Columns.Where(i => i.CremaType != null).Any() == true)
                //        Assert.Fail("테이블이 사용자타입을 사용하는 경우 읽어들이는데 실패를 해야함.");
                //}
                //catch
                //{
                //    if (item.Columns.Where(i => i.CremaType != null).Any() == false)
                //        Assert.Fail("스키마 읽어들이는데 실패함");

                schemaStream.Position = 0;
                testSet.ReadXmlSchema(schemaStream, new CremaTypeXmlResolver(dataSet, item.Namespace));
                //}

                xmlStream.Position = 0;
                testSet.ReadXml(xmlStream);
            }

            foreach (var item in dataSet.Tables)
            {
                if (item.TemplateNamespace != string.Empty)
                {
                    continue;
                }
                var newTable = testSet.Tables[item.Name];
                CremaComparer.CompareTable(item, newTable);
            }
        }
Beispiel #10
0
        public void WriteToTextWriter_ReadFromTextReader()
        {
            var schemaWriter = new StringWriter();
            var xmlWriter    = new StringWriter();

            this.dataSet.WriteXmlSchema(schemaWriter);
            this.dataSet.WriteXml(xmlWriter);

            var schemaReader = new StringReader(schemaWriter.ToString());
            var dataSet      = CremaDataSet.ReadSchema(schemaReader);
            var xmlReader    = new StringReader(xmlWriter.ToString());

            dataSet.ReadXml(xmlReader);

            CremaComparer.CompareDataSet(this.dataSet, dataSet);
        }
Beispiel #11
0
        public void WriteToStream_ReadFromStream()
        {
            var schemaStream = new MemoryStream();
            var xmlStream    = new MemoryStream();

            this.dataSet.WriteXmlSchema(schemaStream);
            this.dataSet.WriteXml(xmlStream);

            schemaStream.Position = 0;
            xmlStream.Position    = 0;

            var dataSet = CremaDataSet.ReadSchema(schemaStream);

            dataSet.ReadXml(xmlStream);

            CremaComparer.CompareDataSet(this.dataSet, dataSet);
        }
        public void WriteToTextWriter_ReaderFromTextReader()
        {
            var dataSet = CremaDataSetExtensions.CreateRandomSet();
            var testSet = new CremaDataSet();

            foreach (var item in dataSet.Types)
            {
                var sw = new StringWriter();
                item.Write(sw);

                var sr = new StringReader(sw.ToString());
                testSet.ReadType(sr);
                var newType = testSet.Types[item.TypeName];

                CremaComparer.CompareType(item, newType);
            }
        }
        public void WriteToStream_ReadFromStream()
        {
            var dataSet = CremaDataSetExtensions.CreateRandomSet();
            var testSet = new CremaDataSet();

            foreach (var item in dataSet.Types)
            {
                var ms = new MemoryStream();
                item.Write(ms);
                ms.Position = 0;

                testSet.ReadType(ms);
                var newType = testSet.Types[item.TypeName];

                CremaComparer.CompareType(item, newType);
            }
        }
        public void WriteToXmlWriter_ReaderFromXmlReader()
        {
            var dataSet = CremaDataSetExtensions.CreateRandomSet();
            var testSet = new CremaDataSet();

            foreach (var item in dataSet.Types)
            {
                var sb     = new StringBuilder();
                var writer = XmlWriter.Create(sb);
                item.Write(writer);
                writer.Close();

                var sr     = new StringReader(sb.ToString());
                var reader = XmlReader.Create(sr);
                testSet.ReadType(reader);
                var newType = testSet.Types[item.TypeName];

                CremaComparer.CompareType(item, newType);
            }
        }
        public void WriteToFile_ReadFromFile()
        {
            var dataSet = CremaDataSetExtensions.CreateRandomSet();
            var testSet = new CremaDataSet();

            foreach (var item in dataSet.Types)
            {
                string schemaPath = PathUtility.GetTempFileName();
                item.Write(schemaPath);

                try
                {
                    testSet.ReadType(schemaPath);
                }
                finally
                {
                    FileUtility.Delete(schemaPath);
                }

                var newType = testSet.Types[item.TypeName];
                CremaComparer.CompareType(item, newType);
            }
        }
Beispiel #16
0
        public static void CompareDataSet(CremaDataSet dataSet1, CremaDataSet dataSet2)
        {
            if (dataSet1 == null && dataSet2 == null)
            {
                return;
            }
            if (dataSet1 == null || dataSet2 == null)
            {
                Assert.Fail("타입이 같지 않습니다.");
            }

            CompareSchema(dataSet1, dataSet2);
            CompareXml(dataSet1, dataSet2);

            Assert.AreEqual(dataSet1.DataSetName, dataSet2.DataSetName, "DataSetName");
            Assert.AreEqual(dataSet1.Namespace, dataSet2.Namespace, "Namespace");
            Assert.AreEqual(dataSet1.TableNamespace, dataSet2.TableNamespace, "TableNamespace");
            Assert.AreEqual(dataSet1.TypeNamespace, dataSet2.TypeNamespace, "TypeNamespace");

            Assert.AreEqual(dataSet1.Tables.Count, dataSet2.Tables.Count, "Tables.Count");

            for (int i = 0; i < dataSet1.Tables.Count; i++)
            {
                var table1 = dataSet1.Tables[i];
                var table2 = dataSet2.Tables[table1.Name, table1.CategoryPath];
                CremaComparer.CompareTable(table1, table2);
            }

            Assert.AreEqual(dataSet1.Types.Count, dataSet2.Types.Count, "Types.Count");

            for (int i = 0; i < dataSet1.Types.Count; i++)
            {
                var type1 = dataSet1.Types[i];
                var type2 = dataSet2.Types[type1.TypeName];
                CremaComparer.CompareType(type1, type2);
            }
        }
Beispiel #17
0
        public void WriteToFile_ReadFromFile()
        {
            var testSet = new CremaDataSet();
            var dataSet = CremaDataSetExtensions.CreateRandomSet();

            foreach (var item in dataSet.Tables)
            {
                var schemaPath = PathUtility.GetTempFileName();
                var xmlPath    = PathUtility.GetTempFileName();

                try
                {
                    if (item.TemplateNamespace == string.Empty)
                    {
                        item.WriteXmlSchema(schemaPath);
                    }
                    else
                    {
                        item.TemplatedParent.WriteXmlSchema(schemaPath);
                    }
                    item.WriteXml(xmlPath);

                    try
                    {
                        if (item.TemplateNamespace == string.Empty)
                        {
                            testSet.ReadXmlSchema(schemaPath);
                        }
                        else
                        {
                            testSet.ReadXmlSchema(schemaPath, new ItemName(item.CategoryPath, item.Name));
                        }
                        if (item.Columns.Where(i => i.CremaType != null).Any() == true)
                        {
                            Assert.Fail("테이블이 사용자타입을 사용하는 경우 읽어들이는데 실패를 해야함.");
                        }
                    }
                    catch
                    {
                        if (item.TemplateNamespace == string.Empty)
                        {
                            testSet.ReadXmlSchema(schemaPath, new CremaTypeXmlResolver(dataSet, item.Namespace));
                        }
                        else
                        {
                            testSet.ReadXmlSchema(schemaPath, new ItemName(item.CategoryPath, item.Name), new CremaTypeXmlResolver(dataSet, item.Namespace));
                        }
                    }

                    if (item.TemplateNamespace == string.Empty)
                    {
                        testSet.ReadXml(xmlPath);
                    }
                    else
                    {
                        testSet.ReadXml(xmlPath, new ItemName(item.CategoryPath, item.Name));
                    }
                }
                finally
                {
                    FileUtility.Delete(schemaPath);
                    FileUtility.Delete(xmlPath);
                }
            }

            foreach (var item in dataSet.Tables)
            {
                var newTable = testSet.Tables[item.Name];
                CremaComparer.CompareTable(item, newTable);
            }
        }