public void UpdateReplicationInvalidIntTest() { //create a new method input and use the appropriate operation name OperationInput operationInput = new OperationInput { Name = "update", AllowMultipleObject = false }; var input = new List <DataEntity>(); var table = new DataEntity(); var columnData = new EntityProperties(); //create the comparison experssion for selecting the records to update operationInput.LookupCondition = new Expression[] { new ComparisonExpression(ComparisonOperator.Equal, new ComparisonValue(ComparisonValueType.Constant, "Region"), new ComparisonValue(ComparisonValueType.Constant, "North"), null) }; //add the columns to change table.ObjectDefinitionFullName = "Customers"; columnData.Add("CreditOnHold", "5328475903427853943453245324532453425345324523453453453425345324523452342345"); columnData.Add("ModifiedOn", DateTime.Now); table.Properties = columnData; input.Add(table); operationInput.Input = input.ToArray(); var operationResult = _rsTargetConnector.ExecuteOperation(operationInput); Assert.IsFalse(operationResult.Success[0]); Assert.AreEqual(0, operationResult.ObjectsAffected[0]); }
private EntityProperties GetPrimaryKeyProperties(DataEntity dataEntity, OleDbMetadataAccess metadataAccess) { var primaryKeyProperties = new EntityProperties(); //Use the data entity name to retrieve a list of indexes var indexColumns = metadataAccess.GetTableIndexInformation(dataEntity.ObjectDefinitionFullName); //Add each of the Primary Keys and their values found in the data entity. foreach (DataRow row in indexColumns.Rows) { if (!Convert.ToBoolean(row["PRIMARY_KEY"])) { continue; } var columnName = row["COLUMN_NAME"].ToString(); // Check if the priamry key column is included in the data entity. if (dataEntity.Properties.ContainsKey(columnName)) { // Add the key and its value to the primary key list. primaryKeyProperties.Add(columnName, dataEntity.Properties[columnName]); } else { // If the key has not been added set it to null. primaryKeyProperties.Add(columnName, null); } } return(primaryKeyProperties); }
public void UpdateReplicationNullValueValidTest() { //create a new method input and use the appropriate operation name OperationInput operationInput = new OperationInput { Name = "update", AllowMultipleObject = false }; var input = new List <DataEntity>(); var table = new DataEntity(); var columnData = new EntityProperties(); //create the comparison experssion for selecting the records to update operationInput.LookupCondition = new Expression[] { new ComparisonExpression( ComparisonOperator.IsNull, new ComparisonValue(ComparisonValueType.Constant, "Country"), null, null) }; //add the columns to change table.ObjectDefinitionFullName = "Addresses"; columnData.Add("Country", "USA"); columnData.Add("ModifiedOn", DateTime.Now); table.Properties = columnData; input.Add(table); operationInput.Input = input.ToArray(); var operationResult = _rsTargetConnector.ExecuteOperation(operationInput); Assert.IsTrue(operationResult.Success[0]); Assert.IsTrue(operationResult.ObjectsAffected[0] >= 1); }
public static IEnumerable <DataEntity> ReadAnyFile(Query query) { var entityName = query.RootEntity.ObjectDefinitionFullName; var constraints = BuildConstraintDictionary(query.Constraints); constraints.TryGetValue("SearchFileName", out var filename); if (filename == null) { throw new InvalidExecuteQueryException("Missing SearchFileName filter."); } constraints.TryGetValue("SearchPath", out var folder); if (folder == null) { throw new InvalidExecuteQueryException("Missing SearchPath filter."); } if (folder.ToString().EndsWith("\\") == false) { folder = folder + "\\".ToString(); } var dataEntity = new DataEntity(entityName); var entityProperties = new EntityProperties(); try { switch (entityName) { case EntityNames.FileText: string Text = ""; Text = File.ReadAllText(folder.ToString() + filename.ToString()); //add encoding option here entityProperties.Add("Text", Text); dataEntity.Properties = entityProperties; break; case EntityNames.FileBytes: Byte[] Bytes = null; Bytes = File.ReadAllBytes(folder.ToString() + filename.ToString()); entityProperties.Add("Bytes", Bytes); dataEntity.Properties = entityProperties; break; } } catch (Exception exp) { Logger.Write(Logger.Severity.Error, $"Cannot find Folder or File when querying entity: {entityName}.", exp.Message + exp.InnerException); throw new InvalidExecuteQueryException("Cannot find Folder or File: " + exp.Message); } yield return(dataEntity); }
public static EntityProperties LoadProperties([NotNull] XmlNode node) { Assert.ArgumentNotNull(node, "node"); var properties = new EntityProperties(); foreach (XmlAttribute attribute in node.Attributes) { properties.Add(attribute.Name, new EntityPropertyValue(CleanupProperyValue(attribute.Value))); } foreach (XmlNode childNode in node.ChildNodes) { properties.Add(childNode.Name, new EntityPropertyValue(childNode.InnerText)); } return(properties); }
public void UpdateReplicationTest() { OperationInput operationInput = new OperationInput(); List <DataEntity> input = new List <DataEntity>(); DataEntity table = new DataEntity(); EntityProperties columnData = new EntityProperties(); operationInput.Name = "update"; operationInput.AllowMultipleObject = false; //create the comparison experssion for selecting the records to update operationInput.LookupCondition = new Expression[] { new ComparisonExpression(ComparisonOperator.Equal, new ComparisonValue(ComparisonValueType.Constant, "State"), new ComparisonValue(ComparisonValueType.Constant, "MA"), null) }; //add the columns to change table.ObjectDefinitionFullName = "Addresses"; columnData.Add("Fax", "NA"); columnData.Add("ModifiedOn", DateTime.Now); table.Properties = columnData; input.Add(table); operationInput.Input = input.ToArray(); //execute the operation OperationResult operationResult = _rsTargetConnector.ExecuteOperation(operationInput); Assert.IsTrue(operationResult.Success[0]); Assert.IsTrue(operationResult.ObjectsAffected[0] >= 1); }
private void LoadEntityProperies(string entityTypeName) { var entconfig = Models.EntityConfig.Get(entityTypeName); if (entconfig != null) { foreach (var p in entconfig.PropertyConfigs) { if (!string.IsNullOrWhiteSpace(p.ViewModelName)) { EntityProperties.Add(Activator.CreateInstance(Type.GetType(p.ViewModelName), p, Model) as VM_EntityProperty); } else { EntityProperties.Add(new VM_EntityProperty(p, Model)); } } } }
private static Dictionary <string, PropertyInfo> GetEntityPerpertiesInfoList <TType>(string entityFullName) where TType : new() { if (EntityProperties.ContainsKey(entityFullName)) { return(EntityProperties[entityFullName]); } var piList = new Dictionary <string, PropertyInfo>(); var props = typeof(TType).GetTypeInfo().GetProperties(BindingFlags.Instance | BindingFlags.Public); foreach (var prop in props) { piList.Add(prop.Name.ToLower(), prop); } EntityProperties.Add(entityFullName, piList); return(piList); }
public static IEnumerable <DataEntity> ReadAllRows(Query query) { var entityName = query.RootEntity.ObjectDefinitionFullName; var constraints = BuildConstraintDictionary(query.Constraints); constraints.TryGetValue("SearchFileName", out var filename); if (filename == null) { throw new InvalidExecuteQueryException("Missing SearchFileName filter."); } constraints.TryGetValue("SearchPath", out var folder); if (folder == null) { throw new InvalidExecuteQueryException("Missing SearchPath filter."); } if (folder.ToString().EndsWith("\\") == false) { folder = folder + "\\".ToString(); } switch (entityName) { case EntityNames.FileLines: string[] Lines = null; Lines = File.ReadAllLines(folder.ToString() + filename.ToString(), System.Text.Encoding.UTF8); foreach (var l in Lines) { var linesDE = new DataEntity(entityName); var linesProps = new EntityProperties(); linesProps.Add("Lines", l); linesDE.Properties = linesProps; yield return(linesDE); } break; } }
public void InsertExistingRowInvalidTest() { //create a new method input and use the appropriate operation name OperationInput operationInput = new OperationInput { Name = "create" }; var input = new List <DataEntity>(); var table = new DataEntity(); var columnData = new EntityProperties(); //create a DataEntity for the row table.ObjectDefinitionFullName = "Products"; columnData.Add("RecordId", "9D595A0B-1C4F-43EF-8C03-B01EC343EF99"); columnData.Add("ProductNumber", "XXXXXX"); columnData.Add("ProductName", "Technical Consulting"); columnData.Add("Type", "Service"); columnData.Add("UoMSchedule", "Consulting"); columnData.Add("ListPrice", "150.00"); columnData.Add("Cost", "0.00"); columnData.Add("StandardCost", "0.00"); columnData.Add("QuantityInStock", "0"); columnData.Add("QuantityOnOrder", "0"); columnData.Add("Discontinued", "0"); columnData.Add("CreatedOn", DateTime.Now); columnData.Add("ModifiedOn", DateTime.Now); //add the row data to the input table.Properties = columnData; input.Add(table); operationInput.Input = input.ToArray(); //execute the selected operation //execute the selected operation OperationResult operationResult = _rsTargetConnector.ExecuteOperation(operationInput); //verify the result is not a success Assert.IsFalse(operationResult.Success[0]); //verify that a row was added Assert.AreEqual(ErrorNumber.DuplicateUniqueKey, operationResult.ErrorInfo[0].Number); }
public void InsertRowSingleQuoteValidTest() { //create a new method input and use the appropriate operation name OperationInput operationInput = new OperationInput { Name = "create" }; var input = new List <DataEntity>(); var table = new DataEntity(); var columnData = new EntityProperties(); //create a DataEntity for the row table.ObjectDefinitionFullName = "Products"; columnData.Add("RecordId", Guid.NewGuid().ToString()); columnData.Add("ProductNumber", DateTime.Now.GetHashCode()); columnData.Add("ProductName", "Screwdriver"); columnData.Add("Type", "O'Neil"); columnData.Add("UoMSchedule", "65"); columnData.Add("ListPrice", "65"); columnData.Add("Cost", "65"); columnData.Add("StandardCost", "65"); columnData.Add("QuantityInStock", "65"); columnData.Add("QuantityOnOrder", "65"); columnData.Add("Discontinued", "0"); columnData.Add("CreatedOn", DateTime.Now); columnData.Add("ModifiedOn", DateTime.Now); //add the row data to the input table.Properties = columnData; input.Add(table); operationInput.Input = input.ToArray(); //execute the selected operation //execute the selected operation OperationResult operationResult = _rsTargetConnector.ExecuteOperation(operationInput); //verify the result is a success Assert.IsTrue(operationResult.Success[0]); //verify that a row was added Assert.IsTrue(operationResult.ObjectsAffected[0] >= 1); }
public void UpdateTooManyRowsInvalidTest() { OperationInput operationInput = new OperationInput(); List<DataEntity> input = new List<DataEntity>(); DataEntity table = new DataEntity(); EntityProperties columnData = new EntityProperties(); operationInput.Name = "update"; //note: altering of multiple rows is not allowed operationInput.AllowMultipleObject = false; //create the comparison experssion for selecting the records to update operationInput.LookupCondition = new Expression[] { new ComparisonExpression(ComparisonOperator.IsNull, new ComparisonValue(ComparisonValueType.Constant, "Description"), null, null) }; //add the columns to change table.ObjectDefinitionFullName = "PickLists"; columnData.Add("Description", ""); table.Properties = columnData; input.Add(table); operationInput.Input = input.ToArray(); //execute the operation OperationResult operationResult = _sysConnector.ExecuteOperation(operationInput); //validate that the update was a success Assert.IsTrue(operationResult.Success[0]); Assert.AreEqual(0, operationResult.ObjectsAffected[0]); }
private EntityProperties GetPrimaryKeyProperties(DataEntity dataEntity, OleDbMetadataAccess metadataAccess) { var primaryKeyProperties = new EntityProperties(); //Use the data entity name to retrieve a list of indexes var indexColumns = metadataAccess.GetTableIndexInformation(dataEntity.ObjectDefinitionFullName); //Add each of the Primary Keys and their values found in the data entity. foreach (DataRow row in indexColumns.Rows) { if (!Convert.ToBoolean(row["PRIMARY_KEY"])) { continue; } var columnName = row["COLUMN_NAME"].ToString(); // Check if the priamry key column is included in the data entity. if (dataEntity.Properties.ContainsKey(columnName)) { // Add the key and its value to the primary key list. primaryKeyProperties.Add(columnName, dataEntity.Properties[columnName]); } else { // If the key has not been added set it to null. primaryKeyProperties.Add(columnName, null); } } return primaryKeyProperties; }
public void UpdateValidTest() { OperationInput operationInput = new OperationInput(); List<DataEntity> input = new List<DataEntity>(); DataEntity table = new DataEntity(); EntityProperties columnData = new EntityProperties(); operationInput.Name = "update"; operationInput.AllowMultipleObject = false; //create the comparison experssion for selecting the records to update operationInput.LookupCondition = new Expression[] { new ComparisonExpression(ComparisonOperator.Equal, new ComparisonValue(ComparisonValueType.Property, "Addresses.CustomerNumber"), new ComparisonValue(ComparisonValueType.Constant, "LITWAREI0001"), null) }; //add the columns to change table.ObjectDefinitionFullName = "Addresses"; columnData.Add("Fax", "NA"); table.Properties = columnData; input.Add(table); operationInput.Input = input.ToArray(); //execute the operation OperationResult operationResult = _sysConnector.ExecuteOperation(operationInput); //validate that the operation was successfull Assert.IsTrue(operationResult.Success[0]); //validate that only one records has been updated Assert.AreEqual(1, operationResult.ObjectsAffected[0]); }
public void InsertUnknownTableInValidTest() { //create a new method input and use the appropriate operation name OperationInput operationInput = new OperationInput { Name = "create" }; var input = new List<DataEntity>(); var table = new DataEntity(); var columnData = new EntityProperties(); //create a DataEntity for the row table.ObjectDefinitionFullName = InvalidPropertyValue; columnData.Add("RecordId", Guid.NewGuid().ToString()); columnData.Add("ProductNumber", "134234g"); columnData.Add("ProductName", "Screwdriver"); columnData.Add("Type", "FinishGood"); columnData.Add("UoMSchedule", "65"); columnData.Add("ListPrice", "65"); columnData.Add("Cost", "65"); columnData.Add("StandardCost", "65"); columnData.Add("QuantityInStock", "65"); columnData.Add("QuantityOnOrder", "65"); columnData.Add("Discontinued", "0"); columnData.Add("CreatedOn", DateTime.Now); columnData.Add("ModifiedOn", DateTime.Now); //add the row data to the input table.Properties = columnData; input.Add(table); operationInput.Input = input.ToArray(); //execute the selected operation OperationResult operationResult = _sysConnector.ExecuteOperation(operationInput); //verify the result is not a success Assert.IsFalse(operationResult.Success[0]); Assert.AreEqual(0, operationResult.ObjectsAffected[0]); }
public void UpdateReplicationTest() { OperationInput operationInput = new OperationInput(); List<DataEntity> input = new List<DataEntity>(); DataEntity table = new DataEntity(); EntityProperties columnData = new EntityProperties(); operationInput.Name = "update"; operationInput.AllowMultipleObject = false; //create the comparison experssion for selecting the records to update operationInput.LookupCondition = new Expression[] { new ComparisonExpression(ComparisonOperator.Equal, new ComparisonValue(ComparisonValueType.Constant, "State"), new ComparisonValue(ComparisonValueType.Constant, "MA"), null) }; //add the columns to change table.ObjectDefinitionFullName = "Addresses"; columnData.Add("Fax", "NA"); columnData.Add("ModifiedOn", DateTime.Now); table.Properties = columnData; input.Add(table); operationInput.Input = input.ToArray(); //execute the operation OperationResult operationResult = _rsTargetConnector.ExecuteOperation(operationInput); Assert.IsTrue(operationResult.Success[0]); Assert.IsTrue(operationResult.ObjectsAffected[0] >=1); }
public static IEnumerable <DataEntity> FileValuesToDE(string[] dirs, string entityName) { if (dirs != null) { foreach (string dir in dirs) { var getFileName = Path.GetFileName(dir); var fileExt = Path.GetExtension(dir); var info = new FileInfo(dir); var fileLength = info.Length; var createTime = info.CreationTimeUtc; var lastAccessTime = info.LastAccessTimeUtc; var folder = Path.GetFileName(Path.GetDirectoryName(dir)); var exists = info.Exists; var directoryName = info.DirectoryName; var hidden = info.Attributes.HasFlag(FileAttributes.Hidden); var archive = info.Attributes.HasFlag(FileAttributes.Archive); var temporary = info.Attributes.HasFlag(FileAttributes.Temporary); var system = info.Attributes.HasFlag(FileAttributes.System); var dataEntityFolder = new DataEntity(); dataEntityFolder.ObjectDefinitionFullName = entityName.ToString(); var folderProps = new EntityProperties(); folderProps.Add("FullPath", dir); folderProps.Add("FolderName", folder); folderProps.Add("FileName", getFileName); folderProps.Add("FileExtension", fileExt); folderProps.Add("Exists", exists); folderProps.Add("FileSize", fileLength); folderProps.Add("CreatedOn", createTime); folderProps.Add("AccessedOn", lastAccessTime); folderProps.Add("Path", directoryName); folderProps.Add("Hidden", hidden); folderProps.Add("Archive", archive); folderProps.Add("Temporary", temporary); folderProps.Add("System", system); dataEntityFolder.Properties = folderProps; yield return(dataEntityFolder); } } else { yield return(new DataEntity(entityName)); } }
public void UpdateMultipleRowsValidTest() { //create a new method input and use the appropriate operation name OperationInput operationInput = new OperationInput { Name = "update", AllowMultipleObject = true }; var input = new List<DataEntity>(); var table = new DataEntity(); var columnData = new EntityProperties(); //create the comparison experssion for selecting the records to update operationInput.LookupCondition = new Expression[] { new ComparisonExpression( ComparisonOperator.IsNull,new ComparisonValue(ComparisonValueType.Property, "TaxSchedule"), null, null) }; //add the columns to change table.ObjectDefinitionFullName = "Addresses"; columnData.Add("TaxSchedule", "ST-PA"); table.Properties = columnData; input.Add(table); operationInput.Input = input.ToArray(); //execute the selected operaiton var operationResult = _sysConnector.ExecuteOperation(operationInput); //validate that the operation was success Assert.IsTrue(operationResult.Success[0]); //validate that multiple rows have been updated Assert.IsTrue(operationResult.ObjectsAffected[0] >= 1); }
public void UpdateReplicationNullValueValidTest() { //create a new method input and use the appropriate operation name OperationInput operationInput = new OperationInput { Name = "update", AllowMultipleObject = false }; var input = new List<DataEntity>(); var table = new DataEntity(); var columnData = new EntityProperties(); //create the comparison experssion for selecting the records to update operationInput.LookupCondition = new Expression[] { new ComparisonExpression( ComparisonOperator.IsNull,new ComparisonValue(ComparisonValueType.Constant, "Country"), null, null) }; //add the columns to change table.ObjectDefinitionFullName = "Addresses"; columnData.Add("Country", "USA"); columnData.Add("ModifiedOn", DateTime.Now); table.Properties = columnData; input.Add(table); operationInput.Input = input.ToArray(); var operationResult = _rsTargetConnector.ExecuteOperation(operationInput); Assert.IsTrue(operationResult.Success[0]); Assert.IsTrue(operationResult.ObjectsAffected[0] >= 1); }
public void UpdateInvalidIntTest() { //create a new method input and use the appropriate operation name OperationInput operationInput = new OperationInput { Name = "update", AllowMultipleObject = false }; var input = new List<DataEntity>(); var table = new DataEntity(); var columnData = new EntityProperties(); //create the comparison experssion for selecting the records to update operationInput.LookupCondition = new Expression[] { new ComparisonExpression(ComparisonOperator.Equal, new ComparisonValue(ComparisonValueType.Property, "Region"), new ComparisonValue(ComparisonValueType.Constant, "North"), null) }; //add the columns to change table.ObjectDefinitionFullName = "Customers"; columnData.Add("CreditOnHold", "5328475903427853943453245324532453425345324523453453453425345324523452342345"); columnData.Add("ModifiedOn", DateTime.Now); table.Properties = columnData; input.Add(table); operationInput.Input = input.ToArray(); var operationResult = _sysConnector.ExecuteOperation(operationInput); //validate that the result of the operation was not a success Assert.IsFalse(operationResult.Success[0]); //validate that no objects have been affected Assert.AreEqual(0, operationResult.ObjectsAffected[0]); }
public void UpdateInvalidDateTest() { //create a new method input and use the appropriate operation name OperationInput operationInput = new OperationInput { Name = "update", AllowMultipleObject = false }; var input = new List<DataEntity>(); var table = new DataEntity(); var columnData = new EntityProperties(); //create the comparison experssion for selecting the records to update operationInput.LookupCondition = new Expression[] { new ComparisonExpression(ComparisonOperator.Equal, new ComparisonValue(ComparisonValueType.Property, "Type"), new ComparisonValue(ComparisonValueType.Constant, "Order"), null) }; //add the columns to change table.ObjectDefinitionFullName = "SalesOrders"; columnData.Add("OrderDate", InvalidPropertyValue); columnData.Add("ModifiedOn", DateTime.Now); table.Properties = columnData; input.Add(table); operationInput.Input = input.ToArray(); var operationResult = _sysConnector.ExecuteOperation(operationInput); Assert.IsFalse(operationResult.Success[0]); Assert.AreEqual(0, operationResult.ObjectsAffected[0]); }
public void UpdateBooleanValidTest() { var input = new List<DataEntity>(); var table = new DataEntity(); var columnData = new EntityProperties(); var operationInput = new OperationInput(); operationInput.Name = "update"; operationInput.AllowMultipleObject = false; //create a new comparison expression that will only attempt to update one row of data operationInput.LookupCondition = new Expression[] { new ComparisonExpression(ComparisonOperator.Equal, new ComparisonValue(ComparisonValueType.Property, "ProductNumber"), new ComparisonValue(ComparisonValueType.Constant,"ME256"), null) }; table.ObjectDefinitionFullName = "Products"; //This will only accept a value that has a value of 1, or 0 for TRUE or FALSE columnData.Add("Discontinued", 1); table.Properties = columnData; input.Add(table); operationInput.Input = input.ToArray(); var operationResult = _sysConnector.ExecuteOperation(operationInput); //validate the the result was a success Assert.IsTrue(operationResult.Success[0]); //validate that only one row of data was affected Assert.AreEqual(1, operationResult.ObjectsAffected[0]); }
public void InsertUnknownTableInValidTest() { //create a new method input and use the appropriate operation name OperationInput operationInput = new OperationInput { Name = "create" }; var input = new List <DataEntity>(); var table = new DataEntity(); var columnData = new EntityProperties(); //create a DataEntity for the row table.ObjectDefinitionFullName = InvalidPropertyValue; columnData.Add("RecordId", Guid.NewGuid().ToString()); columnData.Add("ProductNumber", "134234g"); columnData.Add("ProductName", "Screwdriver"); columnData.Add("Type", "FinishGood"); columnData.Add("UoMSchedule", "65"); columnData.Add("ListPrice", "65"); columnData.Add("Cost", "65"); columnData.Add("StandardCost", "65"); columnData.Add("QuantityInStock", "65"); columnData.Add("QuantityOnOrder", "65"); columnData.Add("Discontinued", "0"); columnData.Add("CreatedOn", DateTime.Now); columnData.Add("ModifiedOn", DateTime.Now); //add the row data to the input table.Properties = columnData; input.Add(table); operationInput.Input = input.ToArray(); //execute the selected operation OperationResult operationResult = _rsTargetConnector.ExecuteOperation(operationInput); //verify the result is not a success Assert.IsFalse(operationResult.Success[0]); Assert.AreEqual(0, operationResult.ObjectsAffected[0]); }
public void InsertExistingRowInvalidTest() { //create a new method input and use the appropriate operation name OperationInput operationInput = new OperationInput { Name = "create" }; var input = new List<DataEntity>(); var table = new DataEntity("Customers"); var columnData = new EntityProperties(); //create a DataEntity for the row table.ObjectDefinitionFullName = "Customers"; columnData.Add("CustomerNumber", "ABERDEEN0001"); columnData.Add("CompanyName", "Aberdeen Inc."); columnData.Add("Active", "1"); //add the row data to the input table.Properties = columnData; input.Add(table); operationInput.Input = input.ToArray(); //execute the selected operation OperationResult operationResult = _sysConnector.ExecuteOperation(operationInput); //verify the result is not a success Assert.IsFalse(operationResult.Success[0]); //verify that a row was added Assert.AreEqual(ErrorNumber.DuplicateUniqueKey, operationResult.ErrorInfo[0].Number); }
//public static T From<T>(DataEntity de, ObjDefs e) where T : new() //{ // var data = new T(); // // TODO: Consider getting this from the type instead of DataEntity // var od = e.GetOrBuild(de.ObjectDefinitionFullName); // foreach (var property in de.Properties) // { // var propertySetter = od.Properties[property.Key]; // propertySetter?.Set(data, property.Value); // } // foreach (var c in de.Children) // { // var dataEntityProp = od.Properties[c.Key] as IDataEntityProperty; // if (dataEntityProp != null) // { // var dataEntity = c.Value.FirstOrDefault(); // if (dataEntity != null) // { // dataEntityProp.Set(data, dataEntity); // } // } // var dataEntityListProp = od.Properties[c.Key] as IDataEntityListProperty; // if (dataEntityListProp != null) // { // var dataEntity = c.Value; // if (dataEntity != null) // { // dataEntityListProp.Set(data, dataEntity); // } // } // } // return data; //} public static DataEntity To <T>(T data, ObjDefs e, QueryEntity qe = null) { if (data == null) { return(null); } var stub = MetadataReflector.GetObjectDefStubFromType(typeof(T)); var od = e.GetOrBuild(stub.Name); var de = new DataEntity(od.Name); var props = new EntityProperties(); var children = new EntityChildren(); foreach (var keyValuePair in od.Properties) { var name = keyValuePair.Key; var getter = keyValuePair.Value; if (!getter.IsObjectDefProp) { if (qe == null || qe.PropertyList.Contains(name)) { props.Add(name, getter.Get(data)); } } else { var dataEntityGetter = getter as IDataEntityProperty; if (dataEntityGetter != null) { if (qe == null) { var cde = dataEntityGetter.Get(data); var v = cde == null ? new List <DataEntity>() : new List <DataEntity> { cde }; children.Add(name, v); } else { var propQe = qe.ChildList.FirstOrDefault(q => q.Name == name); if (propQe != null) { var cde = dataEntityGetter.Get(data, propQe); var v = cde == null ? new List <DataEntity>() : new List <DataEntity> { cde }; children.Add(name, v); } } } var dataEntityListGetter = getter as IDataEntityListProperty; if (dataEntityListGetter != null) { if (qe == null) { var cde = dataEntityListGetter.Get(data); // Workaround fopr CORE Bug if (cde == null) { cde = new List <DataEntity>(); } children.Add(name, cde); } else { var propQe = qe.ChildList.FirstOrDefault(q => q.Name == name); if (propQe != null) { var cde = dataEntityListGetter.Get(data, propQe); // Workaround fopr CORE Bug if (cde == null) { cde = new List <DataEntity>(); } children.Add(name, cde); } } } } } de.Properties = props; de.Children = children; return(de); }
public void UpsertingExistingRowInvalidTest() { //create a new method input and use the appropriate operation name OperationInput operationInput = new OperationInput { Name = "upsert" }; var input = new List<DataEntity>(); var table = new DataEntity(); var columnData = new EntityProperties(); //create a DataEntity for the row table.ObjectDefinitionFullName = "Customers"; columnData.Add("CustomerNumber", "ABERDEEN0001"); columnData.Add("CompanyName", "Aberdeen Inc."); columnData.Add("Active", "1"); columnData.Add("Email", "*****@*****.**"); //add the row data to the input table.Properties = columnData; input.Add(table); operationInput.Input = input.ToArray(); //execute the selected operation OperationResult operationResult = _sysConnector.ExecuteOperation(operationInput); //verify the result is a success Assert.IsTrue(operationResult.Success[0]); //verify that a row was added Assert.AreEqual(1, operationResult.ObjectsAffected[0]); }
public void InsertExistingRowInvalidTest() { //create a new method input and use the appropriate operation name OperationInput operationInput = new OperationInput { Name = "create" }; var input = new List<DataEntity>(); var table = new DataEntity(); var columnData = new EntityProperties(); //create a DataEntity for the row table.ObjectDefinitionFullName = "Products"; columnData.Add("RecordId", "9D595A0B-1C4F-43EF-8C03-B01EC343EF99"); columnData.Add("ProductNumber", "XXXXXX"); columnData.Add("ProductName", "Technical Consulting"); columnData.Add("Type", "Service"); columnData.Add("UoMSchedule", "Consulting"); columnData.Add("ListPrice", "150.00"); columnData.Add("Cost", "0.00"); columnData.Add("StandardCost", "0.00"); columnData.Add("QuantityInStock", "0"); columnData.Add("QuantityOnOrder", "0"); columnData.Add("Discontinued", "0"); columnData.Add("CreatedOn", DateTime.Now); columnData.Add("ModifiedOn", DateTime.Now); //add the row data to the input table.Properties = columnData; input.Add(table); operationInput.Input = input.ToArray(); //execute the selected operation //execute the selected operation OperationResult operationResult = _rsTargetConnector.ExecuteOperation(operationInput); //verify the result is not a success Assert.IsFalse(operationResult.Success[0]); //verify that a row was added Assert.AreEqual(ErrorNumber.DuplicateUniqueKey, operationResult.ErrorInfo[0].Number); }
public void InsertRowValidTest() { //create a new method input and use the appropriate operation name OperationInput operationInput = new OperationInput { Name = "create" }; var input = new List<DataEntity>(); var table = new DataEntity(); var columnData = new EntityProperties(); //create a DataEntity for the row table.ObjectDefinitionFullName = "Products"; columnData.Add("RecordId", Guid.NewGuid().ToString()); columnData.Add("ProductNumber", DateTime.Now.GetHashCode()); columnData.Add("ProductName", "Screwdriver"); columnData.Add("Type", "FinishGood"); columnData.Add("UoMSchedule", null); columnData.Add("ListPrice", "65"); columnData.Add("Cost", "65"); columnData.Add("StandardCost", "65"); columnData.Add("QuantityInStock", "65"); columnData.Add("QuantityOnOrder", "65"); columnData.Add("Discontinued", "0"); //add the row data to the input table.Properties = columnData; input.Add(table); operationInput.Input = input.ToArray(); //execute the selected operation OperationResult operationResult = _sysConnector.ExecuteOperation(operationInput); //verify the result is a success Assert.IsTrue(operationResult.Success[0]); //verify that a row was added Assert.IsTrue(operationResult.ObjectsAffected[0] >= 1); }