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); } }
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 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 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); } }
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); } }
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); } }