public EmptyEntityCleanerTests() { source = new DataModelSource { ShortName = "test", Path = "/dev/null" }; cleaner = new EmptyEntityCleaner(logger.Object); cleaner.Input = input.Object; }
public AttributeMergerTests() { sourceSource = new DataModelSource(); targetSource = new DataModelSource(); sourceModel = new DataModel(); targetModel = new DataModel(); sourceEntity = sourceModel.FindOrCreateEntity("entity", sourceSource); targetEntity = targetModel.FindOrCreateEntity("entity", targetSource); sourceAttribute = sourceEntity.FindOrCreateAttribute("att", sourceSource); targetAttribute = targetEntity.FindOrCreateAttribute("att", targetSource); merger = new AttributeMerger(logger.Object); }
public async Task <DataModel> RunAsync() { // Set up the model var model = new DataModel { Id = ModelId, Name = ModelName }; var source = new DataModelSource { ShortName = ShortName, Path = Path }; model.Sources.Add(source); // Get the document that we'll be translating to a model var xsdDoc = await Input.RunAsync(); // Populate the model foreach (var xsdElement in xsdDoc.Elements) { // Find or create the entity var entity = model.FindOrCreateEntity(xsdElement.Name, source); entity.Comment = xsdElement.Comment; if (!string.IsNullOrEmpty(xsdElement.DataType)) { if (string.IsNullOrEmpty(xsdElement.RefName)) { entity.DataType = typeFactory.Make(xsdElement.DataType, ParseMaxLength(xsdElement)); } else { // This should never happen, but include it anyway entity.DataType = typeFactory.Make(xsdElement.DataType, xsdElement.RefName); } } // Add the attributes as attributes foreach (var xsdChild in xsdElement.Attributes) { var attribute = entity.FindOrCreateAttribute(xsdChild.Name, source); attribute.DataType = typeFactory.Make(xsdChild.DataType, ParseMaxLength(xsdChild)); attribute.Comment = xsdChild.Comment; attribute.MinOccurs = xsdChild.MinOccurs; attribute.MaxOccurs = xsdChild.MaxOccurs; attribute.IsXmlAttribute = true; attribute.EnumValues.AddRange(xsdChild.EnumValues); } // Add the child elements as attributes with complex types foreach (var xsdChild in xsdElement.Elements) { var attribute = entity.FindOrCreateAttribute(xsdChild.Name, source); if (xsdChild.DataType != null) { if (string.IsNullOrEmpty(xsdChild.RefName)) { attribute.DataType = typeFactory.Make(xsdChild.DataType, ParseMaxLength(xsdChild)); } else { attribute.DataType = typeFactory.Make(xsdChild.DataType, xsdChild.RefName); } } else { // TODO - improve this error message throw new LoaderException("DataType is null!"); } attribute.Comment = xsdChild.Comment; attribute.MinOccurs = xsdChild.MinOccurs; attribute.MaxOccurs = xsdChild.MaxOccurs; attribute.EnumValues.AddRange(xsdChild.EnumValues); } } // Return our glorious result return(model); }